X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=addons%2Fstock%2Fproduct.py;h=41335b920840504bd8f96aaf5cac45e10dc184e2;hb=1d3f8eba879f02da7fc0bb46c9801029eccbc8c8;hp=8dbe4c77227e346d28de297b1024ba19fed9e7ef;hpb=591e329bb0efe4997677a0bee2e6f3b558e35df8;p=odoo%2Fodoo.git diff --git a/addons/stock/product.py b/addons/stock/product.py index 8dbe4c7..41335b9 100644 --- a/addons/stock/product.py +++ b/addons/stock/product.py @@ -177,7 +177,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 +191,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', @@ -334,7 +334,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', @@ -442,6 +442,13 @@ class product_template(osv.osv): result['context'] = "{'tree_view_ref':'stock.view_move_tree'}" return result + def write(self, cr, uid, ids, vals, context=None): + if 'uom_po_id' in vals: + product_ids = self.pool.get('product.product').search(cr, uid, [('product_tmpl_id', 'in', ids)], context=context) + if self.pool.get('stock.move').search(cr, uid, [('product_id', 'in', product_ids)], context=context, limit=1): + raise osv.except_osv(_('Error!'), _("You can not change the unit of measure of a product that has already been used in a stock move. If you need to change the unit of measure, you may deactivate this product.") % ()) + return super(product_template, self).write(cr, uid, ids, vals, context=context) + class product_removal_strategy(osv.osv): _name = 'product.removal'