Skip to content

Commit

Permalink
[MIG] product_assortment: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PieterPaulussen committed Dec 20, 2024
1 parent deff106 commit 8dbe676
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 46 deletions.
2 changes: 1 addition & 1 deletion product_assortment/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name": "Product Assortment",
"summary": """
Adds the ability to manage products assortment""",
"version": "16.0.2.0.0",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"development_status": "Production/Stable",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
Expand Down
2 changes: 0 additions & 2 deletions product_assortment/data/ir_cron.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
/>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False" />
<field name="active" eval="False" />
<field
name="nextcall"
Expand Down
2 changes: 1 addition & 1 deletion product_assortment/i18n/ca.po
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ msgid "Partners to apply"
msgstr "Socis a aplicar"

#. module: product_assortment
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_tree
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_list
msgid "Product"
msgstr "Producte"

Expand Down
2 changes: 1 addition & 1 deletion product_assortment/i18n/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ msgid "Partners to apply"
msgstr ""

#. module: product_assortment
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_tree
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_list
msgid "Product"
msgstr "Produkt"

Expand Down
2 changes: 1 addition & 1 deletion product_assortment/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ msgid "Partners to apply"
msgstr "Contactos a los que aplica"

#. module: product_assortment
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_tree
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_list
msgid "Product"
msgstr "Producto"

Expand Down
2 changes: 1 addition & 1 deletion product_assortment/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ msgid "Partners to apply"
msgstr "Appliquer aux partenaires"

#. module: product_assortment
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_tree
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_list
msgid "Product"
msgstr "Produit"

Expand Down
2 changes: 1 addition & 1 deletion product_assortment/i18n/it.po
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ msgid "Partners to apply"
msgstr "Partner da applicare"

#. module: product_assortment
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_tree
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_list
msgid "Product"
msgstr "Prodotto"

Expand Down
2 changes: 1 addition & 1 deletion product_assortment/i18n/product_assortment.pot
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ msgid "Partners to apply"
msgstr ""

#. module: product_assortment
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_tree
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_list
msgid "Product"
msgstr ""

Expand Down
25 changes: 14 additions & 11 deletions product_assortment/models/ir_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright 2023 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.osv import expression
from odoo.tools import ormcache
from odoo.tools.safe_eval import datetime, safe_eval
Expand Down Expand Up @@ -52,9 +52,7 @@ class IrFilters(models.Model):

@api.model
def _get_default_is_assortment(self):
if self.env.context.get("product_assortment", False):
return True
return False
return self.env.context.get("product_assortment", False)

@api.model
def _update_assortment_default_values(self, vals_list):
Expand Down Expand Up @@ -83,7 +81,7 @@ def get_partner_domain_fields(self):
for ir_filter in self.sudo().search([("is_assortment", "=", True)]):
domain = ir_filter._get_eval_partner_domain()

Check warning on line 82 in product_assortment/models/ir_filters.py

View check run for this annotation

Codecov / codecov/patch

product_assortment/models/ir_filters.py#L82

Added line #L82 was not covered by tests
for item in domain:
if isinstance(item, (list, tuple)) and isinstance(item[0], str):
if isinstance(item, list | tuple) and isinstance(item[0], str):
field_set.add(item[0].split(".")[0])

Check warning on line 85 in product_assortment/models/ir_filters.py

View check run for this annotation

Codecov / codecov/patch

product_assortment/models/ir_filters.py#L85

Added line #L85 was not covered by tests
return field_set

Expand Down Expand Up @@ -146,18 +144,23 @@ def _compute_record_count(self):
record.record_count = self.env[record.model_id].search_count(domain)

@api.model
def _get_action_domain(self, action_id=None):
def _get_action_domain(
self, action_id=None, embedded_action_id=None, embedded_parent_res_id=None
):
# tricky way to act on get_filter method to prevent returning
# assortment in search view filters
domain = super()._get_action_domain(action_id=action_id)
domain = expression.AND([[("is_assortment", "=", False)], domain])
res = super()._get_action_domain(
action_id=action_id,
embedded_action_id=embedded_action_id,
embedded_parent_res_id=embedded_parent_res_id,
)

return domain
return res + [("is_assortment", "=", False)]

def write(self, vals):
res = super().write(vals)
if "partner_ids" in vals or "partner_domain" in vals:
self.clear_caches()
self.env.registry.clear_cache()

Check warning on line 163 in product_assortment/models/ir_filters.py

View check run for this annotation

Codecov / codecov/patch

product_assortment/models/ir_filters.py#L163

Added line #L163 was not covered by tests
return res

def show_products(self):
Expand All @@ -167,7 +170,7 @@ def show_products(self):
action.update(
{
"domain": self._get_eval_domain(),
"name": _("Products"),
"name": self.env._("Products"),
"context": self.env.context,
"target": "current",
}
Expand Down
23 changes: 20 additions & 3 deletions product_assortment/tests/test_product_assortment.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class TestProductAssortment(TransactionCase):
def setUp(self):
super(TestProductAssortment, self).setUp()
super().setUp()
self.filter_obj = self.env["ir.filters"]
self.product_obj = self.env["product.product"]
self.assortment = self.filter_obj.create(
Expand Down Expand Up @@ -91,7 +91,24 @@ def test_product_assortment_view(self):
included_product = self.env.ref("product.product_product_7")
self.assortment.write({"whitelist_product_ids": [(4, included_product.id)]})
res = self.assortment.show_products()
self.assertEqual(res["domain"], [("id", "in", [included_product.id])])
# 1=1 is the default open domain for any search result
self.assertEqual(res["domain"], [(1, "=", 1)])

def test_product_assortment_filter_combination(self):
"""Combine a whitelisted and a blacklisted product in order
to validate the combination of both filters. The result should be a
simple domain with the excluded product.
"""
# Add a default no product filter to the assortment
included_product = self.env.ref("product.product_product_7")
self.assortment.write({"whitelist_product_ids": [(4, included_product.id)]})
excluded_product = self.env.ref("product.product_product_2")
self.assortment.write({"blacklist_product_ids": [(4, excluded_product.id)]})
res = self.assortment.show_products()
self.assertEqual(
res["domain"],
[("id", "not in", [excluded_product.id])],
)

def test_record_count(self):
products = self.product_obj.search([])
Expand All @@ -111,7 +128,7 @@ def test_assortment_with_partner_domain(self):
assortment = self.filter_obj.with_context(product_assortment=True).create(
{
"name": "Test Assortment Partner domain",
"partner_domain": "[('id', '=', %s)]" % self.partner.id,
"partner_domain": f"[('id', '=', {self.partner.id})]",
"partner_ids": [(4, self.partner2.id)],
}
)
Expand Down
41 changes: 18 additions & 23 deletions product_assortment/views/product_assortment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
</search>
</field>
</record>
<record id="product_assortment_view_tree" model="ir.ui.view">
<record id="product_assortment_view_list" model="ir.ui.view">
<field name="model">ir.filters</field>
<field name="arch" type="xml">
<tree>
<list>
<field name="name" />
</tree>
</list>
</field>
</record>

Expand All @@ -39,24 +39,20 @@
<span class="o_stat_value">
<field name="record_count" />
</span>
<span
attrs="{'invisible': [('record_count', '&lt;=', 1)]}"
>
Products
</span>
<span
attrs="{'invisible': [('record_count', '&gt;', 1)]}"
>
Product
</span>
<span invisible="record_count == 1">
Products
</span>
<span invisible="record_count != 1">
Product
</span>
</div>
</button>
</div>
<widget
name="web_ribbon"
title="Archived"
bg_color="bg-danger"
attrs="{'invisible': [('active', '=', True)]}"
invisible="active"
/>
<div class="oe_title">
<label for="name" string="Assortment Name" />
Expand Down Expand Up @@ -85,7 +81,7 @@
</group>
<group
string="Restricted product domain"
attrs="{'invisible': [('apply_black_list_product_domain', '=', False)]}"
invisible="not apply_black_list_product_domain"
>
<field
name="black_list_product_domain"
Expand All @@ -110,17 +106,16 @@
name="whitelist_product_ids"
nolabel="1"
colspan="2"
context="{'tree_view_ref': 'product_assortment.product_product_view_tree'}"
context="{'list_view_ref': 'product_assortment.product_product_view_list'}"
/>
</group>
<group name="to_exclude" string="Products to exclude">
<field
name="blacklist_product_ids"
nolabel="1"
colspan="2"
context="{'tree_view_ref': 'product_assortment.product_product_view_tree'}"
>>
</field>
context="{'list_view_ref': 'product_assortment.product_product_view_list'}"
/>
</group>
</group>
<group
Expand All @@ -133,12 +128,12 @@
</form>
</field>
</record>
<record id="product_product_view_tree" model="ir.ui.view">
<record id="product_product_view_list" model="ir.ui.view">
<field name="model">product.product</field>
<field name="arch" type="xml">
<tree>
<list>
<field name="display_name" string="Product" />
</tree>
</list>
</field>
</record>
<record id="actions_product_assortment_view" model="ir.actions.act_window">
Expand All @@ -151,7 +146,7 @@
<field
name="view_ids"
eval="[(5, 0, 0),
(0, 0, {'view_mode': 'tree', 'view_id': ref('product_assortment_view_tree')}),
(0, 0, {'view_mode': 'list', 'view_id': ref('product_assortment_view_list')}),
(0, 0, {'view_mode': 'form', 'view_id': ref('product_assortment_view_form')})]"
/>
</record>
Expand Down

0 comments on commit 8dbe676

Please sign in to comment.