Skip to content

Commit

Permalink
[ADD] values tree view on product attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Kev-Roche committed Mar 7, 2022
1 parent f9a7983 commit 9522d80
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions product_usability/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'views/product_template_view.xml',
'views/product_product.xml',
'views/product_category_view.xml',
'views/product_attribute_view.xml',
],
'installable': True,
}
1 change: 1 addition & 0 deletions product_usability/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from . import product_supplierinfo
from . import product_pricelist
from . import product_category
from . import product_attribute
27 changes: 27 additions & 0 deletions product_usability/models/product_attribute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (C) 2022 Akretion (<http://www.akretion.com>).
# @author Kévin Roche <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models

class ProductAttribute(models.Model):
_inherit = "product.attribute"

values_count = fields.Integer(compute="_compute_values_count")

@api.depends("value_ids")
def _compute_values_count(self):
for attr in self:
attr.values_count = len(attr.value_ids)

def show_values_ids(self):
return {
"name": "Attributes Lines",
"type": "ir.actions.act_window",
"res_id": self.id,
"view_mode": "tree",
"res_model": "product.attribute.value",
"view_id":self.env.ref("product_usability.product_attribute_value_view_tree").id,
"target": "current",
"domain": [("id", "in", self.value_ids.ids)],
}
38 changes: 38 additions & 0 deletions product_usability/views/product_attribute_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>

<record id="product_attribute_values_button" model="ir.ui.view">
<field name="model">product.attribute</field>
<field name="inherit_id" ref="product.product_attribute_view_form" />
<field name="arch" type="xml">
<group name="main_fields" position='before'>
<div class="oe_button_box" name="button_box">
<button
name="show_values_ids"
type="object"
class="oe_stat_button"
icon="fa-tasks"
>
<field
name="values_count"
widget="statinfo"
string="Attribute Values"
/>
</button>
</div>
</group>
</field>
</record>

<record model="ir.ui.view" id="product_attribute_value_view_tree">
<field name="name">product.attribute.value.view.tree</field>
<field name="model">product.attribute.value</field>
<field name="arch" type="xml">
<tree string="Attributes Values">
<field name="name"/>
<field name="is_custom"/>
</tree>
</field>
</record>

</odoo>

0 comments on commit 9522d80

Please sign in to comment.