Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • Apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

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

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

Odoo 12 - Create invoice line with code

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
codeinvoiceinvoice.line12.0
2 Besvarelser
7026 Visninger
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
Kassér
Avatar
Niyas Raphy (Walnut Software Solutions)
Bedste svar

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
Kassér
Wojciech Dobrychłop
Forfatter

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
Bedste svar

where does it goes?

Where I put that code?

0
Avatar
Kassér
Enjoying the discussion? Don't just read, join in!

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

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
Trying to resize signature on invoice
code invoice
Avatar
Avatar
1
jun. 24
2972
Item and Description Lines Not Showing When Invoice is Printed Løst
invoice invoice.line
Avatar
Avatar
Avatar
3
feb. 24
4803
Create new invoice by code Løst
code invoice
Avatar
Avatar
1
nov. 22
19453
Hide Rows in Tree inside Form View Løst
invoice invoice.line
Avatar
Avatar
Avatar
2
sep. 21
11810
how can i make some space for a field in the invoice lines
invoice invoice.line
Avatar
0
maj 16
4223
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة 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 er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

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