Skip to content

Commit e12cca8

Browse files
committed
[ADD] values tree view on product attribute
1 parent f9a7983 commit e12cca8

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

product_usability/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
'views/product_template_view.xml',
3434
'views/product_product.xml',
3535
'views/product_category_view.xml',
36+
'views/product_attribute_view.xml',
3637
],
3738
'installable': True,
3839
}

product_usability/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
from . import product_supplierinfo
44
from . import product_pricelist
55
from . import product_category
6+
from . import product_attribute
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (C) 2022 Akretion (<http://www.akretion.com>).
2+
# @author Kévin Roche <kevin.roche@akretion.com>
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4+
5+
from odoo import api, fields, models
6+
7+
class ProductAttribute(models.Model):
8+
_inherit = "product.attribute"
9+
10+
values_count = fields.Integer(compute="_compute_values_count")
11+
12+
@api.depends("value_ids")
13+
def _compute_values_count(self):
14+
for attr in self:
15+
attr.values_count = len(attr.value_ids)
16+
17+
def show_values_ids(self):
18+
return {
19+
"name": "Attributes Lines",
20+
"type": "ir.actions.act_window",
21+
"res_id": self.id,
22+
"view_mode": "tree",
23+
"res_model": "product.attribute.value",
24+
"view_id":self.env.ref("product_usability.product_attribute_value_view_tree").id,
25+
"target": "current",
26+
"domain": [("id", "in", self.value_ids.ids)],
27+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<odoo>
3+
4+
<record id="product_attribute_values_button" model="ir.ui.view">
5+
<field name="model">product.attribute</field>
6+
<field name="inherit_id" ref="product.product_attribute_view_form" />
7+
<field name="arch" type="xml">
8+
<group name="main_fields" position='before'>
9+
<div class="oe_button_box" name="button_box">
10+
<button
11+
name="show_values_ids"
12+
type="object"
13+
class="oe_stat_button"
14+
icon="fa-tasks"
15+
>
16+
<field
17+
name="values_count"
18+
widget="statinfo"
19+
string="Attribute Values"
20+
/>
21+
</button>
22+
</div>
23+
</group>
24+
</field>
25+
</record>
26+
27+
<record model="ir.ui.view" id="product_attribute_value_view_tree">
28+
<field name="name">product.attribute.value.view.tree</field>
29+
<field name="model">product.attribute.value</field>
30+
<field name="arch" type="xml">
31+
<tree string="Attributes Values">
32+
<field name="name"/>
33+
<field name="is_custom"/>
34+
</tree>
35+
</field>
36+
</record>
37+
38+
</odoo>

0 commit comments

Comments
 (0)