Skip to content

Commit 5be9e10

Browse files
committed
[MIG] sell_only_by_packaging: Migration to 18.0
1 parent 6fe203d commit 5be9e10

14 files changed

Lines changed: 62 additions & 121 deletions

sell_only_by_packaging/README.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ Contributors
9898
- Hiep (Nguyen Hoang) <hiepnh@trobz.com>
9999
- Phuc (Tran Thanh) <phuc@trobz.com>
100100
- Duong (Tran Quoc) <duongtq@trobz.com>
101+
- Tris Doan <tridm@trobz.com>
101102

102103
Other credits
103104
-------------
104105

105-
The development of this module has been financially supported by:
106+
The development and migration of this module has been financially
107+
supported by:
106108

107109
- Camptocamp
108110

sell_only_by_packaging/__manifest__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
{
44
"name": "Sell Only By Packaging",
55
"summary": "Manage sale of packaging",
6-
"version": "16.0.1.1.0",
6+
"version": "18.0.1.0.0",
77
"development_status": "Alpha",
88
"category": "Warehouse Management",
99
"website": "https://github.com/OCA/sale-workflow",
1010
"author": "Camptocamp, BCIM, Odoo Community Association (OCA)",
1111
"license": "AGPL-3",
1212
"application": False,
1313
"installable": True,
14-
"depends": ["product_packaging_level_salable", "sale_stock"],
14+
"depends": ["product_packaging_level_salable"],
1515
"data": [
1616
"views/product_packaging.xml",
1717
"views/product_template.xml",

sell_only_by_packaging/models/product_packaging_level.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2020 Camptocamp SA
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
33

4-
from odoo import _, api, exceptions, models
4+
from odoo import api, exceptions, models
55

66

77
class ProductPackagingLevel(models.Model):
@@ -18,9 +18,10 @@ def _check_sell_only_by_packaging_can_be_sold_packaging_ids(self):
1818
templates._check_sell_only_by_packaging_can_be_sold_packaging_ids()
1919
except exceptions.ValidationError as e:
2020
raise exceptions.ValidationError(
21-
_(
22-
'Packaging level "{}" must stay with "Can be sold",'
21+
self.env._(
22+
'Packaging level %s must stay with "Can be sold",'
2323
' at least one product configured as "sell only'
24-
' by packaging" is using it.'
25-
).format(record.display_name)
24+
' by packaging" is using it.',
25+
record.display_name,
26+
),
2627
) from e

sell_only_by_packaging/models/product_template.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2020 Camptocamp SA
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
33

4-
from odoo import _, api, fields, models
4+
from odoo import api, fields, models
55
from odoo.exceptions import ValidationError
66

77

@@ -41,11 +41,11 @@ def _check_sell_only_by_packaging_sale_ok(self):
4141
for product in self:
4242
if product.sell_only_by_packaging and not product.sale_ok:
4343
raise ValidationError(
44-
_(
44+
self.env._(
4545
"Product %s cannot be defined to be sold only by "
46-
"packaging if it cannot be sold."
47-
)
48-
% product.name
46+
"packaging if it cannot be sold.",
47+
product.name,
48+
),
4949
)
5050

5151
@api.constrains("sell_only_by_packaging", "packaging_ids")
@@ -64,12 +64,12 @@ def _check_sell_only_by_packaging_can_be_sold_packaging_ids(self):
6464
)
6565
):
6666
raise ValidationError(
67-
_(
67+
self.env._(
6868
"Product %s cannot be defined to be sold only by "
6969
"packaging if it does not have any packaging that "
70-
"can be sold defined."
71-
)
72-
% product.name
70+
"can be sold defined.",
71+
product.name,
72+
),
7373
)
7474

7575
@api.depends("sale_ok")

sell_only_by_packaging/models/sale_order_line.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2020 Camptocamp SA
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
33

4-
from odoo import _, api, models
4+
from odoo import api, models
55
from odoo.exceptions import ValidationError
66
from odoo.tools import float_compare
77

@@ -27,18 +27,14 @@ def _check_product_packaging_sell_only_by_packaging(self):
2727
!= 0
2828
):
2929
raise ValidationError(
30-
_(
30+
self.env._(
3131
"Product %s can only be sold with a packaging and a "
32-
"packaging quantity."
33-
)
34-
% line.product_id.name
32+
"packaging quantity.",
33+
line.product_id.name,
34+
),
3535
)
3636

3737
def _force_qty_with_package(self):
38-
"""
39-
40-
:return:
41-
"""
4238
self.ensure_one()
4339
qty = self.product_id._convert_packaging_qty(
4440
self.product_uom_qty, self.product_uom, packaging=self.product_packaging_id

sell_only_by_packaging/readme/CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
- Hiep (Nguyen Hoang) \<<hiepnh@trobz.com>\>
66
- Phuc (Tran Thanh) \<<phuc@trobz.com>\>
77
- Duong (Tran Quoc) \<<duongtq@trobz.com>\>
8+
- Tris Doan \<<tridm@trobz.com>\>

sell_only_by_packaging/readme/CREDITS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The development of this module has been financially supported by:
1+
The development and migration of this module has been financially supported by:
22

33
- Camptocamp
44

sell_only_by_packaging/static/description/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,13 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
444444
<li>Hiep (Nguyen Hoang) &lt;<a class="reference external" href="mailto:hiepnh&#64;trobz.com">hiepnh&#64;trobz.com</a>&gt;</li>
445445
<li>Phuc (Tran Thanh) &lt;<a class="reference external" href="mailto:phuc&#64;trobz.com">phuc&#64;trobz.com</a>&gt;</li>
446446
<li>Duong (Tran Quoc) &lt;<a class="reference external" href="mailto:duongtq&#64;trobz.com">duongtq&#64;trobz.com</a>&gt;</li>
447+
<li>Tris Doan &lt;<a class="reference external" href="mailto:tridm&#64;trobz.com">tridm&#64;trobz.com</a>&gt;</li>
447448
</ul>
448449
</div>
449450
<div class="section" id="other-credits">
450451
<h2><a class="toc-backref" href="#toc-entry-6">Other credits</a></h2>
451-
<p>The development of this module has been financially supported by:</p>
452+
<p>The development and migration of this module has been financially
453+
supported by:</p>
452454
<ul class="simple">
453455
<li>Camptocamp</li>
454456
</ul>
Lines changed: 3 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,14 @@
11
# Copyright 2020 Camptocamp SA
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
33

4-
from odoo.tests.common import Form, TransactionCase
4+
from odoo.addons.product_packaging_level_salable.tests.common import Common
55

66
TU_PRODUCT_QTY = 20
77
PL_PRODUCT_QTY = TU_PRODUCT_QTY * 30
88

99

10-
class Common(TransactionCase):
11-
at_install = False
12-
post_install = True
13-
10+
class SellOnlyByPackagingCommon(Common):
1411
@classmethod
1512
def setUpClass(cls):
16-
super(Common, cls).setUpClass()
17-
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
13+
super().setUpClass()
1814
cls.env.user.groups_id += cls.env.ref("product.group_stock_packaging")
19-
cls.setUpClassPartner()
20-
cls.setUpClassProduct()
21-
cls.setUpClassPackagingType()
22-
cls.setUpClassPackaging()
23-
cls.setUpClassSaleOrder()
24-
cls.setUpClassConfig()
25-
26-
@classmethod
27-
def setUpClassConfig(cls):
28-
cls.precision = cls.env["decimal.precision"].precision_get("Product Price")
29-
30-
@classmethod
31-
def setUpClassPartner(cls):
32-
cls.partner = cls.env.ref("base.res_partner_12")
33-
34-
@classmethod
35-
def setUpClassProduct(cls):
36-
cls.product = cls.env.ref("product.product_product_9")
37-
38-
@classmethod
39-
def setUpClassPackagingType(cls):
40-
cls.packaging_level_tu = cls.env["product.packaging.level"].create(
41-
{"name": "Transport Unit", "code": "TU", "sequence": 1}
42-
)
43-
cls.packaging_level_pl = cls.env["product.packaging.level"].create(
44-
{"name": "Pallet", "code": "PL", "sequence": 2}
45-
)
46-
cls.packaging_level_cannot_be_sold = cls.env["product.packaging.level"].create(
47-
{
48-
"name": "Can not be sold",
49-
"code": "CNBS",
50-
"sequence": 30,
51-
"can_be_sold": False,
52-
}
53-
)
54-
55-
@classmethod
56-
def setUpClassPackaging(cls):
57-
cls.packaging_tu = cls.env["product.packaging"].create(
58-
{
59-
"name": "PACKAGING TU",
60-
"product_id": cls.product.id,
61-
"packaging_level_id": cls.packaging_level_tu.id,
62-
"qty": TU_PRODUCT_QTY,
63-
}
64-
)
65-
cls.packaging_pl = cls.env["product.packaging"].create(
66-
{
67-
"name": "PACKAGING PL",
68-
"product_id": cls.product.id,
69-
"packaging_level_id": cls.packaging_level_pl.id,
70-
"qty": PL_PRODUCT_QTY,
71-
}
72-
)
73-
cls.packaging_cannot_be_sold = cls.env["product.packaging"].create(
74-
{
75-
"name": "Test packaging cannot be sold",
76-
"product_id": cls.product.id,
77-
"qty": 10.0,
78-
"packaging_level_id": cls.packaging_level_cannot_be_sold.id,
79-
}
80-
)
81-
cls.sellable_packagings = cls.packaging_tu | cls.packaging_pl
82-
83-
@classmethod
84-
def setUpClassSaleOrder(cls):
85-
cls.so_model = cls.env["sale.order"]
86-
sale_form = Form(cls.so_model)
87-
sale_form.partner_id = cls.partner
88-
with sale_form.order_line.new() as line:
89-
line.product_id = cls.product
90-
line.product_uom = cls.product.uom_id
91-
cls.order = sale_form.save()
92-
cls.order_line = cls.order.order_line

sell_only_by_packaging/tests/test_sale_line_onchanges.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
# Copyright 2020 Camptocamp SA
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
3+
import logging
34

4-
from odoo.tests.common import Form
5+
from odoo.tests import Form
56

6-
from .common import PL_PRODUCT_QTY, TU_PRODUCT_QTY, Common
7+
from odoo.addons.product_packaging_level_salable.tests.common import (
8+
PL_PRODUCT_QTY,
9+
TU_PRODUCT_QTY,
10+
)
711

12+
from .common import SellOnlyByPackagingCommon
813

9-
class TestPackaging(Common):
14+
15+
class TestPackaging(SellOnlyByPackagingCommon):
1016
def test_compute_qties(self):
11-
with Form(self.order) as so:
17+
with Form(self.order) as so, self.assertLogs(level=logging.WARNING) as logs:
1218
with so.order_line.edit(0) as line:
1319
line.product_packaging_id = self.packaging_tu
1420
line.product_packaging_qty = 31
21+
# catch WARNING by _onchange_product_packaging_id
22+
self.assertEqual(len(logs.records), 1)
23+
self.assertEqual(logs.records[0].levelno, logging.WARNING)
1524
# (20*30)+20 = 31*20 = 620
1625
expected_qty = TU_PRODUCT_QTY + PL_PRODUCT_QTY
1726
self.assertEqual(self.order_line.product_uom_qty, expected_qty)

0 commit comments

Comments
 (0)