Skip to content

Commit

Permalink
[2890][IMP] product_alternative_code: add product views (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
yostashiro authored Dec 30, 2022
1 parent 3f1d9e0 commit fce11e3
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
3 changes: 2 additions & 1 deletion product_alternative_code/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
{
"name": "Product Alternative Code",
"version": "16.0.1.0.0",
"version": "16.0.1.1.0",
"author": "Quartile Limited",
"website": "https://www.quartile.co",
"category": "Product",
"license": "LGPL-3",
"depends": ["product"],
"data": [
"views/product_product_views.xml",
"views/product_template_views.xml",
],
"installable": True,
Expand Down
19 changes: 19 additions & 0 deletions product_alternative_code/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,22 @@ class ProductTemplate(models.Model):
_inherit = "product.template"

alt_code = fields.Char("Alternative Code", help="Alternative product code.")

def name_get(self):
res = super().name_get()
name_list = []
for rec in res:
product = self.browse(rec[0])
alt_code = product.alt_code
if not alt_code:
name_list.append(rec)
continue
name = rec[1]
if not product.default_code:
name = "[" + alt_code + "] " + name
name_list.append((rec[0], name))
continue
pos = name.find("]")
name = name[:pos] + "/" + alt_code + name[pos:]
name_list.append((rec[0], name))
return name_list
39 changes: 39 additions & 0 deletions product_alternative_code/views/product_product_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="product_product_tree_view" model="ir.ui.view">
<field name="name">product.product.tree</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_product_tree_view" />
<field name="arch" type="xml">
<xpath expr="//field[@name='default_code']" position="after">
<field name="alt_code" optional="show" readonly="1" />
</xpath>
</field>
</record>
<record id="product_normal_form_view" model="ir.ui.view">
<field name="name">product.product.form</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view" />
<field name="arch" type="xml">
<xpath expr="//field[@name='default_code']" position="after">
<field name="alt_code" />
</xpath>
</field>
</record>
<record id="product_search_form_view" model="ir.ui.view">
<field name="name">product.product.search</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_search_form_view" />
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="attributes">
<attribute name="filter_domain">[
'|', '|', '|',
('default_code', 'ilike', self),
('name', 'ilike', self),
('barcode', 'ilike', self),
('alt_code', 'ilike', self),
]</attribute>
</xpath>
</field>
</record>
</odoo>
17 changes: 17 additions & 0 deletions product_alternative_code/views/product_template_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,21 @@
</xpath>
</field>
</record>
<record id="product_template_search_view" model="ir.ui.view">
<field name="name">product.template.search</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_search_view" />
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="attributes">
<attribute name="filter_domain">[
'|', '|', '|', '|',
('default_code', 'ilike', self),
('product_variant_ids.default_code', 'ilike', self),
('name', 'ilike', self),
('barcode', 'ilike', self),
('alt_code', 'ilike', self),
]</attribute>
</xpath>
</field>
</record>
</odoo>

0 comments on commit fce11e3

Please sign in to comment.