Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Odoo 12 - Create invoice line with code

Subscriure's

Get notified when there's activity on this post

This question has been flagged
codeinvoiceinvoice.line12.0
2 Respostes
7116 Vistes
Avatar
Wojciech Dobrychłop

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.




0
Avatar
Descartar
Avatar
Niyas Raphy (Walnut Software Solutions)
Best Answer

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

2
Avatar
Descartar
Wojciech Dobrychłop
Autor

Yup, works, thanks!

Dionisis Theonas Zervas

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

Avatar
Alejandro
Best Answer

where does it goes?

Where I put that code?

0
Avatar
Descartar
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
Trying to resize signature on invoice
code invoice
Avatar
Avatar
1
de juny 24
3244
Item and Description Lines Not Showing When Invoice is Printed Solved
invoice invoice.line
Avatar
Avatar
Avatar
3
de febr. 24
5053
Create new invoice by code Solved
code invoice
Avatar
Avatar
1
de nov. 22
19625
Hide Rows in Tree inside Form View Solved
invoice invoice.line
Avatar
Avatar
Avatar
2
de set. 21
11957
how can i make some space for a field in the invoice lines
invoice invoice.line
Avatar
0
de maig 16
4333
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now