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

How to autofill sale.order.line from linked purchase.order(.line)?

Subscriure's

Get notified when there's activity on this post

This question has been flagged
purchasesalesale.order.lineonchange
1 Respondre
8547 Vistes
Avatar
Christian Spitzl

Hi, I've created two modules.
The first one "Sale Quotation 2 Purchase Quotation" links a Sale Order with a Purchase Order and autofills the PO Lines with the values of the linked SO Lines.
So far, so good.
The second one "Purchase Order 2 Sale Order" gives me a lot of trouble. 
It should do nearly the same like the first one, only in the other direction. It should autofill the SO Lines with the values of the linked PO Lines.
The problem is the "product_id_change" method. It checks whether a customer is defined before you can chose a product.
How can I solve it and get it work?

Many thanks for an adivce.

 


FIRST:
Sale Quotation 2 Purchase Quotation

 

<code></p>

class purchase_order(osv.osv):

    _inherit = 'purchase.order'
    _name = 'purchase.order'
    
    STATE_SELECTION = [
        ('draft', 'Draft PO'),
        ('sent', 'RFQ Sent'),
        ('received', 'RFQ Received'),
        ('confirmed', 'Waiting Approval'),
        ('approved', 'Purchase Order'),
        ('except_picking', 'Shipping Exception'),
        ('except_invoice', 'Invoice Exception'),
        ('done', 'Done'),
        ('cancel', 'Cancelled')
    ]
    
    _columns = {
       'state': fields.selection(STATE_SELECTION, 'Status', readonly=True, select=True),
       'purchase_quotation_id': fields.many2one('sale.order', 'Sale Quotation', domain=[('state','in',('draft','sent'))]),
    }
    _defaults = {
        'state': 'draft',
        'purchase_quotation_id': lambda self, cr, uid, context: context.get('purchase_quotation_id', False),
    }

    def onchange_purchase_order(self, cr, uid, id, purchase_quotation_id, partner_id, pricelist_id):
        domain = []
        value = []
        if purchase_quotation_id:
            sale = self.pool.get('sale.order').browse(cr,uid,purchase_quotation_id)
            for line in sale.order_line:
                vals = self.pool.get('purchase.order.line').onchange_product_id(cr, uid, id, pricelist_id, line.product_id.id, line.product_uom_qty, line.product_uom.id, partner_id)
                vals['value'].update({
                    'product_id': line.product_id.id, 
                    'state':'draft', 
                    'move_ids':[], 
                    'invoiced':0,
                    'invoice_lines':[],
                })
            value.append(vals['value'])
            domain.append(vals['domain'])
        return {'value': {'order_line': value}, 'domain': {'order_line': domain}}    

 

class sale_order(osv.osv):
    _inherit = "sale.order"
    _name = "sale.order"

    _columns = {
        'sale_quotation': fields.one2many('purchase.order', 'purchase_quotation_id', 'Purchase Quotation'),
    }
    
sale_order()

</code></p>

 

SECOND:

Purchase Quotation 2 Sale Quotation

<code><p>

class sale_order(osv.osv):

    _inherit = 'sale.order'
    _name = 'sale.order'
    
    STATE_SELECTION = [
        ('draft', 'Draft Quotation'),
        ('sent', 'Quotation Sent'),
        ('cancel', 'Cancelled'),
        ('waiting_date', 'Waiting Schedule'),
        ('progress', 'Sale Order'),
        ('manual', 'Sale to Invoice'),
        ('invoice_except', 'Invoice Exception'),
        ('done', 'Done'),
    ]
    
    _columns = {
       'state': fields.selection(STATE_SELECTION, 'Status', readonly=True, select=True),
       'sale_quotation_id': fields.many2one('purchase.order', 'Purchase Quotation', domain=[('state','in',('draft','sent'))]),
    }
    _defaults = {
        'state': 'draft',
        'sale_quotation_id': lambda self, cr, uid, context: context.get('sale_quotation_id', False),
    }

    def onchange_sale_order(self, cr, uid, id, sale_quotation_id, partner_id, pricelist_id):
        domain = []
        value = []
        if sale_quotation_id:
            purchase = self.pool.get('purchase.order').browse(cr,uid,sale_quotation_id)
            for line in purchase.order_line:
>>>??            vals = self.pool.get('sale.order.line').product_id_change(cr, uid, id, pricelist_id, line.product_id.id, line.product_qty, line.product_uom.id, partner_id)
                vals['value'].update({
                    'product_id': line.product_id.id, 
                    'state':'draft', 
                    'move_ids':[], 
                    'invoiced':0,
                    'invoice_lines':[],
                })
            value.append(vals['value'])
            domain.append(vals['domain'])
        return {'value': {'order_line': value}, 'domain': {'order_line': domain}}    

 

class purchase_order(osv.osv):
    _inherit = "purchase.order"
    _name = "purchase.order"

    _columns = {
        'purchase_quotation': fields.one2many('sale.order', 'sale_quotation_id', 'Sale Quotation'),
    }
    
purchase_order()

</code></p>

0
Avatar
Descartar
Avatar
Ludo - 21South
Best Answer

Do not be offended by my remarks, but I was wondering why you went through all this effort instead of using Odoo regular procurement system for the previous work (from sale to purchase)? Is it because you did not want to confirm the sale before creating the purchase?

Other than that, I think its much simpler that the sketched situation. Create a wizard that takes the current sale order (usually in context under "active id") and use it to read the order line for line (assuming you already know where the purchase order goes), sending the product_id and qty to the on_change method for purchase order line. If configured correctly. You should first create a purchase order, but since that can practically be empty, you should have no trouble creating an order line for the PO based on its id.

Alternatively, you can check the system of procurements (procurement.order in Odoo) and write a method on that. Procurements already have links to both sales as well as purchase orders. Writing a simple method that converts it to purchase orders should do the trick. Then all you have to do is make sure the SO generates a procurement at a point you see fit.

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
How to generate line numbers on quotes Solved
sale sale.order.line
Avatar
Avatar
1
de gen. 25
4407
How can enter freight charges and transporting Charges in sale order? Solved
purchase sale
Avatar
Avatar
1
d’ag. 24
6361
How to add freight charges to product cost in sale quoatation
sale sale.order.line
Avatar
Avatar
2
d’ag. 24
6429
What's the use of Allotment Partner in sale order line? Solved
sale sale.order.line
Avatar
Avatar
Avatar
Avatar
Avatar
6
de des. 22
9793
Sale order line description to purchase order line.
purchase sale sale.order.line purchase_order purchase.order
Avatar
Avatar
1
d’oct. 22
5162
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