sale.py 1.1 KB

12345678910111213141516171819
  1. # -*- coding: utf-8 -*-
  2. from openerp import fields, models, api
  3. class SaleOrder(models.Model):
  4. _inherit = "sale.order"
  5. @api.model
  6. def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None):
  7. if ['id', '!=', False] in domain:
  8. top_most = self.env['ir.config_parameter'].sudo().get_param('top.most.trending.product')
  9. self.env.cr.execute('select product_id, count(product_id) as cnt from sale_order_line group by product_id order by cnt desc limit %s' % (top_most))
  10. so_list = []
  11. for rec in self.env.cr.fetchall():
  12. sol_ids = self.env['sale.order.line'].search([('product_id', '=', rec[0]), ('order_id.state', 'not in', ['draft', 'sent', 'cancel'])])
  13. so_list.extend(list(set([x.order_id.id for x in sol_ids])))
  14. domain.extend([['id', 'in', so_list]])
  15. domain.extend([['company_id', '=', self.env.user.company_id.id]])
  16. return super(SaleOrder, self).search_read(domain=domain, fields=fields, offset=offset, limit=limit, order=order)