s_packaging_calculator: ease override of packaging name

This commit is contained in:
Simone Orsi
2021-05-28 09:03:14 +02:00
committed by nguyen hoang hiep
parent 4f156d449e
commit 7b7cacc7f6

View File

@@ -80,7 +80,9 @@ class Product(models.Model):
the display name of the packaging.
"""
custom_filter = self.env.context.get("_packaging_filter", lambda x: x)
name_getter = self.env.context.get("_packaging_name_getter", lambda x: x.name)
name_getter = self.env.context.get(
"_packaging_name_getter", self._packaging_name_getter
)
packagings = sorted(
[
Packaging(x.id, name_getter(x), x.qty, x.barcode, False)
@@ -100,6 +102,9 @@ class Product(models.Model):
)
return packagings
def _packaging_name_getter(self, packaging):
return packaging.name
def _product_qty_by_packaging(self, pkg_by_qty, qty, with_contained=False):
"""Produce a list of dictionaries of packaging info."""
# TODO: refactor to handle fractional quantities (eg: 0.5 Kg)