Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
6477 Zobrazení

Hello, I'm trying to generate invoices using only code. My problem starts when I try to create invoice lines. Using the Odoo shell, I'm trying to create a simple invoice line like so:


>>> env['account.invoice.line'].create({'name':'test','price_unit':20,'quantity':5,'product_id':1})


But I get the following error


2021-01-19 10:37:10,610 4649 ERROR mydb odoo.sql_db: bad query: INSERT INTO "account_invoice_line" ("id", "create_uid", "create_date", "write_uid", "write_date", "account_id", "discount", "display_type", "is_rounding_line", "name", "price_unit", "product_id", "quantity", "sequence") VALUES (nextval('account_invoice_line_id_seq'), 1, (now() at time zone 'UTC'), 1, (now() at time zone 'UTC'), NULL, '0.00', NULL, false, 'test', '20.00', 1, '5.000', 10) RETURNING id
ERROR: new row for relation "account_invoice_line" violates check constraint "account_invoice_line_accountable_required_fields"
DETAIL:  Failing row contains (119, test, null, 10, null, null, 1, null, 20.00, null, null, null, 5.000, 0.00, null, null, null, null, f, null, 1, 2021-01-19 10:37:01.471099, 1, 2021-01-19 10:37:01.471099).
 
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "<decorator-gen-247>", line 2, in create
  File "/home/wojdob/odoo-dev/odoo/odoo/api.py", line 461, in _model_create_multi
    return create(self, [arg])
  File "/home/wojdob/odoo-dev/odoo/addons/account/models/account_invoice.py", line 1960, in create
    return super(AccountInvoiceLine, self).create(vals_list)
  File "<decorator-gen-3>", line 2, in create
  File "/home/wojdob/odoo-dev/odoo/odoo/api.py", line 462, in _model_create_multi
    return create(self, arg)
  File "/home/wojdob/odoo-dev/odoo/odoo/models.py", line 3588, in create
    records = self._create(data_list)
  File "/home/wojdob/odoo-dev/odoo/odoo/models.py", line 3688, in _create
    cr.execute(query, params)
  File "/home/wojdob/odoo-dev/odoo/odoo/sql_db.py", line 148, in wrapper
    return f(self, *args, **kwargs)
  File "/home/wojdob/odoo-dev/odoo/odoo/sql_db.py", line 225, in execute
    res = self._obj.execute(query, params)
psycopg2.errors.CheckViolation: new row for relation "account_invoice_line" violates check constraint "account_invoice_line_accountable_required_fields"
DETAIL:  Failing row contains (119, test, null, 10, null, null, 1, null, 20.00, null, null, null, 5.000, 0.00, null, null, null, null, f, null, 1, 2021-01-19 10:37:01.471099, 1, 2021-01-19 10:37:01.471099).

I'm not sure what I'm doing wrong, since I'm creating the record with all the required fields. I haven't found any info about the constraint "account_invoice_line_accountable_required_fields", which I suppose is the reason for my problem. Thank you in advance.




Avatar
Zrušit
Nejlepší odpověď

Hi,

Just pass the account_id to create method and see, it will work.

env['account.invoice.line'].create({'name':'test','price_unit':20,'quantity':5,'product_id':1, 'account_id': 1})

Thanks

Avatar
Zrušit
Autor

Yup, works, thanks!

could you please show the full code ? ty in advance. I am new to erp and odoo as my first job as a programmer and i am trying to create an onchange method that auto adds a standar product in account.invoice lines when partner_id changes

Nejlepší odpověď

where does it goes?

Where I put that code?

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
čvn 24
2074
3
úno 24
3629
1
lis 22
18701
2
zář 21
11081
0
kvě 16
3521