# -*- coding: utf-8 -*- from openerp import tools, models, api from openerp.osv import osv, fields class product_stock_line(osv.osv): _name = "product.stock.line" _description = "product.stock.line" _auto = False _columns = { 'product_id': fields.many2one('product.product','product'), 'product_qty': fields.float(string='Cantidad', readonly=True), 'partner_id' : fields.many2one('res.partner',string='Partner'), } _order = 'id asc' def init(self, cr): tools.sql.drop_view_if_exists(cr, 'product_stock_line') cr.execute(""" CREATE OR REPLACE VIEW product_stock_line as ( SELECT row_number() over (ORDER BY po.partner_id)as id, pol.product_id as product_id, sum(pol.qty) as product_qty, po.partner_id as partner_id FROM pos_order_line pol inner join pos_order po on(po.id = pol.order_id) GROUP BY pol.product_id, po.partner_id) """)