From 38baba3a6e3f38e8e54f28b7838efced5c025605 Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Fri, 28 May 2021 09:03:14 +0200 Subject: [PATCH] s_packaging_calculator: ease override of packaging name --- stock_packaging_calculator/models/product.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stock_packaging_calculator/models/product.py b/stock_packaging_calculator/models/product.py index 13ae10f3d..cdf83edf9 100644 --- a/stock_packaging_calculator/models/product.py +++ b/stock_packaging_calculator/models/product.py @@ -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)