Skip to Content
Menu
This question has been flagged
3 Replies
15706 Views

Hi all,

there are major differences between V12 and V13. In V13 i can add an invoice  via API and then i try to add account.move.line to that invoice. I always get the error

Cannot create unbalanced journal entry
Differences debit - credit

i set the following fields:

'account_id' => $account_id,
'move_id' => $odoo_move_id,
'product_id' => 174,
'tax_ids' => [[6, 0, [$odoo_tax_id]]],
'quantity' => 2.0,
'price_unit' => 1.99,
'name' => 'TEST'

Do i really have to add serveral lines in order to make it work? whatelse do i have to do in order to have odoo add the lines automatically just as it does when it do it via the UI?

Fritz


Avatar
Discard
Best Answer

Hi, I have faced the same problem in v13.

Done some code changes, now its working for me.

I here share some of my changes, you may check if its useful for your's.

# Journal

journal_id = self.env['account.journal'].search([('type','=','sale')])[0]

# Move Line creation:

invoice_lines = []

for line in lines:

    invoice_lines.append((0,0,{

                                                            'name': line.name,

                                                            'display_name': line.name,

                                                            'price_unit': price,

                                                            'quantity': qty,

                                                            'product_uom_id': uoms.id,

                                                            'product_id': line.product_id.id,

                                                            'tax_ids': [(6, 0, tax.ids)],

                                                        }))


# Move creation:

    account_move = self.env['account.move'].sudo().create({

                                                            'name':  doc_name,

                                                            'invoice_origin': doc_name,

                                                            'invoice_date': date.today(),

                                                            'type': 'out_invoice',

                                                            'partner_id': partner.id,

                                                            'invoice_line_ids': invoice_lines,

                                                            'journal_id': journal_id.id,

                                                            'company_id': self.env.user.company_id.id,

                                        })


Thanks.

Avatar
Discard
Best Answer

Hi,

Python code example for Odoo 13:

...

from odoo.tests.common import Form

class AccountMove(models.Model):
_inherit = 'account.move'

    def add_invoice_line(self):

         with Form(self) as move_form:
            with move_form.invoice_line_ids.new() as line:
                line.name ='Product Name'
                line.product_uom_id =
                line.price_unit = 1.0
                line.quantity = 1.0
                line.account_id =
            move_form.save()


Avatar
Discard
Best Answer

Read my answer in this question:
Create invoices/credit notes in odoo13 by code.

Avatar
Discard
Author

Thanks, i had a lock on it.

I do a account.move create in the first place. Then i use the move_id to add account.move.line .

And there is the problem. as in former verions i expected that all nessesary lines are being created. at the moment with v13 it looks like i have to submit 3 lines in order to get the balance right.

Is there any way odoo api can add all lines by itself and automatically refere to the customer profile with all tax settings?

I would appreciate an example on how to add an invoice with all lines in V13. Is there any documentation available? I really could not find it.

Best regards and many thanks,

Fritz

Related Posts Replies Views Activity
0
Nov 24
49
2
Mar 22
4356
0
Sep 24
180
0
Jun 24
477
2
Nov 23
1299