[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)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -539,7 +539,7 @@
|
||||
|
||||
<record model="ir.actions.act_window" id="action_purchase_line_product_tree">
|
||||
<field name="context">{}</field>
|
||||
<field name="domain">[('product_id','in',active_ids)]</field>
|
||||
<field name="domain">[('product_id.product_tmpl_id','in',active_ids), ('state', 'in', ['purchase', 'done'])]</field>
|
||||
<field name="name">Purchases</field>
|
||||
<field name="res_model">purchase.order.line</field>
|
||||
<field name="view_id" ref="purchase_order_line_tree"/>
|
||||
|
||||
Reference in New Issue
Block a user