コンテンツへスキップ
メニュー
この質問にフラグが付けられました
3 返信
18409 ビュー

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


アバター
破棄
最善の回答

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.

アバター
破棄
最善の回答

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()


アバター
破棄
最善の回答

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

アバター
破棄
著作者

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

関連投稿 返信 ビュー 活動
0
11月 24
1123
2
3月 22
6182
0
9月 24
1039
0
6月 24
2092
2
11月 23
2870