From 5ff6faa67f95357e5818eb87965b24fb0fdf2d4f Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 20 May 2021 11:37:34 +0000 Subject: [PATCH] [FIX] mrp, stock, purchase_stock: d-t-raw-ify leadDaysPopOver And convert the `t-esc` in the template to `t-out` while at it. So this was a bit of a bummer initially, the PopoverWidgetField gets a pile of JSON as its value (so from the server), and that pile contains a template name (optionally) and... the template context, basically. For leadDaysPopOver the issue was some of that context is supposed to be rendered HTML to straight inject into the template, marking that as HTML-safe would be a bit of an issue (having the JSON specify which parts of the value it returns are HTML-safe being a bit of a conflict of interest). However turns out the thing is way over-complicated and over-engineered: `lead_days_description` necessarily has a very regular structure owing to being injected as a set of table rows, so the various overrides to `_get_lead_days` just make their own lives complicated by formatting the values they want to return into table rows matching the format of an unrelated template. Instead we can change the signature of `_get_lead_days` so the "description" is a list of values to inject in the table (list of pairs, each pair matching the corresponding columns of the table). The template can then take care of formatting those values into table rows the usual way, removing the need for any injection of raw content. This also makes for better / clearer translation strings. --- addons/mrp/models/stock_rule.py | 4 ++-- addons/purchase_stock/models/stock_rule.py | 6 +++--- addons/stock/models/stock_rule.py | 10 +++++++--- addons/stock/static/src/xml/stock_orderpoint.xml | 11 +++++++---- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/addons/mrp/models/stock_rule.py b/addons/mrp/models/stock_rule.py index 7ca58c1363a..fc2bb6125ae 100644 --- a/addons/mrp/models/stock_rule.py +++ b/addons/mrp/models/stock_rule.py @@ -124,11 +124,11 @@ class StockRule(models.Model): manufacture_delay = product.produce_delay delay += manufacture_delay if not bypass_delay_description: - delay_description += '%s+ %d %s' % (_('Manufacturing Lead Time'), manufacture_delay, _('day(s)')) + delay_description.append((_('Manufacturing Lead Time'), _('+ %d day(s)', manufacture_delay))) security_delay = manufacture_rule.picking_type_id.company_id.manufacturing_lead delay += security_delay if not bypass_delay_description: - delay_description += '%s+ %d %s' % (_('Manufacture Security Lead Time'), security_delay, _('day(s)')) + delay_description.append((_('Manufacture Security Lead Time'), _('+ %d day(s)', security_delay))) return delay, delay_description def _push_prepare_move_copy_values(self, move_to_copy, new_date): diff --git a/addons/purchase_stock/models/stock_rule.py b/addons/purchase_stock/models/stock_rule.py index cfa3ea3489e..b9c5fbd7cdf 100644 --- a/addons/purchase_stock/models/stock_rule.py +++ b/addons/purchase_stock/models/stock_rule.py @@ -156,13 +156,13 @@ class StockRule(models.Model): buy_rule.ensure_one() supplier_delay = seller[0].delay if supplier_delay and not bypass_delay_description: - delay_description += '%s+ %d %s' % (_('Vendor Lead Time'), supplier_delay, _('day(s)')) + delay_description.append((_('Vendor Lead Time'), _('+ %d day(s)', supplier_delay))) security_delay = buy_rule.picking_type_id.company_id.po_lead if not bypass_delay_description: - delay_description += '%s+ %d %s' % (_('Purchase Security Lead Time'), security_delay, _('day(s)')) + delay_description.append((_('Purchase Security Lead Time'), _('+ %d day(s)', security_delay))) days_to_purchase = buy_rule.company_id.days_to_purchase if not bypass_delay_description: - delay_description += '%s+ %d %s' % (_('Days to Purchase'), days_to_purchase, _('day(s)')) + delay_description.append((_('Days to Purchase'), _('+ %d day(s)', days_to_purchase))) return delay + supplier_delay + security_delay + days_to_purchase, delay_description @api.model diff --git a/addons/stock/models/stock_rule.py b/addons/stock/models/stock_rule.py index b5ac9cdfd01..79d718d6e8f 100644 --- a/addons/stock/models/stock_rule.py +++ b/addons/stock/models/stock_rule.py @@ -327,13 +327,17 @@ class StockRule(models.Model): :param product: the product of the procurement :type product: :class:`~odoo.addons.product.models.product.ProductProduct` :return: the cumulative delay and cumulative delay's description - :rtype: tuple + :rtype: tuple[int, list[str, str]] """ delay = sum(self.filtered(lambda r: r.action in ['pull', 'pull_push']).mapped('delay')) if self.env.context.get('bypass_delay_description'): - delay_description = "" + delay_description = [] else: - delay_description = ''.join(['%s %s+ %d %s' % (_('Delay on'), html_escape(rule.name), rule.delay, _('day(s)')) for rule in self if rule.action in ['pull', 'pull_push'] and rule.delay]) + delay_description = [ + (_('Delay on %s', rule.name), _('+ %d day(s)', rule.delay)) + for rule in self + if rule.action in ['pull', 'pull_push'] and rule.delay + ] return delay, delay_description diff --git a/addons/stock/static/src/xml/stock_orderpoint.xml b/addons/stock/static/src/xml/stock_orderpoint.xml index afd744c5a04..6c1b9f60b65 100644 --- a/addons/stock/static/src/xml/stock_orderpoint.xml +++ b/addons/stock/static/src/xml/stock_orderpoint.xml @@ -7,7 +7,7 @@ The forecasted stock on the is below the inventory minimum of - : should be replenished to reach the maximum of + : should be replenished to reach the maximum of .

@@ -17,16 +17,19 @@ Today - + + + +
- +
Forecasted Date - = + =