From d108a970e69022e1673a3c108d7b6421dd965fc5 Mon Sep 17 00:00:00 2001
From: "ron@tinyerp.com" <>
Date: Fri, 3 Dec 2010 18:36:21 +0530
Subject: [PATCH] [ADD]wizard to change Product Quantity from Product form View
bzr revid: ron@tinyerp.com-20101203130621-ddfrcf36mls4p7q5
---
addons/stock/__openerp__.py | 5 +-
addons/stock/product_view.xml | 5 +-
addons/stock/stock.py | 1 -
addons/stock/wizard/__init__.py | 2 +-
.../stock/wizard/stock_change_product_qty.py | 106 ++++++++++++++++++
.../wizard/stock_change_product_qty_view.xml | 37 ++++++
6 files changed, 151 insertions(+), 5 deletions(-)
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 0b85511050d..987a0e12493 100644
--- a/addons/stock/__openerp__.py
+++ b/addons/stock/__openerp__.py
@@ -45,10 +45,11 @@ Thanks to the double entry management, the inventory controlling is powerful and
"init_xml" : [],
"demo_xml" : ["stock_demo.xml"],
"update_xml" : [
- "security/stock_security.xml",
- "security/ir.model.access.csv",
+ "security/stock_security.xml",
+ "security/ir.model.access.csv",
"stock_data.xml",
"wizard/stock_move_view.xml",
+ "wizard/stock_change_product_qty_view.xml",
"wizard/stock_partial_picking_view.xml",
"wizard/stock_partial_move_view.xml",
"wizard/stock_fill_inventory_view.xml",
diff --git a/addons/stock/product_view.xml b/addons/stock/product_view.xml
index 35715a9e1fb..04344e18c16 100644
--- a/addons/stock/product_view.xml
+++ b/addons/stock/product_view.xml
@@ -102,9 +102,12 @@
-
+
+
+
diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index 39380f282a5..f7a8ca3830c 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -2431,7 +2431,6 @@ class stock_inventory(osv.osv):
"""
if context is None:
context = {}
-
# to perform the correct inventory corrections we need analyze stock location by
# location, never recursively, so we use a special context
product_context = dict(context, compute_child=False)
diff --git a/addons/stock/wizard/__init__.py b/addons/stock/wizard/__init__.py
index 5e35e0e7297..b903f020f82 100644
--- a/addons/stock/wizard/__init__.py
+++ b/addons/stock/wizard/__init__.py
@@ -33,6 +33,6 @@ import stock_invoice_onshipping
import stock_location_product
import stock_change_standard_price
import stock_return_picking
-
+import stock_change_product_qty
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
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..efceb833644
--- /dev/null
+++ b/addons/stock/wizard/stock_change_product_qty.py
@@ -0,0 +1,106 @@
+# -*- 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 osv import fields, osv
+from tools.translate import _
+import decimal_precision as dp
+from datetime import datetime
+from dateutil.relativedelta import relativedelta
+import time
+
+class stock_change_product_qty(osv.osv_memory):
+ _name = "stock.change.product.qty"
+ _description = "Change Product Quantity"
+ _columns = {
+ 'new_quantity': fields.float('Quantity', required=True),
+ 'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse', required=True, ondelete="cascade"),
+ 'location_id': fields.many2one('stock.location', 'Location', required=True, ondelete="cascade"),
+ }
+
+ _defaults = {
+ 'warehouse_id': 1 or False,
+ }
+
+
+ def onchange_warehouse_id(self, cr, uid, ids, warehouse_id, context={}):
+ """ Finds location id for changed warehouse.
+ @param warehouse_id: Changed id of warehouse.
+ @return: Dictionary of values.
+ """
+ if warehouse_id:
+ w = self.pool.get('stock.warehouse').browse(cr, uid, warehouse_id, context)
+ v = {'location_id': w.lot_stock_id.id}
+ return {'value': v}
+ return {}
+
+ 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_pool = self.pool.get('product.product')
+ product_obj = product_pool.browse(cr, uid, context.get('active_id', False))
+ res = super(stock_change_product_qty, self).default_get(cr, uid, fields, context=context)
+
+ if 'new_quantity' in fields:
+ res.update({'new_quantity': product_obj.qty_available})
+ return res
+
+ def change_product_qty(self, cr, uid, ids, context):
+ """ Changes the Standard Price of Product.
+ And creates an account move accordingly.
+ @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:
+ """
+ move_ids = []
+ rec_id = context and context.get('active_id', False)
+ assert rec_id, _('Active ID is not set in Context')
+
+ inventry_obj_pool = self.pool.get('stock.inventory')
+ prod_obj_pool = self.pool.get('product.product')
+ move_obj_pool = self.pool.get('stock.move')
+
+ res_original = prod_obj_pool.browse(cr, uid, rec_id)
+ res_update = self.browse(cr, uid, ids)
+
+ move_data ={
+ 'product_qty' : res_update[0].new_quantity,
+ 'location_id' : res_update[0].location_id.id,
+ 'product_id' : rec_id,
+ }
+ datas = {
+ 'name': 'INV:' + str(res_original.name),
+ 'company_id' : 1 or False ,
+ 'date': time.strftime('%Y-%m-%d %H:%M:%S'),
+ 'move_ids': [(6, 0, move_data)]
+ }
+
+# inventry_obj_pool.create(cr , uid, datas, context = context)
+ return {}
+stock_change_product_qty()
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..9c88f1c51eb
--- /dev/null
+++ b/addons/stock/wizard/stock_change_product_qty_view.xml
@@ -0,0 +1,37 @@
+
+
+
+
+ Change Product Quantity
+ stock.change.product.qty
+ form
+
+
+
+
+
+
+ Change Product Quantity
+ ir.actions.act_window
+ stock.change.product.qty
+ form
+ form
+
+ new
+
+
+
+
+