Cannot create unbalanced journal entry. Ids: Differences debit - credit Error when trying to create an invoice line

Viewed 3439

I'm trying to create an invoice line using the Web APIs and XML-RPC (python). I receive this error while creating it.

xmlrpc.client.Fault: <Fault 2: 'Cannot create unbalanced journal entry. Ids: [12083]\nDifferences debit - credit: [-2629.33]'>

I'm creating the invoice line as follows:

inv_line_id = models.execute_kw(
        db, uid, password, 
       'account.move.line',
       'create'[
           {'move_id':invoice_id,
            'product_id':product_id[0]['id'],
            'price_unit':product_id[0]['list_price'],
            'quantity':sale_line_id[0]['product_uom_qty'],
            'account_id':account_id[0]['property_account_income_categ_id'][0]
            }
            ]
   )

If i dont add the 'price_unit' the invoice line is being created normally but without a price.

Anyone knows how to fix this ? Thanks in advance

3 Answers

If you are in the same version of me (V13) or if the code is the same in your version. You could pass a value in the context to don't check the balanced.

'check_move_validity' = False

Find in the file account/models/account_move.py . Line 1721 in method write

        # Ensure the move is still well balanced.
    if 'line_ids' in vals:
        if self._context.get('check_move_validity', True):
            self._check_balanced()
        self.update_lines_tax_exigibility()

During the create or write of an account.move with only invoice_line_ids set and not line_ids, the _move_autocomplete_invoice_lines_create or _move_autocomplete_invoice_lines_write method is called to auto compute accounting lines of the invoice. In that case, accounts will be retrieved and taxes, cash rounding, and payment terms will be computed. In the end, the values will contain all accounting lines in line_ids and the moves should be balanced.

Latest version of Odoo 13 dated December 10, 2021.

Edit file: /path_of_odoo/addons/account/models/account_move.py

Example: vim /odoo/addons/account/models/account_move.py

Modify function named _check_balanced and comment line 1582 and add new line whit return

Example:

############################### Before ################################## enter image description here

############################### A F T E R ###############################

enter image description here

Related