Skip to content

Commit

Permalink
Merge PR #227 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by lmignon
  • Loading branch information
OCA-git-bot committed Oct 5, 2023
2 parents 0cd0fa2 + e9a25b3 commit 4a87d1a
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 3 deletions.
60 changes: 59 additions & 1 deletion storage_image_product/models/image_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).


from odoo import api, fields, models
from odoo import _, api, fields, models


class ImageTag(models.Model):
Expand All @@ -27,3 +27,61 @@ def _get_default_apply_on(self):
selection=[("product", "Product"), ("category", "Category")],
default=lambda self: self._get_default_apply_on(),
)
product_img_rel_ids = fields.One2many(
comodel_name="product.image.relation",
inverse_name="tag_id",
string="Product Image Relations",
readonly=True,
)
categ_img_rel_ids = fields.One2many(
comodel_name="category.image.relation",
inverse_name="tag_id",
string="Category Image Relations",
readonly=True,
)
product_tmpl_count = fields.Integer(
string="# of Products", compute="_compute_product_tmpl_count"
)
product_categ_count = fields.Integer(
string="# of Categories", compute="_compute_product_categ_count"
)

@api.depends("product_img_rel_ids")
def _compute_product_tmpl_count(self):
for rec in self:
rec.product_tmpl_count = len(
rec.product_img_rel_ids.mapped("product_tmpl_id")
)

@api.depends("categ_img_rel_ids")
def _compute_product_categ_count(self):
for rec in self:
rec.product_categ_count = len(rec.categ_img_rel_ids.mapped("category_id"))

def action_open_product_templates(self):
self.ensure_one()
product_templates = self.product_img_rel_ids.mapped("product_tmpl_id")
if len(product_templates) >= 1:
result = {
"name": _("Products"),
"domain": [("id", "in", product_templates.ids)],
"res_model": "product.template",
"type": "ir.actions.act_window",
"view_mode": "list,form",
}
return result
return {"type": "ir.actions.act_window_close"}

def action_open_product_categories(self):
self.ensure_one()
product_categories = self.categ_img_rel_ids.mapped("category_id")
if len(product_categories) >= 1:
result = {
"name": _("Product Categories"),
"domain": [("id", "in", product_categories.ids)],
"res_model": "product.category",
"type": "ir.actions.act_window",
"view_mode": "list,form",
}
return result
return {"type": "ir.actions.act_window_close"}
44 changes: 42 additions & 2 deletions storage_image_product/views/image_tag.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<record id="image_tag_view_tree" model="ir.ui.view">
<field name="model">image.tag</field>
<field name="arch" type="xml">
<tree string="Image Tag" editable="bottom">
<tree string="Image Tag">
<field name="name" />
<field name="tech_name" />
<field name="apply_on" />
Expand All @@ -19,11 +19,51 @@
</search>
</field>
</record>
<record id="image_tag_view_form" model="ir.ui.view">
<field name="model">image.tag</field>
<field name="arch" type="xml">
<form string="Image Tag">
<sheet>
<div class="oe_button_box" name="button_box">
<button
class="oe_stat_button"
icon="fa-list"
name="action_open_product_templates"
type="object"
>
<field
name="product_tmpl_count"
widget="statinfo"
string="Products"
/>
</button>
<button
class="oe_stat_button"
icon="fa-list"
name="action_open_product_categories"
type="object"
>
<field
name="product_categ_count"
widget="statinfo"
string="Categories"
/>
</button>
</div>
<group name="main">
<field name="name" />
<field name="tech_name" />
<field name="apply_on" />
</group>
</sheet>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="act_open_image_tag_view">
<field name="name">Image Tag</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">image.tag</field>
<field name="view_mode">tree</field>
<field name="view_mode">tree,form</field>
<field name="search_view_id" ref="image_tag_view_search" />
<field name="domain">[]</field>
<field name="context">{}</field>
Expand Down

0 comments on commit 4a87d1a

Please sign in to comment.