X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=addons%2Fstock%2Fproduct.py;fp=addons%2Fstock%2Fproduct.py;h=23f4d3f42bdbf339c3c0dae80fb1a570508f2283;hb=c15f748be05b3709f5e16680569abdc2949468e2;hp=0dd44afdbda147ac0d6b3f1a5a80f9c59e2a2be7;hpb=1dbf153eb51303c4186ca5e2dacd729aadd95f28;p=odoo%2Fodoo.git diff --git a/addons/stock/product.py b/addons/stock/product.py index 0dd44af..23f4d3f 100644 --- a/addons/stock/product.py +++ b/addons/stock/product.py @@ -23,6 +23,7 @@ from openerp.osv import fields, osv from openerp.tools.translate import _ from openerp.tools.safe_eval import safe_eval as eval import openerp.addons.decimal_precision as dp +from openerp.tools.float_utils import float_round class product_product(osv.osv): _inherit = "product.product" @@ -114,8 +115,8 @@ class product_product(osv.osv): domain_products = [('product_id', 'in', ids)] domain_quant, domain_move_in, domain_move_out = self._get_domain_locations(cr, uid, ids, context=context) - domain_move_in += self._get_domain_dates(cr, uid, ids, context=context) + [('state', 'not in', ('done', 'cancel'))] + domain_products - domain_move_out += self._get_domain_dates(cr, uid, ids, context=context) + [('state', 'not in', ('done', 'cancel'))] + domain_products + domain_move_in += self._get_domain_dates(cr, uid, ids, context=context) + [('state', 'not in', ('done', 'cancel', 'draft'))] + domain_products + domain_move_out += self._get_domain_dates(cr, uid, ids, context=context) + [('state', 'not in', ('done', 'cancel', 'draft'))] + domain_products domain_quant += domain_products if context.get('lot_id') or context.get('owner_id') or context.get('package_id'): if context.get('lot_id'): @@ -136,14 +137,18 @@ class product_product(osv.osv): moves_in = dict(map(lambda x: (x['product_id'][0], x['product_qty']), moves_in)) moves_out = dict(map(lambda x: (x['product_id'][0], x['product_qty']), moves_out)) res = {} - for id in ids: + for product in self.browse(cr, uid, ids, context=context): + id = product.id + qty_available = float_round(quants.get(id, 0.0), precision_rounding=product.uom_id.rounding) + incoming_qty = float_round(moves_in.get(id, 0.0), precision_rounding=product.uom_id.rounding) + outgoing_qty = float_round(moves_out.get(id, 0.0), precision_rounding=product.uom_id.rounding) + virtual_available = float_round(quants.get(id, 0.0) + moves_in.get(id, 0.0) - moves_out.get(id, 0.0), precision_rounding=product.uom_id.rounding) res[id] = { - 'qty_available': quants.get(id, 0.0), - 'incoming_qty': moves_in.get(id, 0.0), - 'outgoing_qty': moves_out.get(id, 0.0), - 'virtual_available': quants.get(id, 0.0) + moves_in.get(id, 0.0) - moves_out.get(id, 0.0), + 'qty_available': qty_available, + 'incoming_qty': incoming_qty, + 'outgoing_qty': outgoing_qty, + 'virtual_available': virtual_available, } - return res def _search_product_quantity(self, cr, uid, obj, name, domain, context): @@ -177,7 +182,6 @@ class product_product(osv.osv): _columns = { 'reception_count': fields.function(_stock_move_count, string="Receipt", type='integer', multi='pickings'), 'delivery_count': fields.function(_stock_move_count, string="Delivery", type='integer', multi='pickings'), - 'qty_available_text': fields.function(_product_available_text, type='char'), 'qty_available': fields.function(_product_available, multi='qty_available', type='float', digits_compute=dp.get_precision('Product Unit of Measure'), string='Quantity On Hand', @@ -192,6 +196,7 @@ class product_product(osv.osv): "or any of its children.\n" "Otherwise, this includes goods stored in any Stock Location " "with 'internal' type."), + 'qty_available2': fields.related('qty_available', type="float", relation="product.product", string="On Hand"), 'virtual_available': fields.function(_product_available, multi='qty_available', type='float', digits_compute=dp.get_precision('Product Unit of Measure'), string='Forecast Quantity', @@ -234,11 +239,6 @@ class product_product(osv.osv): 'orderpoint_ids': fields.one2many('stock.warehouse.orderpoint', 'product_id', 'Minimum Stock Rules'), } - _defaults = { - # Dirty hack to avoid empty stat button in create view - 'qty_available_text': lambda *x: '0.0 On Hand', - } - def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): res = super(product_product,self).fields_view_get(cr, uid, view_id, view_type, context, toolbar=toolbar, submenu=submenu) if context is None: @@ -339,7 +339,7 @@ class product_template(osv.osv): _columns = { 'type': fields.selection([('product', 'Stockable Product'), ('consu', 'Consumable'), ('service', 'Service')], 'Product Type', required=True, help="Consumable: Will not imply stock management for this product. \nStockable product: Will imply stock management for this product."), - 'qty_available_text': fields.function(_product_available_text, type='char'), + 'qty_available2': fields.related('qty_available', type="float", relation="product.template", string="On Hand"), 'property_stock_procurement': fields.property( type='many2one', relation='stock.location', @@ -386,8 +386,6 @@ class product_template(osv.osv): _defaults = { 'sale_delay': 7, - # Dirty hack to avoid empty stat button in create view - 'qty_available_text': lambda *x: '0.0 On Hand', } def action_view_routes(self, cr, uid, ids, context=None):