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
    • Social 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
    • Guest House
    • Drankenhandelaar
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Solar Energy Systems
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC Services
    Others
    • Nonprofit Organization
    • 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

Programmatically create a sale order line

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
modulesalesale.order.lineprogramaticallyv9
1 Beantwoorden
34560 Weergaven
Avatar
Peter Nietz

In our custom Odoo module we need to programmatically create new sales order lines. The purpose is to assist our sales teams to create sales orders for follow-up purchases (the customer has already purchased a software license, we want to offer him an extension/prolongation/...). We have created a wizard for this purpose, which fills in the sales order lines (automatically using various information from other models).

Our code looks roughly as follows:

@api.multi
def add_to_offer(self):
for wizard in self:
new_lines = []
for what in wizard.entries:
new_lines.append((0, 0, {
'name' : what.product_id.name,
'product_id' : what.product_id.id,
'product_uom' : what.product_id.uom_id.id,
'product_uom_qty' : 1
}))
wizard.sale_order_id.write({ 'order_line' : new_lines })

In principle this works at large. We don't get any error messages from Odoo (although we had to explicitly include the fields "name" and "product_uom" in order to work around errors on missing fields.

But... apparently there are still some bits missing. Compared to regular order lines our programmatically created ones are missing the unit price, taxes and subtotal price (potentially even more fields). We could try to calculate and set that stuff explicitly (just as we did with "name" and "product_uom") but that would require us to duplicate lots of code including tax and pricelist stuff. Surely not a good idea...

What is the correct way to programmatically create order lines?


Update: Based on Ahmed's tip we are now invoking the methods listed below on all freshly created order line. This seems to work fine. Many thanks for pointing out this direction, Ahmed.

product_id_change()
product_uom_change()
_compute_invoice_status()
_compute_amount()
_get_to_invoice_qty()
_get_price_reduce()
4
Avatar
Annuleer
Avatar
Qutechs, Ahmed M.Elmubarak
Beste antwoord

Hello,

You can call the on_change methods in the order.line model to get the line update with calculations ...

let's try:

    @api.multi
def add_to_offer(self):
line_env = self.env['sale.order.line']
for wizard in self:
for what in wizard.entries:
new_line = line_env.create({
                            'product_id': what.product_id.id,
                            'name': what.product_id.name,
                            'order_id': what.sale_order_id.id,
                            'product_uom' : what.product_id.uom_id.id})
new_line.product_id_change() #Calling an onchange method to update the record


Then you'll get the Sale order update by the new values ..

Hope this could helps

5
Avatar
Annuleer
Răzvan Anastasescu

In my case (v14.0) everything was fine by just adding the product as a new sale order line except the discount calculation.

So the only thing which worked to trigger that was:

`new_line._onchange_discount()`

Thx for the hint!

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
Add "Add Products" to my custom module like in sale quotation Opgelost
module sale custom sale.order.line quotation
Avatar
Avatar
2
jul. 17
6682
How to generate line numbers on quotes Opgelost
sale sale.order.line
Avatar
Avatar
1
jan. 25
4290
How to add freight charges to product cost in sale quoatation
sale sale.order.line
Avatar
Avatar
2
aug. 24
6393
What's the use of Allotment Partner in sale order line? Opgelost
sale sale.order.line
Avatar
Avatar
Avatar
Avatar
Avatar
6
dec. 22
9692
Odoo 19 - how does rounding work on Sales Order Lines? The Total isn't the sum of the order line totals Opgelost
sale sale.order.line sale.order
Avatar
Avatar
1
nov. 25
272
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