Skip to content

Commit

Permalink
[MIG] sell_only_by_packaging: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
trisdoan committed Dec 31, 2024
1 parent 6fe203d commit 5d68fef
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 122 deletions.
4 changes: 3 additions & 1 deletion sell_only_by_packaging/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,13 @@ Contributors
- Hiep (Nguyen Hoang) <[email protected]>
- Phuc (Tran Thanh) <[email protected]>
- Duong (Tran Quoc) <[email protected]>
- Tris Doan <[email protected]>

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

The development of this module has been financially supported by:
The development and migration of this module has been financially
supported by:

- Camptocamp

Expand Down
6 changes: 3 additions & 3 deletions sell_only_by_packaging/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
{
"name": "Sell Only By Packaging",
"summary": "Manage sale of packaging",
"version": "16.0.1.1.0",
"version": "18.0.1.0.0",
"development_status": "Alpha",
"category": "Warehouse Management",
"category": "Sales",
"website": "https://github.com/OCA/sale-workflow",
"author": "Camptocamp, BCIM, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["product_packaging_level_salable", "sale_stock"],
"depends": ["product_packaging_level_salable"],
"data": [
"views/product_packaging.xml",
"views/product_template.xml",
Expand Down
11 changes: 6 additions & 5 deletions sell_only_by_packaging/models/product_packaging_level.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2020 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import _, api, exceptions, models
from odoo import api, exceptions, models


class ProductPackagingLevel(models.Model):
Expand All @@ -18,9 +18,10 @@ def _check_sell_only_by_packaging_can_be_sold_packaging_ids(self):
templates._check_sell_only_by_packaging_can_be_sold_packaging_ids()
except exceptions.ValidationError as e:
raise exceptions.ValidationError(
_(
'Packaging level "{}" must stay with "Can be sold",'
self.env._(
'Packaging level %s must stay with "Can be sold",'
' at least one product configured as "sell only'
' by packaging" is using it.'
).format(record.display_name)
' by packaging" is using it.',
record.display_name,
),
) from e
18 changes: 9 additions & 9 deletions sell_only_by_packaging/models/product_template.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2020 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)

from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.exceptions import ValidationError


Expand Down Expand Up @@ -41,11 +41,11 @@ def _check_sell_only_by_packaging_sale_ok(self):
for product in self:
if product.sell_only_by_packaging and not product.sale_ok:
raise ValidationError(
_(
self.env._(
"Product %s cannot be defined to be sold only by "
"packaging if it cannot be sold."
)
% product.name
"packaging if it cannot be sold.",
product.name,
),
)

@api.constrains("sell_only_by_packaging", "packaging_ids")
Expand All @@ -64,12 +64,12 @@ def _check_sell_only_by_packaging_can_be_sold_packaging_ids(self):
)
):
raise ValidationError(
_(
self.env._(
"Product %s cannot be defined to be sold only by "
"packaging if it does not have any packaging that "
"can be sold defined."
)
% product.name
"can be sold defined.",
product.name,
),
)

@api.depends("sale_ok")
Expand Down
14 changes: 5 additions & 9 deletions sell_only_by_packaging/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2020 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)

from odoo import _, api, models
from odoo import api, models
from odoo.exceptions import ValidationError
from odoo.tools import float_compare

Expand All @@ -27,18 +27,14 @@ def _check_product_packaging_sell_only_by_packaging(self):
!= 0
):
raise ValidationError(
_(
self.env._(
"Product %s can only be sold with a packaging and a "
"packaging quantity."
)
% line.product_id.name
"packaging quantity.",
line.product_id.name,
),
)

def _force_qty_with_package(self):
"""
:return:
"""
self.ensure_one()
qty = self.product_id._convert_packaging_qty(
self.product_uom_qty, self.product_uom, packaging=self.product_packaging_id
Expand Down
1 change: 1 addition & 0 deletions sell_only_by_packaging/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
- Hiep (Nguyen Hoang) \<<[email protected]>\>
- Phuc (Tran Thanh) \<<[email protected]>\>
- Duong (Tran Quoc) \<<[email protected]>\>
- Tris Doan \<<[email protected]>\>
2 changes: 1 addition & 1 deletion sell_only_by_packaging/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The development of this module has been financially supported by:
The development and migration of this module has been financially supported by:

- Camptocamp

Expand Down
4 changes: 3 additions & 1 deletion sell_only_by_packaging/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,13 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li>Hiep (Nguyen Hoang) &lt;<a class="reference external" href="mailto:hiepnh&#64;trobz.com">hiepnh&#64;trobz.com</a>&gt;</li>
<li>Phuc (Tran Thanh) &lt;<a class="reference external" href="mailto:phuc&#64;trobz.com">phuc&#64;trobz.com</a>&gt;</li>
<li>Duong (Tran Quoc) &lt;<a class="reference external" href="mailto:duongtq&#64;trobz.com">duongtq&#64;trobz.com</a>&gt;</li>
<li>Tris Doan &lt;<a class="reference external" href="mailto:tridm&#64;trobz.com">tridm&#64;trobz.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#toc-entry-6">Other credits</a></h2>
<p>The development of this module has been financially supported by:</p>
<p>The development and migration of this module has been financially
supported by:</p>
<ul class="simple">
<li>Camptocamp</li>
</ul>
Expand Down
84 changes: 3 additions & 81 deletions sell_only_by_packaging/tests/common.py
Original file line number Diff line number Diff line change
@@ -1,92 +1,14 @@
# Copyright 2020 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from odoo.tests.common import Form, TransactionCase
from odoo.addons.product_packaging_level_salable.tests.common import Common

TU_PRODUCT_QTY = 20
PL_PRODUCT_QTY = TU_PRODUCT_QTY * 30


class Common(TransactionCase):
at_install = False
post_install = True

class SellOnlyByPackagingCommon(Common):
@classmethod
def setUpClass(cls):
super(Common, cls).setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
super().setUpClass()
cls.env.user.groups_id += cls.env.ref("product.group_stock_packaging")
cls.setUpClassPartner()
cls.setUpClassProduct()
cls.setUpClassPackagingType()
cls.setUpClassPackaging()
cls.setUpClassSaleOrder()
cls.setUpClassConfig()

@classmethod
def setUpClassConfig(cls):
cls.precision = cls.env["decimal.precision"].precision_get("Product Price")

@classmethod
def setUpClassPartner(cls):
cls.partner = cls.env.ref("base.res_partner_12")

@classmethod
def setUpClassProduct(cls):
cls.product = cls.env.ref("product.product_product_9")

@classmethod
def setUpClassPackagingType(cls):
cls.packaging_level_tu = cls.env["product.packaging.level"].create(
{"name": "Transport Unit", "code": "TU", "sequence": 1}
)
cls.packaging_level_pl = cls.env["product.packaging.level"].create(
{"name": "Pallet", "code": "PL", "sequence": 2}
)
cls.packaging_level_cannot_be_sold = cls.env["product.packaging.level"].create(
{
"name": "Can not be sold",
"code": "CNBS",
"sequence": 30,
"can_be_sold": False,
}
)

@classmethod
def setUpClassPackaging(cls):
cls.packaging_tu = cls.env["product.packaging"].create(
{
"name": "PACKAGING TU",
"product_id": cls.product.id,
"packaging_level_id": cls.packaging_level_tu.id,
"qty": TU_PRODUCT_QTY,
}
)
cls.packaging_pl = cls.env["product.packaging"].create(
{
"name": "PACKAGING PL",
"product_id": cls.product.id,
"packaging_level_id": cls.packaging_level_pl.id,
"qty": PL_PRODUCT_QTY,
}
)
cls.packaging_cannot_be_sold = cls.env["product.packaging"].create(
{
"name": "Test packaging cannot be sold",
"product_id": cls.product.id,
"qty": 10.0,
"packaging_level_id": cls.packaging_level_cannot_be_sold.id,
}
)
cls.sellable_packagings = cls.packaging_tu | cls.packaging_pl

@classmethod
def setUpClassSaleOrder(cls):
cls.so_model = cls.env["sale.order"]
sale_form = Form(cls.so_model)
sale_form.partner_id = cls.partner
with sale_form.order_line.new() as line:
line.product_id = cls.product
line.product_uom = cls.product.uom_id
cls.order = sale_form.save()
cls.order_line = cls.order.order_line
17 changes: 13 additions & 4 deletions sell_only_by_packaging/tests/test_sale_line_onchanges.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
# Copyright 2020 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
import logging

from odoo.tests.common import Form
from odoo.tests import Form

from .common import PL_PRODUCT_QTY, TU_PRODUCT_QTY, Common
from odoo.addons.product_packaging_level_salable.tests.common import (
PL_PRODUCT_QTY,
TU_PRODUCT_QTY,
)

from .common import SellOnlyByPackagingCommon

class TestPackaging(Common):

class TestPackaging(SellOnlyByPackagingCommon):
def test_compute_qties(self):
with Form(self.order) as so:
with Form(self.order) as so, self.assertLogs(level=logging.WARNING) as logs:
with so.order_line.edit(0) as line:
line.product_packaging_id = self.packaging_tu
line.product_packaging_qty = 31
# catch WARNING by _onchange_product_packaging_id
self.assertEqual(len(logs.records), 1)
self.assertEqual(logs.records[0].levelno, logging.WARNING)
# (20*30)+20 = 31*20 = 620
expected_qty = TU_PRODUCT_QTY + PL_PRODUCT_QTY
self.assertEqual(self.order_line.product_uom_qty, expected_qty)
Expand Down
14 changes: 11 additions & 3 deletions sell_only_by_packaging/tests/test_sale_only_by_packaging.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Copyright 2020 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)

import logging

from odoo.exceptions import ValidationError
from odoo.tests import Form
from odoo.tools import mute_logger

from .common import Common
from .common import SellOnlyByPackagingCommon


class TestSaleProductByPackagingOnly(Common):
class TestSaleProductByPackagingOnly(SellOnlyByPackagingCommon):
def test_write_auto_fill_packaging(self):
order_line = self.order.order_line
self.assertFalse(order_line.product_packaging_id)
Expand Down Expand Up @@ -63,7 +65,10 @@ def test_convert_packaging_qty(self):
# Now force the qty on the packaging
packaging.force_sale_qty = True
with Form(self.order) as sale_order:
with sale_order.order_line.edit(0) as so_line:
with (
sale_order.order_line.edit(0) as so_line,
self.assertLogs(level=logging.WARNING) as logs,
):
so_line.product_packaging_id = packaging
so_line.product_uom_qty = 52
self.assertAlmostEqual(
Expand All @@ -89,6 +94,9 @@ def test_convert_packaging_qty(self):
self.assertAlmostEqual(
so_line.product_uom_qty, 220, places=self.precision
)
# catch WARNING by _onchange_product_packaging_id
self.assertEqual(len(logs.records), 1)
self.assertEqual(logs.records[0].levelno, logging.WARNING)

def test_onchange_qty_is_not_pack_multiple(self):
"""Check package when qantity is not a multiple of package quantity.
Expand Down
2 changes: 1 addition & 1 deletion sell_only_by_packaging/views/product_packaging.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="product_packaging_tree_view_inherit" model="ir.ui.view">
<field name="name">product.packaging.tree.view.inherit</field>
<field name="name">product.packaging.list.view.inherit</field>
<field name="model">product.packaging</field>
<field name="inherit_id" ref="product.product_packaging_tree_view" />
<field name="arch" type="xml">
Expand Down
4 changes: 2 additions & 2 deletions sell_only_by_packaging/views/product_product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="product_product_tree_view" model="ir.ui.view">
<field name="name">product.product.tree.inherit</field>
<field name="name">product.product.list.inherit</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_product_tree_view" />
<field name="arch" type="xml">
<field name="lst_price" position="after">
<field name="sell_only_by_packaging" invisible="1" />
<field
name="min_sellable_qty"
attrs="{'invisible':['|', ('type', '!=', 'product'), ('sell_only_by_packaging', '=', False)]}"
optional="show"
invisible="type != 'product' or not sell_only_by_packaging"
/>
</field>
</field>
Expand Down
4 changes: 2 additions & 2 deletions sell_only_by_packaging/views/product_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">
<div name="options" position="inside">
<div attrs="{'invisible': [('sale_ok', '=', False)]}">
<div invisible="not sale_ok">
<field name="sell_only_by_packaging" />
<label for="sell_only_by_packaging" />
</div>
Expand All @@ -18,7 +18,7 @@
</field>
</record>
<record id="product_template_tree_view" model="ir.ui.view">
<field name="name">product.template.tree.inherit</field>
<field name="name">product.template.list.inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_tree_view" />
<field name="arch" type="xml">
Expand Down

0 comments on commit 5d68fef

Please sign in to comment.