Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Sociale media-marketing
    • E-mailmarketing
    • Sms-marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Gastenverblijf
    • Drankenhandelaar
    • Hotel
    Vastgoed
    • Makelaarskantoor
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accountantskantoor
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textiel
    • Metaal
    • Meubels
    • Eten
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Zonne-energiesystemen
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC-diensten
    Andere
    • Non-profitorganisatie
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

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

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

Odoo 12 - Create invoice line with code

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
codeinvoiceinvoice.line12.0
2 Antwoorden
7121 Weergaven
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
Annuleer
Avatar
Niyas Raphy (Walnut Software Solutions)
Beste antwoord

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
Annuleer
Wojciech Dobrychłop
Auteur

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
Beste antwoord

where does it goes?

Where I put that code?

0
Avatar
Annuleer
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Gerelateerde posts Antwoorden Weergaven Activiteit
Trying to resize signature on invoice
code invoice
Avatar
Avatar
1
jun. 24
3246
Item and Description Lines Not Showing When Invoice is Printed Opgelost
invoice invoice.line
Avatar
Avatar
Avatar
3
feb. 24
5056
Create new invoice by code Opgelost
code invoice
Avatar
Avatar
1
nov. 22
19627
Hide Rows in Tree inside Form View Opgelost
invoice invoice.line
Avatar
Avatar
Avatar
2
sep. 21
11958
how can i make some space for a field in the invoice lines
invoice invoice.line
Avatar
0
mei 16
4334
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة 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 is een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

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