Skip to content

Commit

Permalink
[MIG] product_set: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NICO-SOLUTIONS committed Mar 26, 2024
1 parent e18482b commit 5936133
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 23 deletions.
2 changes: 2 additions & 0 deletions product_set/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ Contributors

- Pilar Vargas

- Nils Coenen <[email protected]>

Other credits
-------------

Expand Down
2 changes: 1 addition & 1 deletion product_set/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"category": "Sale",
"license": "AGPL-3",
"author": "Anybox, Odoo Community Association (OCA)",
"version": "16.0.3.0.0",
"version": "17.0.1.0.0",
"website": "https://github.com/OCA/product-attribute",
"depends": ["product"],
"data": [
Expand Down
27 changes: 15 additions & 12 deletions product_set/models/product_set.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Copyright 2015 Anybox S.A.S
# Copyright 2016-2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
from odoo import api, fields, models


class ProductSet(models.Model):
_name = "product.set"
_description = "Product set"

name = fields.Char(help="Product set name", required=True)
name = fields.Char(help="Product set name", required=True, translate=True)
active = fields.Boolean(default=True)
ref = fields.Char(
string="Internal Reference", help="Product set internal reference", copy=False
Expand All @@ -32,14 +32,17 @@ class ProductSet(models.Model):
"it's going to be available for all of them.",
)

def name_get(self):
return [(rec.id, rec._name_get()) for rec in self]
display_name = fields.Char(
compute="_compute_display_name", string="Display Name", store=False, translate=True
)

def _name_get(self):
parts = []
if self.ref:
parts.append("[%s]" % self.ref)
parts.append(self.name)
if self.partner_id:
parts.append("@ %s" % self.partner_id.name)
return " ".join(parts)
@api.depends("name", "ref", "partner_id.name")
def _compute_display_name(self):
for rec in self:
parts = []
if rec.ref:
parts.append("[%s]" % rec.ref)
parts.append(rec.name or "")
if rec.partner_id and rec.partner_id.name:
parts.append("@ %s" % rec.partner_id.name)
rec.display_name = " ".join(map(str, parts))
1 change: 1 addition & 0 deletions product_set/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
- Manuel Regidor \<<[email protected]>\>
- [Tecnativa](https://www.tecnativa.com):
- Pilar Vargas
- Nils Coenen \<<[email protected]>\>
1 change: 1 addition & 0 deletions product_set/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li>Pilar Vargas</li>
</ul>
</li>
<li>Nils Coenen &lt;<a class="reference external" href="mailto:nils.coenen&#64;nico-solutions.de">nils.coenen&#64;nico-solutions.de</a>&gt;</li>
</ul>
</div>
<div class="section" id="other-credits">
Expand Down
13 changes: 10 additions & 3 deletions product_set/tests/test_product_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ def test_name(self):
# no ref
product_set.name = "Foo"
product_set.ref = ""
self.assertEqual(product_set.name_get(), [(product_set.id, "Foo")])
self.assertEqual(
product_set.read(["display_name"]),
[{"id": product_set.id, "display_name": "Foo"}],
)
# with ref
product_set.ref = "123"
self.assertEqual(product_set.name_get(), [(product_set.id, "[123] Foo")])
self.assertEqual(
product_set.read(["display_name"]),
[{"id": product_set.id, "display_name": "[123] Foo"}],
)
# with partner
partner = self.env.ref("base.res_partner_1")
product_set.partner_id = partner
self.assertEqual(
product_set.name_get(), [(product_set.id, "[123] Foo @ %s" % partner.name)]
product_set.read(["display_name"]),
[{"id": product_set.id, "display_name": "[123] Foo @ %s" % partner.name}],
)
7 changes: 2 additions & 5 deletions product_set/views/product_set.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
name="web_ribbon"
title="Archived"
bg_color="bg-danger"
attrs="{'invisible': [('active', '=', True)]}"
invisible="active"
/>
<div class="oe_button_box" name="button_box" />
<group name="main">
Expand All @@ -48,10 +48,7 @@
>
<tree editable="top">
<field name="sequence" widget="handle" />
<field
name="product_id"
attrs="{'required': [('display_type', '=', False)]}"
/>
<field name="product_id" required="not display_type" />
<field name="quantity" />
<field name="display_type" invisible="1" />
<field name="name" widget="section_and_note_text" />
Expand Down
3 changes: 1 addition & 2 deletions product_set/wizard/product_set_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def _compute_product_set_line_ids(self):

def _get_lines(self):
# hook here to take control on used lines
for set_line in self.product_set_line_ids:
yield set_line
yield from self.product_set_line_ids

Check warning on line 37 in product_set/wizard/product_set_wizard.py

View check run for this annotation

Codecov / codecov/patch

product_set/wizard/product_set_wizard.py#L37

Added line #L37 was not covered by tests

def _check_partner(self):
"""This method may be extended in other modules that use product_set as a base."""
Expand Down

0 comments on commit 5936133

Please sign in to comment.