2018-01-16 06:58:15 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-01-16 11:34:37 +01:00
|
|
|
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
|
2018-01-16 06:58:15 +01:00
|
|
|
|
2018-01-16 11:34:37 +01:00
|
|
|
from flectra import api, fields, models
|
2018-01-16 06:58:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ProductProduct(models.Model):
|
|
|
|
_inherit = 'product.product'
|
|
|
|
|
|
|
|
@api.multi
|
|
|
|
def _sales_count(self):
|
|
|
|
r = {}
|
2018-04-05 10:25:40 +02:00
|
|
|
if not self.user_has_groups('sales_team.group_sale_salesman'):
|
|
|
|
return r
|
2018-01-16 06:58:15 +01:00
|
|
|
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')
|