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

Automate CRM leads with sales.order

Suscribirse

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

Se marcó esta pregunta
crmsales.ordercrm.lead
2 Respuestas
2707 Vistas
Avatar
Lucas Sanches

Hello, good afternoon! I'm using Odoo to register several leads and structured the kanban pipeline as follows: new -> qualified -> proposition -> won. 

The idea is that when changing the stage to "won", Odoo retrieves the lead data and creates a subscription/invoice in the sales.order. I tried to develop some things, even with code, but it always returns the error:

The operation cannot be completed: 

Create/update: a mandatory field is not set. 

Delete: another model requires the record being deleted. If possible, archive it instead. 

Model: Sales Order (sale.order) 

Field: Customer (partner_id). 

Would anyone know how to provide some coding for this use?

0
Avatar
Descartar
Apiuser

What have you tried so far? What was your code?

Avatar
Cybrosys Techno Solutions Pvt.Ltd
Mejor respuesta

Hi,


The error you’re getting is very common when trying to automatically create a Sales Order from a CRM Lead in Odoo. It basically says that the partner_id (Customer) is not set when creating the sale order, and partner_id is mandatory.


Try the following code,


from odoo import models, api, fields

from odoo.exceptions import UserError


class CrmLead(models.Model):

    _inherit = 'crm.lead'


    def action_create_sale_order(self):

        for lead in self:

            if not lead.partner_id:

                raise UserError("Please set a Customer for this lead before creating a Sales Order.")


            sale_order_vals = {

                'partner_id': lead.partner_id.id,

                'origin': lead.name,

                'order_line': [(0, 0, {

                    'product_id': lead.product_id.id if lead.product_id else False,

                    'product_uom_qty': 1,

                    'price_unit': lead.expected_revenue or 0.0,

                })],

            }

            self.env['sale.order'].create(sale_order_vals)


Trigger the method on stage change


    def write(self, vals):

        res = super(CrmLead, self).write(vals)

        if 'stage_id' in vals:

            for lead in self:

                if lead.stage_id.name.lower() == 'won':

                    lead.action_create_sale_order()

        return res


* Customer must exist: The partner_id field is mandatory for sale.order. If your leads don’t have a customer yet, you need to either:

          - Force the user to select one before moving to “won”, or

          - Automatically create a partner from the lead data.

* Optional products: If the lead doesn’t have a product, you can skip or use a default product.

* Order lines: You can customize the order lines as needed, e.g., subscription, quantity, or price.



Hope it helps

0
Avatar
Descartar
Avatar
Sandeep
Mejor respuesta

It looks like you're running into a common issue when automating sales order creation from CRM leads: missing required fields. The error message indicates that the partner_id field (Customer) in the sale.order model is not being set when you're trying to create the sales order.



  First, ensure that your lead has a customer (partner_id) associated with it. The automation needs to pull this customer data from the lead.

  Next, in your code, make sure you're explicitly setting the partner_id field when creating the sale.order. For example:
  order_vals = {'partner_id': lead.partner_id.id, 'other_field': lead.other_field}

  Finally, double-check that lead.partner_id is actually populated with a valid customer before attempting to create the sales order. Add a check to ensure lead.partner_id exists.


Resources:
https://blog.pragtech.co.in/pos-whatsapp-integration-how-to-go-beyond-receipts-and-build-customer-relationships/#respond

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
new row violates check constraint "ir_model_data_name_nospaces Error while importing data Resuelto
crm crm.lead
Avatar
Avatar
1
jun 24
4320
Remove kanban view from crm pipeline Resuelto
crm crm.lead
Avatar
Avatar
2
sept 22
3966
Odoo 12 :Can i invisible crm menu string using attrs Resuelto
crm crm.lead
Avatar
Avatar
Avatar
2
oct 19
4334
[ODOO V12] How to link an outside sales order to an existing opportunity in the CRM? Resuelto
crm sales.order odoo12
Avatar
Avatar
1
nov 25
3846
[ODOO V12] How to link an outside sales order to an existing opportunity in the CRM? Resuelto
crm sales.order team
Avatar
Avatar
Avatar
2
mar 24
2024
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