Skip to content

Commit 5c4f3ea

Browse files
[MIG] product_assortment: Migration to 18.0
1 parent deff106 commit 5c4f3ea

11 files changed

+58
-45
lines changed

product_assortment/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"name": "Product Assortment",
77
"summary": """
88
Adds the ability to manage products assortment""",
9-
"version": "16.0.2.0.0",
9+
"version": "18.0.1.0.0",
1010
"license": "AGPL-3",
1111
"development_status": "Production/Stable",
1212
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",

product_assortment/data/ir_cron.xml

-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
/>
2222
<field name="interval_number">1</field>
2323
<field name="interval_type">days</field>
24-
<field name="numbercall">-1</field>
25-
<field name="doall" eval="False" />
2624
<field name="active" eval="False" />
2725
<field
2826
name="nextcall"

product_assortment/i18n/ca.po

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ msgid "Partners to apply"
117117
msgstr "Socis a aplicar"
118118

119119
#. module: product_assortment
120-
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_tree
120+
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_list
121121
msgid "Product"
122122
msgstr "Producte"
123123

product_assortment/i18n/de.po

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ msgid "Partners to apply"
124124
msgstr ""
125125

126126
#. module: product_assortment
127-
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_tree
127+
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_list
128128
msgid "Product"
129129
msgstr "Produkt"
130130

product_assortment/i18n/es.po

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ msgid "Partners to apply"
125125
msgstr "Contactos a los que aplica"
126126

127127
#. module: product_assortment
128-
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_tree
128+
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_list
129129
msgid "Product"
130130
msgstr "Producto"
131131

product_assortment/i18n/fr.po

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ msgid "Partners to apply"
123123
msgstr "Appliquer aux partenaires"
124124

125125
#. module: product_assortment
126-
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_tree
126+
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_list
127127
msgid "Product"
128128
msgstr "Produit"
129129

product_assortment/i18n/it.po

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ msgid "Partners to apply"
124124
msgstr "Partner da applicare"
125125

126126
#. module: product_assortment
127-
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_tree
127+
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_list
128128
msgid "Product"
129129
msgstr "Prodotto"
130130

product_assortment/i18n/product_assortment.pot

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ msgid "Partners to apply"
113113
msgstr ""
114114

115115
#. module: product_assortment
116-
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_tree
116+
#: model_terms:ir.ui.view,arch_db:product_assortment.product_product_view_list
117117
msgid "Product"
118118
msgstr ""
119119

product_assortment/models/ir_filters.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright 2023 Tecnativa - Carlos Dauden
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44

5-
from odoo import _, api, fields, models
5+
from odoo import api, fields, models
66
from odoo.osv import expression
77
from odoo.tools import ormcache
88
from odoo.tools.safe_eval import datetime, safe_eval
@@ -52,9 +52,7 @@ class IrFilters(models.Model):
5252

5353
@api.model
5454
def _get_default_is_assortment(self):
55-
if self.env.context.get("product_assortment", False):
56-
return True
57-
return False
55+
return self.env.context.get("product_assortment", False)
5856

5957
@api.model
6058
def _update_assortment_default_values(self, vals_list):
@@ -83,7 +81,7 @@ def get_partner_domain_fields(self):
8381
for ir_filter in self.sudo().search([("is_assortment", "=", True)]):
8482
domain = ir_filter._get_eval_partner_domain()
8583
for item in domain:
86-
if isinstance(item, (list, tuple)) and isinstance(item[0], str):
84+
if isinstance(item, list | tuple) and isinstance(item[0], str):
8785
field_set.add(item[0].split(".")[0])
8886
return field_set
8987

@@ -146,13 +144,18 @@ def _compute_record_count(self):
146144
record.record_count = self.env[record.model_id].search_count(domain)
147145

148146
@api.model
149-
def _get_action_domain(self, action_id=None):
147+
def _get_action_domain(
148+
self, action_id=None, embedded_action_id=None, embedded_parent_res_id=None
149+
):
150150
# tricky way to act on get_filter method to prevent returning
151151
# assortment in search view filters
152-
domain = super()._get_action_domain(action_id=action_id)
153-
domain = expression.AND([[("is_assortment", "=", False)], domain])
152+
res = super()._get_action_domain(
153+
action_id=action_id,
154+
embedded_action_id=embedded_action_id,
155+
embedded_parent_res_id=embedded_parent_res_id,
156+
)
154157

155-
return domain
158+
return res + [("is_assortment", "=", False)]
156159

157160
def write(self, vals):
158161
res = super().write(vals)
@@ -167,7 +170,7 @@ def show_products(self):
167170
action.update(
168171
{
169172
"domain": self._get_eval_domain(),
170-
"name": _("Products"),
173+
"name": self.env._("Products"),
171174
"context": self.env.context,
172175
"target": "current",
173176
}

product_assortment/tests/test_product_assortment.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class TestProductAssortment(TransactionCase):
1010
def setUp(self):
11-
super(TestProductAssortment, self).setUp()
11+
super().setUp()
1212
self.filter_obj = self.env["ir.filters"]
1313
self.product_obj = self.env["product.product"]
1414
self.assortment = self.filter_obj.create(
@@ -91,7 +91,24 @@ def test_product_assortment_view(self):
9191
included_product = self.env.ref("product.product_product_7")
9292
self.assortment.write({"whitelist_product_ids": [(4, included_product.id)]})
9393
res = self.assortment.show_products()
94-
self.assertEqual(res["domain"], [("id", "in", [included_product.id])])
94+
# 1=1 is the default open domain for any search result
95+
self.assertEqual(res["domain"], [(1, "=", 1)])
96+
97+
def test_product_assortment_filter_combination(self):
98+
"""Combine a whitelisted and a blacklisted product in order
99+
to validate the combination of both filters. The result should be a
100+
simple domain with the excluded product.
101+
"""
102+
# Add a default no product filter to the assortment
103+
included_product = self.env.ref("product.product_product_7")
104+
self.assortment.write({"whitelist_product_ids": [(4, included_product.id)]})
105+
excluded_product = self.env.ref("product.product_product_2")
106+
self.assortment.write({"blacklist_product_ids": [(4, excluded_product.id)]})
107+
res = self.assortment.show_products()
108+
self.assertEqual(
109+
res["domain"],
110+
[("id", "not in", [excluded_product.id])],
111+
)
95112

96113
def test_record_count(self):
97114
products = self.product_obj.search([])
@@ -111,7 +128,7 @@ def test_assortment_with_partner_domain(self):
111128
assortment = self.filter_obj.with_context(product_assortment=True).create(
112129
{
113130
"name": "Test Assortment Partner domain",
114-
"partner_domain": "[('id', '=', %s)]" % self.partner.id,
131+
"partner_domain": f"[('id', '=', {self.partner.id})]",
115132
"partner_ids": [(4, self.partner2.id)],
116133
}
117134
)

product_assortment/views/product_assortment.xml

+18-23
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
</search>
1313
</field>
1414
</record>
15-
<record id="product_assortment_view_tree" model="ir.ui.view">
15+
<record id="product_assortment_view_list" model="ir.ui.view">
1616
<field name="model">ir.filters</field>
1717
<field name="arch" type="xml">
18-
<tree>
18+
<list>
1919
<field name="name" />
20-
</tree>
20+
</list>
2121
</field>
2222
</record>
2323

@@ -39,24 +39,20 @@
3939
<span class="o_stat_value">
4040
<field name="record_count" />
4141
</span>
42-
<span
43-
attrs="{'invisible': [('record_count', '&lt;=', 1)]}"
44-
>
45-
Products
46-
</span>
47-
<span
48-
attrs="{'invisible': [('record_count', '&gt;', 1)]}"
49-
>
50-
Product
51-
</span>
42+
<span invisible="record_count == 1">
43+
Products
44+
</span>
45+
<span invisible="record_count != 1">
46+
Product
47+
</span>
5248
</div>
5349
</button>
5450
</div>
5551
<widget
5652
name="web_ribbon"
5753
title="Archived"
5854
bg_color="bg-danger"
59-
attrs="{'invisible': [('active', '=', True)]}"
55+
invisible="active"
6056
/>
6157
<div class="oe_title">
6258
<label for="name" string="Assortment Name" />
@@ -85,7 +81,7 @@
8581
</group>
8682
<group
8783
string="Restricted product domain"
88-
attrs="{'invisible': [('apply_black_list_product_domain', '=', False)]}"
84+
invisible="not apply_black_list_product_domain"
8985
>
9086
<field
9187
name="black_list_product_domain"
@@ -110,17 +106,16 @@
110106
name="whitelist_product_ids"
111107
nolabel="1"
112108
colspan="2"
113-
context="{'tree_view_ref': 'product_assortment.product_product_view_tree'}"
109+
context="{'list_view_ref': 'product_assortment.product_product_view_list'}"
114110
/>
115111
</group>
116112
<group name="to_exclude" string="Products to exclude">
117113
<field
118114
name="blacklist_product_ids"
119115
nolabel="1"
120116
colspan="2"
121-
context="{'tree_view_ref': 'product_assortment.product_product_view_tree'}"
122-
>>
123-
</field>
117+
context="{'list_view_ref': 'product_assortment.product_product_view_list'}"
118+
/>
124119
</group>
125120
</group>
126121
<group
@@ -133,12 +128,12 @@
133128
</form>
134129
</field>
135130
</record>
136-
<record id="product_product_view_tree" model="ir.ui.view">
131+
<record id="product_product_view_list" model="ir.ui.view">
137132
<field name="model">product.product</field>
138133
<field name="arch" type="xml">
139-
<tree>
134+
<list>
140135
<field name="display_name" string="Product" />
141-
</tree>
136+
</list>
142137
</field>
143138
</record>
144139
<record id="actions_product_assortment_view" model="ir.actions.act_window">
@@ -151,7 +146,7 @@
151146
<field
152147
name="view_ids"
153148
eval="[(5, 0, 0),
154-
(0, 0, {'view_mode': 'tree', 'view_id': ref('product_assortment_view_tree')}),
149+
(0, 0, {'view_mode': 'list', 'view_id': ref('product_assortment_view_list')}),
155150
(0, 0, {'view_mode': 'form', 'view_id': ref('product_assortment_view_form')})]"
156151
/>
157152
</record>

0 commit comments

Comments
 (0)