diff --git a/addons/stock/wizard/stock_change_product_qty.py b/addons/stock/wizard/stock_change_product_qty.py
index 5b6a79ad694..c21d61b9a3b 100644
--- a/addons/stock/wizard/stock_change_product_qty.py
+++ b/addons/stock/wizard/stock_change_product_qty.py
@@ -1,17 +1,21 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
-from openerp.osv import fields, osv, orm
+from openerp.osv import fields, osv
import openerp.addons.decimal_precision as dp
from openerp.tools.translate import _
from openerp import tools
from openerp.exceptions import UserError, AccessError
+
class stock_change_product_qty(osv.osv_memory):
_name = "stock.change.product.qty"
_description = "Change Product Quantity"
+
_columns = {
- 'product_id' : fields.many2one('product.product', 'Product'),
+ 'product_id': fields.many2one('product.product', 'Product', required=True),
+ 'product_tmpl_id': fields.many2one('product.template', 'Template', required=True),
+ 'product_variant_count': fields.related('product_tmpl_id', 'product_variant_count', type='integer', string='Variant Number'),
'new_quantity': fields.float('New Quantity on Hand', digits_compute=dp.get_precision('Product Unit of Measure'), required=True, help='This quantity is expressed in the Default Unit of Measure of the product.'),
'lot_id': fields.many2one('stock.production.lot', 'Serial Number', domain="[('product_id','=',product_id)]"),
'location_id': fields.many2one('stock.location', 'Location', required=True, domain="[('usage', '=', 'internal')]"),
@@ -22,23 +26,12 @@ class stock_change_product_qty(osv.osv_memory):
}
def default_get(self, cr, uid, fields, context):
- """ To get default values for the object.
- @param self: The object pointer.
- @param cr: A database cursor
- @param uid: ID of the user currently logged in
- @param fields: List of fields for which we want default values
- @param context: A standard dictionary
- @return: A dictionary which of fields with values.
- """
-
res = super(stock_change_product_qty, self).default_get(cr, uid, fields, context=context)
if context.get('active_model') == 'product.template':
product_ids = self.pool.get('product.product').search(cr, uid, [('product_tmpl_id', '=', context.get('active_id'))], context=context)
- if len(product_ids) == 1:
+ if product_ids:
res['product_id'] = product_ids[0]
- else:
- raise UserError(_('Please use the Product Variant view to update the product quantity.'))
if 'location_id' in fields:
location_id = res.get('location_id', False)
@@ -55,15 +48,20 @@ class stock_change_product_qty(osv.osv_memory):
res['location_id'] = location_id
return res
+ def create(self, cr, uid, values, context=None):
+ if values.get('product_id'):
+ values.update(self.onchange_product_id(cr, uid, None, values['product_id'], context=context)['value'])
+ return super(stock_change_product_qty, self).create(cr, uid, values, context=context)
+
+ def onchange_product_id(self, cr, uid, ids, prod_id, context=None):
+ product = self.pool.get('product.product').browse(cr, uid, prod_id)
+ return {'value': {
+ 'product_tmpl_id': product.product_tmpl_id.id,
+ 'product_variant_count': product.product_tmpl_id.product_variant_count
+ }}
+
def change_product_qty(self, cr, uid, ids, context=None):
- """ Changes the Product Quantity by making a Physical Inventory.
- @param self: The object pointer.
- @param cr: A database cursor
- @param uid: ID of the user currently logged in
- @param ids: List of IDs selected
- @param context: A standard dictionary
- @return:
- """
+ """ Changes the Product Quantity by making a Physical Inventory. """
if context is None:
context = {}
diff --git a/addons/stock/wizard/stock_change_product_qty_view.xml b/addons/stock/wizard/stock_change_product_qty_view.xml
index 8dc5a1b3512..1e1a3a16721 100644
--- a/addons/stock/wizard/stock_change_product_qty_view.xml
+++ b/addons/stock/wizard/stock_change_product_qty_view.xml
@@ -7,7 +7,12 @@