-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] values tree view on product attribute
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# 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): | ||
attr_counts = {attr:len(attr.value_ids) for attr in self} | ||
for attr in self: | ||
attr.values_count = attr_counts.get(attr) | ||
|
||
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)], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |