Skip to Content
Menu
This question has been flagged
1 Reply
1455 Views

Dear Odoo Community

I am trying to update invoice line with automated action feature.
Here is my code:


for record in records:
id1 = env["account.move.line"].search([('product_id', 'ilike', 'OFIDA')])[0].id
id2 = env["account.move.line"].search([('product_id', 'ilike', 'TAXE VOIRIE')])[0].id
record['line_ids'] = [
(1, id1, {'quantity': 0.01, 'price_unit': record.x_studio_fob_1 }),
(1, id2, {'quantity': record.x_studio_taxe_voirie, 'price_unit': record.x_studio_poids_t })
]

I am getting the below error message:

Cannot create an unbalanced accounting document. Ids: [7822] Debit - credit difference: [-3100.0]


Can anybody assist me with the correct code syntax to automatically recompute the invoice?

Avatar
Discard
Author Best Answer

I was able to fix my issue with the below codes in automated actions:


for record in records.with_context(check_move_validity=False):
    id1 = env["account.move.line"].search([('product_id', 'ilike', 'OFIDA')])[0].id
    id2 = env["account.move.line"].search([('product_id', 'ilike', 'TAXE VOIRIE')])[0].id
    id3 = env["account.move.line"].search([('product_id', 'ilike', 'CEEC')])[0].id
    id4 = env["account.move.line"].search([('product_id', 'ilike', 'FERE')])[0].id
    id5 = env["account.move.line"].search([('product_id', 'ilike', 'LMC')])[0].id

    record['line_ids'] = [
        (1, id1, {'quantity': 0.01, 'price_unit': record.x_studio_fob_1 }),
        (1, id2, {'quantity': record.x_studio_poids_t, 'price_unit': record.x_studio_taxe_voirie }),
        (1, id3, {'price_unit': record.x_studio_ceec }),
        (1, id4, {'quantity': record.x_studio_poids_t }),
        (1, id5, {'quantity': record.x_studio_poids_t, 'price_unit': record.x_studio_lmc })                
                                    ]


    record._recompute_dynamic_lines(recompute_all_taxes=True, recompute_tax_base_amount=True) 



Avatar
Discard