# -*- coding: utf-8 -*- ############################################################################## # # Cybrosys Technologies Pvt. Ltd. # Copyright (C) 2009-TODAY Cybrosys Technologies(). # Author: Sreejith P() # you can modify it under the terms of the GNU LESSER # GENERAL PUBLIC LICENSE (LGPL v3), Version 3. # # It is forbidden to publish, distribute, sublicense, or sell copies # of the Software or modified copies of the Software. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. # # You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE # GENERAL PUBLIC LICENSE (LGPL v3) along with this program. # If not, see . # ############################################################################## from openerp import fields, models, api class ProductForm(models.Model): _inherit = 'product.template' internal_location = fields.One2many('stock.quantity', 'product_id', compute='get_product_qty') def get_product_qty(self): location_list = [] product_list = [] obj_location = self.env['stock.location'].search([('usage', '=', 'internal')]) for i in obj_location: location_list.append(i.id) obj_product = self.env['product.product'].search([('product_tmpl_id', '=', self.id)]) for i in obj_product: obj_quant = self.env['stock.quant'].search([('product_id', '=', i.id), ('location_id', 'in', location_list)]) for obj in obj_quant: print obj.location_id.id move_line = {'product_id': obj.product_id.id, 'stock_location': obj.location_id.id, 'qty_on_hand': obj.qty, } product_list.append(move_line) for i in product_list: self.internal_location |= self.env['stock.quantity'].create(i) class InternalLocation(models.Model): _name = 'stock.quantity' stock_location = fields.Many2one('stock.location', string='Location Name') qty_on_hand = fields.Float('On Hand') forecast = fields.Float('Forecast') incoming_qty = fields.Float('Incoming Quantity') outgoing_qty = fields.Float('Outgoing Quantity') product_id = fields.Many2one('product.template', string='Product')