From e3d7ff9c69c3419405a6d057b8a19e6fe099ff3b Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Tue, 7 Jan 2014 12:04:09 +0100 Subject: [PATCH] [REV] stock: added back the wizard to change the quantity removed in previous commit: it's not deprecated at all as it applies on product, not stock moves\! bzr revid: qdp-launchpad@openerp.com-20140107110409-hclpl2552l65bs3i --- addons/stock/__openerp__.py | 1 + addons/stock/wizard/__init__.py | 1 + .../stock/wizard/stock_change_product_qty.py | 109 ++++++++++++++++++ .../wizard/stock_change_product_qty_view.xml | 36 ++++++ 4 files changed, 147 insertions(+) create mode 100644 addons/stock/wizard/stock_change_product_qty.py create mode 100644 addons/stock/wizard/stock_change_product_qty_view.xml diff --git a/addons/stock/__openerp__.py b/addons/stock/__openerp__.py index 140d1c48ecf..9e286faf81c 100644 --- a/addons/stock/__openerp__.py +++ b/addons/stock/__openerp__.py @@ -73,6 +73,7 @@ Dashboard / Reports for Warehouse Management will include: 'stock_data.xml', 'stock_data.yml', 'wizard/stock_move_view.xml', + 'wizard/stock_change_product_qty_view.xml', 'wizard/stock_inventory_merge_view.xml', 'wizard/stock_location_product_view.xml', 'wizard/stock_inventory_line_split_view.xml', diff --git a/addons/stock/wizard/__init__.py b/addons/stock/wizard/__init__.py index eace40b8327..a29f3207ca1 100644 --- a/addons/stock/wizard/__init__.py +++ b/addons/stock/wizard/__init__.py @@ -24,6 +24,7 @@ import stock_inventory_merge import stock_inventory_line_split import stock_location_product import stock_return_picking +import stock_change_product_qty import make_procurement_product import mrp_procurement import orderpoint_procurement diff --git a/addons/stock/wizard/stock_change_product_qty.py b/addons/stock/wizard/stock_change_product_qty.py new file mode 100644 index 00000000000..3b40557884a --- /dev/null +++ b/addons/stock/wizard/stock_change_product_qty.py @@ -0,0 +1,109 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# 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 . +# +############################################################################## + +from openerp.osv import fields, osv, orm +import openerp.addons.decimal_precision as dp +from openerp.tools.translate import _ +from openerp import tools + +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'), + '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')]"), + } + + def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): + if context is None: context = {} + fvg = super(stock_change_product_qty, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu) + product_id = context and context.get('active_id', False) or False + + if view_type == 'form' and (context.get('active_model') == 'product.product') and product_id: + prod_obj = self.pool.get('product.product').browse(cr, uid, product_id, context=context) + fvg['fields']['lot_id']['required'] = prod_obj.track_production + + return fvg + + 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. + """ + product_id = context and context.get('active_id', False) or False + res = super(stock_change_product_qty, self).default_get(cr, uid, fields, context=context) + + if 'new_quantity' in fields: + res.update({'new_quantity': 1}) + if 'product_id' in fields: + res.update({'product_id': product_id}) + if 'location_id' in fields: + try: + model, location_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock', 'stock_location_stock') + self.pool.get('stock.location').check_access_rule(cr, uid, [location_id], 'read', context=context) + except (orm.except_orm, ValueError): + location_id = False + res.update({'location_id': location_id}) + return res + + 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: + """ + if context is None: + context = {} + + rec_id = context and context.get('active_id', False) + assert rec_id, _('Active ID is not set in Context') + + inventry_obj = self.pool.get('stock.inventory') + inventry_line_obj = self.pool.get('stock.inventory.line') + prod_obj_pool = self.pool.get('product.product') + + res_original = prod_obj_pool.browse(cr, uid, rec_id, context=context) + for data in self.browse(cr, uid, ids, context=context): + if data.new_quantity < 0: + raise osv.except_osv(_('Warning!'), _('Quantity cannot be negative.')) + inventory_id = inventry_obj.create(cr , uid, {'name': _('INV: %s') % tools.ustr(res_original.name)}, context=context) + line_data ={ + 'inventory_id' : inventory_id, + 'product_qty' : data.new_quantity, + 'location_id' : data.location_id.id, + 'product_id' : rec_id, + 'product_uom_id' : res_original.uom_id.id, + 'prod_lot_id' : data.lot_id.id + } + inventry_line_obj.create(cr , uid, line_data, context=context) + inventry_obj.action_done(cr, uid, [inventory_id], context=context) + return {} + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/stock/wizard/stock_change_product_qty_view.xml b/addons/stock/wizard/stock_change_product_qty_view.xml new file mode 100644 index 00000000000..18c548b2c65 --- /dev/null +++ b/addons/stock/wizard/stock_change_product_qty_view.xml @@ -0,0 +1,36 @@ + + + + + Change Product Quantity + stock.change.product.qty + +
+ + + + + + +
+
+
+
+
+ + + Update Product Quantity + ir.actions.act_window + stock.change.product.qty + form + form + + new + + +
+
+