Odoo Hilfe


7 Antworten
Mayank Gosai USA - Vereinigte Staaten von Amerika
22.01.18, 11:17

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'
  print 'Service product'

5 Kommentare
tyrion Kanada
22.01.18, 11:36

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

Mayank Gosai USA - Vereinigte Staaten von Amerika
22.01.18, 11:58

Can you share your field declaration code ?

Your .py file.

tyrion Kanada
22.01.18, 12:13


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):


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'


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


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 USA - Vereinigte Staaten von Amerika
22.01.18, 12:19


I think in the loop your are missing variable line.

Can you try with line.product_id.product_tmpl_id.type

Hope it helps,


Mayank Gosai

Waleed Mohsen Jemen
22.01.18, 12:34

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

airacobra Spanien
25.01.18, 07:13

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).

Fragen Sie
Keep Informed
2 Verfolger
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now