0
votes

I get records in record.department_id.id. These records have record.price_subtotal. I need to add record.price_subtotal if they have the same record.department_id.id. How do I do this with the .get() method And output it to the xml

 reconciliation_act_id = self.env["alfaleads.accounts.receivable"].search([("reconciliation_act_id", "=", self.id)])
            if not reconciliation_act_id:
                self.env["alfaleads.accounts.receivable"].create({"reconciliation_act_id": self.id})
    
                for record in self.reconciliation_act_line_ids:
                    if record.department_id.id:
                        vals = {
                            "department_id": record.department_id.id,
                            "total_amount_interim": record.price_subtotal,
                            "account_receivable_id": self.accounts_receivable_id.id,
                        }
                        self.env["alfaleads.accounts.interim.total"].create(vals)
            else:
                for record in self.reconciliation_act_line_ids:
                    if record.department_id.id:
                        reconciliation_act_id.write({'alfaleads_accounts_department_total_ids': [(0, 0, {
                                        "department_id": record.department_id.id,
                                        "total_amount_interim": record.price_subtotal,
                                        "account_receivable_id": self.accounts_receivable_id.id})]})

my.xml

<field name="alfaleads_accounts_department_total_ids">
                                <tree editable="bottom">
                                    <field name="department_id" />
                                    <field name="total_amount_interim" widget="monetary"/>
                                </tree>
                        </field>

At the moment the records look like this. and I need one record 'CPA' and total_amount_interim = 100 enter image description here please help