Merge branch 'master' of https://github.com/odoo/odoo
[odoo/odoo.git] / addons / product_extended / wizard / wizard_price.py
index ddbeff9..688baff 100644 (file)
@@ -21,8 +21,9 @@
 #
 ##############################################################################
 
+from openerp.exceptions import except_orm
 from openerp.osv import fields, osv
-
+from openerp.tools.translate import _
 
 class wizard_price(osv.osv):
     _name = "wizard.price"
@@ -35,24 +36,27 @@ class wizard_price(osv.osv):
 
     def default_get(self, cr, uid, fields, context=None):
         res = super(wizard_price, self).default_get(cr, uid, fields, context=context)
-        product_pool = self.pool.get('product.product')
+        product_pool = self.pool.get('product.template')
         product_obj = product_pool.browse(cr, uid, context.get('active_id', False))
         if context is None:
             context = {}
         rec_id = context and context.get('active_id', False)
         assert rec_id, _('Active ID is not set in Context.')
-        res['info_field'] = str(product_pool.compute_price(cr, uid, [product_obj.id], test=True, context=context))
+        res['info_field'] = str(product_pool.compute_price(cr, uid, [], template_ids=[product_obj.id], test=True, context=context))
         return res
 
     def compute_from_bom(self, cr, uid, ids, context=None):
         assert len(ids) == 1
         if context is None:
             context = {}
+        model = context.get('active_model')
+        if model != 'product.template':
+            raise except_orm(_('Wrong model!'), _('This wizard is build for product templates, while you are currently running it from a product variant.'))
         rec_id = context and context.get('active_id', False)
         assert rec_id, _('Active ID is not set in Context.')
-        prod_obj = self.pool.get('product.product')
+        prod_obj = self.pool.get('product.template')
         res = self.browse(cr, uid, ids, context=context)
         prod = prod_obj.browse(cr, uid, rec_id, context=context)
-        prod_obj.compute_price(cr, uid, [prod.id], real_time_accounting=res[0].real_time_accounting, recursive=res[0].recursive, test=False, context=context)
+        prod_obj.compute_price(cr, uid, [], template_ids=[prod.id], real_time_accounting=res[0].real_time_accounting, recursive=res[0].recursive, test=False, context=context)
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: