[ADD]wizard to change Product Quantity from Product form View

bzr revid: ron@tinyerp.com-20101203130621-ddfrcf36mls4p7q5
This commit is contained in:
ron@tinyerp.com 2010-12-03 18:36:21 +05:30
parent 5324a27c17
commit d108a970e6
6 changed files with 151 additions and 5 deletions

View File

@ -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",

View File

@ -102,9 +102,12 @@
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="arch" type="xml">
<group name="status" position="after">
<group colspan="2" col="2">
<group colspan="2" col="3">
<separator string="Stocks" colspan="4"/>
<field name="qty_available"/>
<button name="%(action_view_change_product_quantity)d" string="Update"
type="action" icon="gtk-execute" />
<newline/>
<field name="virtual_available"/>
</group>
<group colspan="2" col="2" name="lot" groups="base.group_extended">

View File

@ -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)

View File

@ -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:

View File

@ -0,0 +1,106 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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()

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_change_product_quantity" model="ir.ui.view">
<field name="name">Change Product Quantity</field>
<field name="model">stock.change.product.qty</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Change Product Quantity">
<separator string="Change Quantity" colspan="4"/>
<newline/>
<field name="new_quantity" />
<field name="warehouse_id" on_change="onchange_warehouse_id(warehouse_id)" widget="selection"/>
<field name="location_id" />
<separator string="" colspan="4" />
<label string="" colspan="2"/>
<group col="2" colspan="2">
<button special="cancel" string="_Cancel" icon="gtk-cancel"/>
<button name="change_product_qty" string="_Apply" type="object" icon="gtk-apply"/>
</group>
</form>
</field>
</record>
<record id="action_view_change_product_quantity" model="ir.actions.act_window">
<field name="name">Change Product Quantity</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">stock.change.product.qty</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_change_product_quantity"/>
<field name="target">new</field>
</record>
</data>
</openerp>