1
# -*- encoding: latin-1 -*-
2
##############################################################################
4
# Copyright (c) 2009 �ngel �lvarez - NaN (http://www.nan-tic.com) All Rights Reserved.
7
# WARNING: This program as such is intended to be used by professional
8
# programmers who take the whole responsability of assessing all potential
9
# consequences resulting from its eventual inadequacies and bugs
10
# End users who are looking for a ready-to-use solution with commercial
11
# garantees and support are strongly adviced to contract a Free Software
14
# This program is Free Software; you can redistribute it and/or
15
# modify it under the terms of the GNU General Public License
16
# as published by the Free Software Foundation; either version 2
17
# of the License, or (at your option) any later version.
19
# This program is distributed in the hope that it will be useful,
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
# GNU General Public License for more details.
24
# You should have received a copy of the GNU General Public License
25
# along with this program; if not, write to the Free Software
26
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
##############################################################################
31
from osv import osv, fields
34
from tools import config
35
from tools.translate import _
37
class product_product(osv.osv):
38
_inherit = 'product.product'
39
_name = 'product.product'
41
def rounding(self,f, r):
44
return round(f / r) * r
46
def _search_values(self,cr,uid,product_id,bulk_id,context=None):
47
result = {'qty':None, 'uom':None }
48
bom_ids = self.pool.get('mrp.bom').search(cr,uid,[('product_id','=', product_id)],context=context)
49
for bom in self.pool.get('mrp.bom').browse(cr, uid, bom_ids, context=context):
51
for line in bom.bom_lines:
52
if line.product_id.id == bulk_id:
53
value += round(line.product_qty,5)
54
uom_id = line.product_uom.id
55
# break NOTE: I remove break because I found more than one bom with same components more than one time.
56
result['qty'] = round( value, 5 )
57
result['uom'] = uom_id
60
def _get_qty_available( self, cr, uid, ids, field_name, field_value, context=None):
62
for product in self.browse(cr, uid, ids, context):
63
#search stock of this product
64
if field_name == 'bulk_qty_available':
65
product_stock_qty = product.qty_available
67
product_stock_qty = product.virtual_available
73
for product_bulk in product.bulk_of_product_ids:
74
#search unit_convertion
77
#seach bom factor and uom_dest
78
res = self._search_values(cr,uid,product_bulk.id, product.id,context=context)
82
#search stock and uom of bulk
83
#for bulk_product in self.browse(cr, uid, [product_bulk.id], context=context):
84
if field_name == 'bulk_qty_available':
85
bulk_qty = product_bulk.qty_available
87
bulk_qty = product_bulk.virtual_available
88
uom_id = product.uom_id.id
90
#convert bulk stock to Udm of this product
91
amount = self.pool.get('product.uom')._compute_qty(cr, uid, uom_dest, factor, uom_id)
93
bulk_stock += amount * bulk_qty
96
result[product.id] = self.rounding(product_stock_qty + bulk_stock, product.uom_id.rounding)
100
def _bulk( self, cr, uid, ids, field_name, field_value, context=None):
102
for product in self.browse(cr, uid, ids, context):
104
if product.bulk_of_product_ids and len(product.bulk_of_product_ids) > 0:
105
result[product.id] = True
107
result[product.id] = False
109
for bulks in product.bulk_of_product_ids:
110
if product.bulk_of_product_ids and len(product.bulk_of_product_ids) > 0:
111
result[product.id] = True
113
result[product.id] = False
114
>>>>>>> 6dfe98a788cc2c7a754f46028a8cd135f6c63cfc
118
'bulk_id': fields.many2one('product.product', 'Bulk', select=1, help='Bulk related with this product'),
119
'bulk_of_product_ids': fields.one2many('product.product', 'bulk_id', 'Bulk Of', help='List of all products that have the current one as a bulk.'),
120
'bulk': fields.function(_bulk, method=True, type='boolean', string='Is Bulk?', help='A product is a bulk if there are products that have this as bulk.'),
121
'bulk_qty_available': fields.function(_get_qty_available, method=True, type='float', string='Bulk Stock'),
122
'bulk_virtual_available': fields.function(_get_qty_available, method=True, type='float', string='Virt. bulk stock'),
128
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: