[FIX] mrp: hide smart buttons for kits

When a kit template has several variants, the on hand quantity can be
incorrect.

To reproduce the issue:
1. Create two products P_compo, P_kit:
    - P_kit:
        - Storable
        - Variants:
            - Color (White, Black)
    - P_compo:
        - Storable
2. Update the on hand quantity of P_compo: 10
3. Create two BoMs:
    - BoM01:
        - Product: P_kit
        - Variant: Black
        - Type: Kit
        - Components: 1 x P_compo
    - BoM02:
        - Product: P_kit
        - Variant: White
        - Type: Kit
        - Components: 2 x P_compo
4. Open the form view of the template P_kit

Error: it displays "15 units on hand", which is impossible (there are
only 10 P_compo available)

Since it is difficult to determine the expected value, a decision has
been made: hide these smart buttons if a template has more than one
variant and if at least one of the variants is a kit.

OPW-2645299
OPW-2678400
OPW-3076502

closes odoo/odoo#108284

X-original-commit: cf3b83d6a48c080d900d9cf343e4012be718c79d
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Adrien Widart <awt@odoo.com>
This commit is contained in:
Adrien Widart (awt)
2022-12-22 11:40:55 +01:00
parent 3b9406419a
commit 1f3cbfd7ca
2 changed files with 6 additions and 4 deletions
+1 -1
View File
@@ -53,7 +53,7 @@ class ProductTemplate(models.Model):
super()._compute_show_qty_status_button()
for template in self:
if template.is_kits:
template.show_on_hand_qty_status_button = True
template.show_on_hand_qty_status_button = template.product_variant_count <= 1
template.show_forecasted_qty_status_button = False
def _compute_used_in_bom_count(self):
+5 -3
View File
@@ -54,8 +54,9 @@
<field name="inherit_id" ref="product.product_template_tree_view"/>
<field name="arch" type="xml">
<field name="uom_id" position="before">
<field name="qty_available" attrs="{'invisible':[('type', '!=', 'product')]}" optional="show" decoration-danger="qty_available &lt; 0"/>
<field name="virtual_available" attrs="{'invisible':[('type', '!=', 'product')]}" optional="show" decoration-danger="virtual_available &lt; 0" decoration-bf="1"/>
<field name="show_on_hand_qty_status_button" invisible="1"/>
<field name="qty_available" attrs="{'invisible':[('show_on_hand_qty_status_button', '=', False)]}" optional="show" decoration-danger="qty_available &lt; 0"/>
<field name="virtual_available" attrs="{'invisible':[('show_on_hand_qty_status_button', '=', False)]}" optional="show" decoration-danger="virtual_available &lt; 0" decoration-bf="1"/>
</field>
<field name="default_code" position="after">
<field name="responsible_id" widget="many2one_avatar_user"/>
@@ -157,9 +158,10 @@
<field name="arch" type="xml">
<xpath expr="//kanban" position="inside">
<field name="type"/>
<field name="show_on_hand_qty_status_button"/>
</xpath>
<xpath expr="//div[@name='product_lst_price']" position="after">
<div t-if="record.type.raw_value == 'product'">On hand: <field name="qty_available"/> <field name="uom_id"/></div>
<div t-if="record.show_on_hand_qty_status_button.raw_value">On hand: <field name="qty_available"/> <field name="uom_id"/></div>
</xpath>
</field>
</record>