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 check the product type of the product in the sale.order.line?[odoo10]

Suscribirse

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

Se marcó esta pregunta
productsale.ordertypesource_code
7 Respuestas
7684 Vistas
Avatar
tyrion

I have to check the product type of each line in the sale.order.line before invoicing. So in the sale.py I have added the code under action_invoice_create(self, grouped=False, final=False) method (line 342 of source code).

But the code doesn't enter the print condition according to the product type. How to correct?

if group_key not in invoices:
 if 'product_id.product_tmpl_id.type' == 'service':
  print 'Service product'
     elif 'product_id.product_tmpl_id.type' == 'stockable':
         print 'Stockable product'      
     else:
         print 'Service product'

0
Avatar
Descartar
Avatar
Mayank Gosai
Mejor respuesta

Hello Naksha,

All you did is correct , you just need to correct your field name declaration as you code it in string.

Replace this 'product_id.product_tmpl_id.type' to product_id.product_tmpl_id.type.

Paste this code:

if group_key not in invoices:
  if product_id.product_tmpl_id.type == 'service':
   print 'Service product'
elif product_id.product_tmpl_id.type == 'stockable':
      print 'Stockable product'
  else:
  print 'Service product'

1
Avatar
Descartar
tyrion
Autor

But removing the single quotes just make Unresolved reference 'product_id'. I tried that in pycharm.

Mayank Gosai

Can you share your field declaration code ?

Your .py file.

tyrion
Autor

@api.multi

def action_invoice_create(self, grouped=False, final=False):

"""

Create the invoice associated to the SO.

:param grouped: if True, invoices are grouped by SO id. If False, invoices are grouped by

(partner_invoice_id, currency)

:param final: if True, refunds will be generated if necessary

:returns: list of created invoices

"""

inv_obj = self.env['account.invoice']

precision = self.env['decimal.precision'].precision_get('Product Unit of Measure')

invoices = {}

references = {}

for order in self:

group_key = order.id if grouped else (order.partner_invoice_id.id, order.currency_id.id)

for line in order.order_line.sorted(key=lambda l: l.qty_to_invoice < 0):

if float_is_zero(line.qty_to_invoice, precision_digits=precision):

continue

if group_key not in invoices:

if group_key not in invoices:

if product_id.product_tmpl_id.type == 'service':

print 'Service product'

elif product_id.product_tmpl_id.type == 'stockable':

print 'Stockable product'

else:

print 'Consumable product'

inv_data = order._prepare_invoice()

invoice = inv_obj.create(inv_data)

references[invoice] = order

invoices[group_key] = invoice

elif group_key in invoices:

vals = {}

if order.name not in invoices[group_key].origin.split(', '):

vals['origin'] = invoices[group_key].origin + ', ' + order.name

if order.client_order_ref and order.client_order_ref not in invoices[group_key].name.split(', ') and order.client_order_ref != invoices[group_key].name:

vals['name'] = invoices[group_key].name + ', ' + order.client_order_ref

invoices[group_key].write(vals)

if line.qty_to_invoice > 0:

line.invoice_line_create(invoices[group_key].id, line.qty_to_invoice)

elif line.qty_to_invoice < 0 and final:

line.invoice_line_create(invoices[group_key].id, line.qty_to_invoice)

if references.get(invoices.get(group_key)):

if order not in references[invoices[group_key]]:

references[invoice] = references[invoice] | order

That is the source code from sale.py odoo 10 community edition(from line 324). I was trying my code directly there. (It's not the norm, just experimenting)

Mayank Gosai

Hi,

I think in the loop your are missing variable line.

Can you try with line.product_id.product_tmpl_id.type

Hope it helps,

Regards,

Mayank Gosai

Waleed Ali Mohsen

You modified the original sale.py file so you need to upgrade the sales app --> from Apps open sales app and upgrade it. give it a try

Avatar
airacobra
Mejor respuesta

action_invoice_create method belogs to "sale.order" model.  product_id field belongs to "sale.order.line" model and is linked in "sale.order" by order_line field.

So you can not refer to product_id without appropriate prefix: line.product_id in this case while iterating by self.order_line.

Anyway  to avoid future headake you should write custom module instead of changing standrd one. 

рекомендую почитать доки по питону (https://docs.python.org).

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
What are the product types in Odoo 14? Resuelto
product type
Avatar
Avatar
Avatar
Avatar
3
may 23
9457
Sale order State update (Sale order > sale to invoice)
product sale.order
Avatar
Avatar
1
ene 16
5357
How can I sell products with bundled usage and bill for excess consumption
product sale sale.order
Avatar
0
jul 24
1877
How to get related field value from database ? Resuelto
product sale sale.order
Avatar
Avatar
1
mar 24
15568
Product type file...add or edit types ?
product type add
Avatar
0
mar 15
5367
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.

Sitio web hecho con

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