product_stock_line.py 1.0 KB

12345678910111213141516171819202122232425262728
  1. # -*- coding: utf-8 -*-
  2. from openerp import tools, models, api
  3. from openerp.osv import osv, fields
  4. class product_stock_line(osv.osv):
  5. _name = "product.stock.line"
  6. _description = "product.stock.line"
  7. _auto = False
  8. _columns = {
  9. 'product_id': fields.many2one('product.product','product'),
  10. 'product_qty': fields.float(string='Cantidad', readonly=True),
  11. 'partner_id' : fields.many2one('res.partner',string='Partner'),
  12. }
  13. _order = 'id asc'
  14. def init(self, cr):
  15. tools.sql.drop_view_if_exists(cr, 'product_stock_line')
  16. cr.execute("""
  17. CREATE OR REPLACE VIEW product_stock_line as (
  18. SELECT row_number() over (ORDER BY po.partner_id)as id,
  19. pol.product_id as product_id,
  20. sum(pol.qty) as product_qty,
  21. po.partner_id as partner_id
  22. FROM pos_order_line pol
  23. inner join pos_order po on(po.id = pol.order_id)
  24. GROUP BY pol.product_id, po.partner_id)
  25. """)