Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita una demostración
  • Precios
  • Ayuda

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

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyectos
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

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

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
purchasesalesale.order.lineonchange
1 Responder
8538 Vistas
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
Mejor respuesta

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
¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Registrarse
Publicaciones relacionadas Respuestas Vistas Actividad
How to generate line numbers on quotes Resuelto
sale sale.order.line
Avatar
Avatar
1
ene 25
4398
How can enter freight charges and transporting Charges in sale order? Resuelto
purchase sale
Avatar
Avatar
1
ago 24
6357
How to add freight charges to product cost in sale quoatation
sale sale.order.line
Avatar
Avatar
2
ago 24
6428
What's the use of Allotment Partner in sale order line? Resuelto
sale sale.order.line
Avatar
Avatar
Avatar
Avatar
Avatar
6
dic 22
9785
Sale order line description to purchase order line.
purchase sale sale.order.line purchase_order purchase.order
Avatar
Avatar
1
oct 22
5158
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidad
  • Seguridad
الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y estar totalmente integrado.

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