flectra/addons/sale/models/product_product.py
2018-01-16 02:34:37 -08:00

24 lines
757 B
Python

# -*- coding: utf-8 -*-
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
from flectra import api, fields, models
class ProductProduct(models.Model):
_inherit = 'product.product'
@api.multi
def _sales_count(self):
r = {}
domain = [
('state', 'in', ['sale', 'done']),
('product_id', 'in', self.ids),
]
for group in self.env['sale.report'].read_group(domain, ['product_id', 'product_uom_qty'], ['product_id']):
r[group['product_id'][0]] = group['product_uom_qty']
for product in self:
product.sales_count = r.get(product.id, 0)
return r
sales_count = fields.Integer(compute='_sales_count', string='# Sales')