[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.
This commit is contained in:
@@ -124,11 +124,11 @@ class StockRule(models.Model):
|
||||
manufacture_delay = product.produce_delay
|
||||
delay += manufacture_delay
|
||||
if not bypass_delay_description:
|
||||
delay_description += '<tr><td>%s</td><td class="text-right">+ %d %s</td></tr>' % (_('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 += '<tr><td>%s</td><td class="text-right">+ %d %s</td></tr>' % (_('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):
|
||||
|
||||
@@ -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 += '<tr><td>%s</td><td class="text-right">+ %d %s</td></tr>' % (_('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 += '<tr><td>%s</td><td class="text-right">+ %d %s</td></tr>' % (_('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 += '<tr><td>%s</td><td class="text-right">+ %d %s</td></tr>' % (_('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
|
||||
|
||||
@@ -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(['<tr><td>%s %s</td><td class="text-right">+ %d %s</td></tr>' % (_('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
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
The forecasted stock on the <b><t t-esc="lead_days_date"/></b>
|
||||
is <t t-if="qty_to_order <= 0"><b><t t-esc="qty_forecast"/> <t t-esc="product_uom_name"/></b></t><t t-else="">
|
||||
below the inventory <b>minimum of <t t-esc="product_min_qty"/> <t t-esc="product_uom_name"/>
|
||||
: <t t-esc="qty_to_order"/> <t t-esc="product_uom_name"/> should be replenished</b> to reach the maximum of
|
||||
: <t t-esc="qty_to_order"/> <t t-esc="product_uom_name"/> should be replenished</b> to reach the maximum of
|
||||
<t t-esc="product_max_qty"/> <t t-esc="product_uom_name"/>.</t>
|
||||
</p>
|
||||
<table t-if="lead_days_description" class="table table-borderless table-sm">
|
||||
@@ -17,16 +17,19 @@
|
||||
Today
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<t t-esc="today"/>
|
||||
<t t-out="today"/>
|
||||
</td>
|
||||
</tr>
|
||||
<t t-raw="lead_days_description"/>
|
||||
<tr t-foreach="lead_days_description" t-as="descr">
|
||||
<td><t t-out="descr[0]"/></td>
|
||||
<td class="text-right"><t t-out="descr[1]"/></td>
|
||||
</tr>
|
||||
<tr class="table-info">
|
||||
<td>
|
||||
Forecasted Date
|
||||
</td>
|
||||
<td class="text-right text-nowrap">
|
||||
= <t t-esc="lead_days_date"/>
|
||||
= <t t-out="lead_days_date"/>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user