Add stock_packaging_calculator_packaging_type

This commit is contained in:
Simone Orsi
2021-05-28 09:41:04 +02:00
committed by nguyen hoang hiep
parent 928f03b0a1
commit f2198af1e8
10 changed files with 124 additions and 0 deletions

View File

@@ -0,0 +1 @@
wait for the bot ;)

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -0,0 +1,16 @@
# Copyright 2021 Camptocamp SA
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl)
{
"name": "Stock packaging calculator packaging type",
"summary": "Glue module for packaging type",
"version": "13.0.1.0.0",
"development_status": "Alpha",
"category": "Warehouse Management",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "LGPL-3",
"application": False,
"installable": True,
"auto_install": True,
"depends": ["stock_packaging_calculator", "product_packaging_type"],
}

View File

@@ -0,0 +1,2 @@
from . import product
from . import product_qty_by_packaging_mixin

View File

@@ -0,0 +1,25 @@
# Copyright 2021 Camptocamp SA
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl)
from odoo import models
class Product(models.Model):
_inherit = "product.product"
def _packaging_name_getter(self, packaging):
return packaging.packaging_type_id.name
def _qty_by_packaging_as_str(self, packaging, qty):
# By default use packaging type code
qty_by_packaging_type_fname = self.env.context.get(
"qty_by_packaging_type_fname", "code"
)
compact_mode = self.env.context.get("qty_by_packaging_type_compact", True)
sep = "" if compact_mode else " "
# Override to use packaging type code
if packaging and packaging.packaging_type_id:
name = packaging.packaging_type_id[qty_by_packaging_type_fname]
return f"{qty}{sep}{name}"
else:
return super()._qty_by_packaging_as_str(packaging, qty)

View File

@@ -0,0 +1,23 @@
# Copyright 2021 Camptocamp SA
# @author: Simone Orsi <simone.orsi@camptocamp.com>
# @author: Sébastien Alix <sebastien.alix@camptocamp.com>
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl)
from odoo import api, models
class ProductQtyByPackagingMixin(models.AbstractModel):
"""Allow displaying product qty by packaging.
"""
_inherit = "product.qty_by_packaging.mixin"
# Amazing.. unlike `api.depends`, `depends_context` cannot use a lambda
# to delegate lookup. Hence we are forced to override and call super.
@api.depends_context(
"lang",
"qty_by_pkg_total_units",
"qty_by_packaging_type_fname",
"qty_by_packaging_type_compact",
)
def _compute_product_qty_by_packaging_display(self):
super()._compute_product_qty_by_packaging_display()

View File

@@ -0,0 +1 @@
* Simone Orsi <simone.orsi@camptocamp.com>

View File

@@ -0,0 +1,3 @@
Glue module for `stock_packaging_calculator` and `product_packaging_type`.
Mainly to use packaging type's code instead of packaging's name.

View File

@@ -0,0 +1 @@
from . import test_packaging_by_qty

View File

@@ -0,0 +1,51 @@
# Copyright 2021 Camptocamp SA
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl)
from odoo.addons.stock_packaging_calculator.tests.common import TestCommon
from odoo.addons.stock_packaging_calculator.tests.utils import make_pkg_values
class TestCalc(TestCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.type_retail_box = cls.env["product.packaging.type"].create(
{"name": "Retail Box", "code": "PACK", "sequence": 3}
)
cls.type_transport_box = cls.env["product.packaging.type"].create(
{"name": "Transport Box", "code": "CASE", "sequence": 4}
)
cls.type_pallet = cls.env["product.packaging.type"].create(
{"name": "Pallet", "code": "PALLET", "sequence": 5}
)
cls.pkg_box.packaging_type_id = cls.type_retail_box
cls.pkg_big_box.packaging_type_id = cls.type_transport_box
cls.pkg_pallet.packaging_type_id = cls.type_pallet
def test_calc_1(self):
expected = [
make_pkg_values(self.pkg_pallet, qty=1, name=self.type_pallet.name),
make_pkg_values(self.pkg_big_box, qty=3, name=self.type_transport_box.name),
make_pkg_values(self.pkg_box, qty=1, name=self.type_retail_box.name),
make_pkg_values(self.uom_unit, qty=5),
]
self.assertEqual(self.product_a.product_qty_by_packaging(2655), expected)
def test_calc_2(self):
expected = [
make_pkg_values(self.pkg_big_box, qty=1, name=self.type_transport_box.name),
make_pkg_values(self.pkg_box, qty=3, name=self.type_retail_box.name),
]
self.assertEqual(self.product_a.product_qty_by_packaging(350), expected)
def test_as_str(self):
self.assertEqual(self.product_a.product_qty_by_packaging_as_str(10), "")
self.assertEqual(self.product_a.product_qty_by_packaging_as_str(100), "2PACK")
self.assertEqual(
self.product_a.product_qty_by_packaging_as_str(250), "1CASE,\xa01PACK"
)
self.assertEqual(
self.product_a.with_context(
qty_by_packaging_type_fname="name", qty_by_packaging_type_compact=False,
).product_qty_by_packaging_as_str(250),
"1 Transport Box,\xa01 Retail Box",
)