[FIX] stock: fix inconsistency beteen product variant and product template

Before commit:
   The issue is that the product is not in the 'available' filter but its
   kanban tile says 'on hand' quantity is available. A different issue is a raise because of this commit:
   https://github.com/odoo/odoo/commit/b08e3d114aa4efe687b4d4cca3de462a3dbe6eea. in this
   commit set the "active_test=False" for product template that's why it fetches all active and inactive
   warehouses and it becomes true for product variant as we don't get
   active_test=False. so condition becomes true and it will fetch only active warehouse and related
   location and result is displayed the different on_hand qty on variant and template.

After commit:
   we prevent the archive location quantity on the product template and its related quants to
   make a consistency between product template and product variant.

closes odoo/odoo#74965

X-original-commit: 52a9d4f08f383acbdcd4b06b8bcb6ee7844243b1
Signed-off-by: William Henrotin <Whenrow@users.noreply.github.com>
This commit is contained in:
Ankita Raval
2021-08-11 12:12:08 +00:00
parent 80e1259fd9
commit ea6786dfcb
+3 -3
View File
@@ -684,7 +684,7 @@ class ProductTemplate(models.Model):
def _compute_quantities_dict(self):
variants_available = {
p['id']: p for p in self.with_context(active_test=False).product_variant_ids.read(['qty_available', 'virtual_available', 'incoming_qty', 'outgoing_qty'])
p['id']: p for p in self.product_variant_ids.read(['qty_available', 'virtual_available', 'incoming_qty', 'outgoing_qty'])
}
prod_available = {}
for template in self:
@@ -692,7 +692,7 @@ class ProductTemplate(models.Model):
virtual_available = 0
incoming_qty = 0
outgoing_qty = 0
for p in template.with_context(active_test=False).product_variant_ids:
for p in template.product_variant_ids:
qty_available += variants_available[p.id]["qty_available"]
virtual_available += variants_available[p.id]["virtual_available"]
incoming_qty += variants_available[p.id]["incoming_qty"]
@@ -842,7 +842,7 @@ class ProductTemplate(models.Model):
# Be aware that the exact same function exists in product.product
def action_open_quants(self):
return self.with_context(active_test=False).product_variant_ids.filtered(lambda p: p.active or p.qty_available != 0).action_open_quants()
return self.product_variant_ids.filtered(lambda p: p.active or p.qty_available != 0).action_open_quants()
def action_update_quantity_on_hand(self):
advanced_option_groups = [