[FIX] purchase, sale: button "Sales" and "Purchases"
The number inside the button "Sales" is the quantity sold and the number inside the button "Purchases" is the quantity bought.
This commit is contained in:
@@ -1649,11 +1649,14 @@ class product_product(osv.Model):
|
||||
_inherit = 'product.product'
|
||||
|
||||
def _purchase_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
Purchase = self.pool['purchase.order.line']
|
||||
return {
|
||||
product_id: Purchase.search_count(cr,uid, [('product_id', '=', product_id)], context=context)
|
||||
for product_id in ids
|
||||
}
|
||||
r = dict.fromkeys(ids, 0)
|
||||
domain = [
|
||||
('state', 'in', ['confirmed', 'approved', 'except_picking', 'except_invoice', 'done']),
|
||||
('product_id', 'in', ids),
|
||||
]
|
||||
for group in self.pool['purchase.report'].read_group(cr, uid, domain, ['product_id', 'quantity'], ['product_id'], context=context):
|
||||
r[group['product_id'][0]] = group['quantity']
|
||||
return r
|
||||
|
||||
def action_view_purchases(self, cr, uid, ids, context=None):
|
||||
if isinstance(ids, (int, long)):
|
||||
|
||||
+8
-5
@@ -1169,11 +1169,14 @@ class product_product(osv.Model):
|
||||
_inherit = 'product.product'
|
||||
|
||||
def _sales_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
sale = self.pool['sale.order.line']
|
||||
return {
|
||||
product_id: sale.search_count(cr, uid, [('product_id', '=', product_id), ('state', 'in', ['waiting_date', 'progress', 'manual', 'shipping_except', 'invoice_except', 'confirmed', 'done'])], context=context)
|
||||
for product_id in ids
|
||||
}
|
||||
r = dict.fromkeys(ids, 0)
|
||||
domain = [
|
||||
('state', 'in', ['waiting_date', 'progress', 'manual', 'shipping_except', 'invoice_except', 'done']),
|
||||
('product_id', 'in', ids),
|
||||
]
|
||||
for group in self.pool['sale.report'].read_group(cr, uid, domain, ['product_id', 'product_uom_qty'], ['product_id'], context=context):
|
||||
r[group['product_id'][0]] = group['product_uom_qty']
|
||||
return r
|
||||
|
||||
def action_view_sales(self, cr, uid, ids, context=None):
|
||||
result = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'sale.action_order_line_product_tree', raise_if_not_found=True)
|
||||
|
||||
Reference in New Issue
Block a user