Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][ADD] values tree view on product attribute #165

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
bealdav marked this conversation as resolved.
Show resolved Hide resolved

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>