Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Guest House
    • Distributeur de boissons
    • Hotel
    Real Estate
    • Real Estate Agency
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consulting
    • Accounting Firm
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Solar Energy Systems
    • Cordonnier
    • Services de nettoyage
    • HVAC Services
    Others
    • Nonprofit Organization
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

Programmatically create a sale order line

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
modulesalesale.order.lineprogramaticallyv9
1 Répondre
34549 Vues
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
Ignorer
Avatar
Qutechs, Ahmed M.Elmubarak
Meilleure réponse

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
Ignorer
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!

Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
Add "Add Products" to my custom module like in sale quotation Résolu
module sale custom sale.order.line quotation
Avatar
Avatar
2
juil. 17
6682
How to generate line numbers on quotes Résolu
sale sale.order.line
Avatar
Avatar
1
janv. 25
4284
How to add freight charges to product cost in sale quoatation
sale sale.order.line
Avatar
Avatar
2
août 24
6389
What's the use of Allotment Partner in sale order line? Résolu
sale sale.order.line
Avatar
Avatar
Avatar
Avatar
Avatar
6
déc. 22
9688
Odoo 19 - how does rounding work on Sales Order Lines? The Total isn't the sum of the order line totals Résolu
sale sale.order.line sale.order
Avatar
Avatar
1
nov. 25
265
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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