Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.

Module: Return Merchandise Authorization Management

Entity: rma.operation

Compute Method: _compute_count_rma

Inputs Method Outputs
self.update(
            {
                "count_rma_draft": 0,
                "count_rma_processed": 0,
                "count_rma_awaiting_action": 0,
            }
        )
state_by_op = defaultdict(int)
for group in self.env["rma"].read_group(
            AND([[("operation_id", "!=", False)]]),
            groupby=["operation_id", "state"],
            fields=["id"],
            lazy=False,
        ):
            operation_id = group.get("operation_id")[0]
            state = group.get("state")
            count = group.get("__count")
            if state == "draft":
                state_by_op[(operation_id, "count_rma_draft")] += count
            if state in PROCESSED_STATES:
                state_by_op[(operation_id, "count_rma_processed")] += count
            if state in AWAITING_ACTION_STATES:
                state_by_op[(operation_id, "count_rma_awaiting_action")] += count
for (operation_id, field), count in state_by_op.items():
            self.browse(operation_id).update({field: count})

Back to entity