Hello,
Currently in Odoo warning on the onchange product is available for the only sale.order (Sale module). It is not raised when you change the product in account.invoice. Generally in Odoo invoice is created from sale.order so they are not put this option in invoicing.
So to raise a warning on adding a product to an invoice you have to call the onchange method of product in account.invoice and raise warning.
you can refer the below method in sale module sale.py : 1002:
@api.multi
@api.onchange('product_id')
def product_id_change(self):
if not self.product_id:
return {'domain': {'product_uom': []}}
vals = {}
domain = {'product_uom': [('category_id', '=', self.product_id.uom_id.category_id.id)]}
if not self.product_uom or (self.product_id.uom_id.id != self.product_uom.id):
vals['product_uom'] = self.product_id.uom_id
vals['product_uom_qty'] = 1.0
product = self.product_id.with_context(
lang=self.order_id.partner_id.lang,
partner=self.order_id.partner_id.id,
quantity=vals.get('product_uom_qty') or self.product_uom_qty,
date=self.order_id.date_order,
pricelist=self.order_id.pricelist_id.id,
uom=self.product_uom.id
)
result = {'domain': domain}
title = False
message = False
warning = {}
if product.sale_line_warn != 'no-message':
title = _("Warning for %s") % product.name
message = product.sale_line_warn_msg
warning['title'] = title
warning['message'] = message
result = {'warning': warning}
if product.sale_line_warn == 'block':
self.product_id = False
return result
name = product.name_get()[0][1]
if product.description_sale:
name += '\n' + product.description_sale
vals['name'] = name
self._compute_tax_id()
if self.order_id.pricelist_id and self.order_id.partner_id:
vals['price_unit'] = self.env['account.tax']._fix_tax_included_price_company(self._get_display_price(product), product.taxes_id, self.tax_id, self.company_id)
self.update(vals)
return result
If you want more help you can contact us.
Thank You.
Hi, have a look at this paid solution - https://apps.odoo.com/apps/modules/11.0/smart_warnings/. It let configure almost any sort of warnings for any document
Thanks for the suggestion! However if a user validates the invoice without saving it prior, will the warning be displayed before the invoice confirmation?
Anyway, i'll keep in mind the plugin for other projects.
Yes, warnings are regretfully shown only after reloading (after saving or refreshing a page, e.g.)