From 1165291ed5439003b3f9130e40c844a39749aec0 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Thu, 10 Mar 2016 16:51:22 +0100 Subject: [PATCH] [FIX] purchase: Traceback and bad counter computation On the product_template, the stat button to indicate the purchased quatity is buggy in several ways. 1/ The states in the read_group domain have been mistaken with the states on the picking (clap, clap) 2/ The read_group is seeking the fields product_id and quantity. Too bad, on the model the name is unit_quantity (clap, clap) 3/ The displayed PO lines weren't chosen from a domain. So the computed quantity didn't correspond to the displayed lines from the button (small clap, clap) 4/ The action_purchase_line_product_tree linked to the stat button is selecting the PO lines where the product is the product id. Too bad, on the PO line this is a product.product and on the current object this is a product.template (epic clap, clap) --- addons/purchase/purchase.py | 6 +++--- addons/purchase/purchase_view.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index f71e787c739..ef4c8533485 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -971,12 +971,12 @@ class ProductProduct(models.Model): @api.multi def _purchase_count(self): domain = [ - ('state', 'in', ['confirmed', 'approved', 'done']), + ('state', 'in', ['purchase', 'done']), ('product_id', 'in', self.mapped('id')), ] r = {} - for group in self.env['purchase.report'].read_group(domain, ['product_id', 'quantity'], ['product_id']): - r[group['product_id'][0]] = group['quantity'] + for group in self.env['purchase.report'].read_group(domain, ['product_id', 'unit_quantity'], ['product_id']): + r[group['product_id'][0]] = group['unit_quantity'] for product in self: product.purchase_count = r.get(product.id, 0) return True diff --git a/addons/purchase/purchase_view.xml b/addons/purchase/purchase_view.xml index a78c0298db7..55996435132 100644 --- a/addons/purchase/purchase_view.xml +++ b/addons/purchase/purchase_view.xml @@ -539,7 +539,7 @@ {} - [('product_id','in',active_ids)] + [('product_id.product_tmpl_id','in',active_ids), ('state', 'in', ['purchase', 'done'])] Purchases purchase.order.line