[FIX] some product_qty fields are set with hardcoded decimal precision, and some...
[odoo/odoo.git] / addons / mrp_subproduct / mrp_subproduct.py
index 5519bba..3c4bb93 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 ##############################################################################
-#    
+#
 #    OpenERP, Open Source Management Solution
 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
 #
 #    GNU Affero General Public License for more details.
 #
 #    You should have received a copy of the GNU Affero General Public License
-#    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
 
 from osv import fields
 from osv import osv
+import decimal_precision as dp
 
 class mrp_subproduct(osv.osv):
     _name = 'mrp.subproduct'
     _description = 'Sub Product'
     _columns={
         'product_id': fields.many2one('product.product', 'Product', required=True),
-        'product_qty': fields.float('Product Qty', required=True),
+        'product_qty': fields.float('Product Qty', digits_compute=dp.get_precision('Product UoM'), required=True),
         'product_uom': fields.many2one('product.uom', 'Product UOM', required=True),
         'subproduct_type': fields.selection([('fixed','Fixed'),('variable','Variable')], 'Quantity Type', required=True),
         'bom_id': fields.many2one('mrp.bom', 'BoM'),
@@ -35,14 +36,14 @@ class mrp_subproduct(osv.osv):
     _defaults={
         'subproduct_type': lambda *args: 'fixed'
     }
-    
-    def onchange_product_id(self, cr, uid, ids, product_id,context={}):
+
+    def onchange_product_id(self, cr, uid, ids, product_id, context=None):
         """ Changes UoM if product_id changes.
         @param product_id: Changed product_id
         @return: Dictionary of changed values
         """
         if product_id:
-            prod = self.pool.get('product.product').browse(cr, uid, product_id)
+            prod = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
             v = {'product_uom': prod.uom_id.id}
             return {'value': v}
         return {}
@@ -53,16 +54,15 @@ class mrp_bom(osv.osv):
     _name = 'mrp.bom'
     _description = 'Bill of Material'
     _inherit='mrp.bom'
-    
+
     _columns={
         'sub_products':fields.one2many('mrp.subproduct', 'bom_id', 'sub_products'),
     }
 mrp_bom()
 
 class mrp_production(osv.osv):
-    _name = 'mrp.production'
     _description = 'Production'
-    _inherit= 'mrp.production'   
+    _inherit= 'mrp.production'
 
     def action_confirm(self, cr, uid, ids):
         """ Confirms production order and calculates quantity based on subproduct_type.
@@ -95,7 +95,7 @@ class mrp_production(osv.osv):
                     'state': 'waiting',
                     'production_id': production.id
                 }
-                sub_prod_ids = self.pool.get('stock.move').create(cr, uid, data)
+                self.pool.get('stock.move').create(cr, uid, data)
         return picking_id
 
 mrp_production()