In the product.template model , I added new smart button which return an ir.actions.act_window action to the model stock.quant , when clicking on the same button I want also to return a warning if there is a warning in the product based on conditions : Here is the code of warning:
if not self or not self.env.user.has_group('sale.group_warning_sale'): return
if self.sale_line_warn != 'no-message': if self.sale_line_warn_msg: message = self.sale_line_warn_msg warning = { 'title': ("Warning for %s") % self.name, 'message': message }
if self.sale_line_warn == 'block': self = False
return {'warning': warning}
Here is my function:
def my_action(self): return { 'name': _('Stock'), 'view_type': 'form', 'view_mode': 'tree', 'res_model': 'stock.quant', 'context': {'default_name': 'My warning message'}, 'type': 'ir.actions.act_window', }
*Any help please ? Is it possible to do it ? Thanks
xml file:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_product_inherit" model="ir.ui.view">
<field name="name">view_product_inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button class="oe_stat_button" name="my_action"
type="object" icon="fa-shopping-cart" string="Stock">
</button>
</div>
</field>
</record>
</odoo>