24 lines
745 B
Python
24 lines
745 B
Python
|
# -*- coding: utf-8 -*-
|
||
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||
|
|
||
|
from odoo 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')
|