calculated product stock on stock move between given dates in context and open wizard for that on location tree structure

bzr revid: hmo@tinyerp.com-20080920111331-0x1nsrdcxdt8jluj
This commit is contained in:
Harshad Modi
2008-09-20 16:43:31 +05:30
parent 4f1a35dd18
commit fec257ca0a
6 changed files with 113 additions and 70 deletions
+16 -4
View File
@@ -202,6 +202,7 @@ class stock_location(osv.osv):
return result
def _product_get_multi_location(self, cr, uid, ids, product_ids=False, context={}, states=['done'], what=('in', 'out')):
product_obj = self.pool.get('product.product')
states_str = ','.join(map(lambda s: "'%s'" % s, states))
if not product_ids:
@@ -218,27 +219,38 @@ class stock_location(osv.osv):
location_ids_str = ','.join(map(str, ids))
results = []
results2 = []
from_date=context.get('from_date',False)
to_date=context.get('to_date',False)
date_str=False
if from_date and to_date:
date_str="date>='%s' and date<=%s"%(from_date,to_date)
elif from_date:
date_str="date>='%s'"%(from_date)
elif to_date:
date_str="date<='%s'"%(to_date)
if 'in' in what:
# all moves from a location out of the set to a location in the set
# all moves from a location out of the set to a location in the set
cr.execute(
'select sum(product_qty), product_id, product_uom '\
'from stock_move '\
'where location_id not in ('+location_ids_str+') '\
'and location_dest_id in ('+location_ids_str+') '\
'and product_id in ('+prod_ids_str+') '\
'and state in ('+states_str+') '\
'and state in ('+states_str+') '+ (date_str and 'and '+date_str+' ' or '') +''\
'group by product_id,product_uom'
)
results = cr.fetchall()
if 'out' in what:
# all moves from a location in the set to a location out of the set
# all moves from a location in the set to a location out of the set
cr.execute(
'select sum(product_qty), product_id, product_uom '\
'from stock_move '\
'where location_id in ('+location_ids_str+') '\
'and location_dest_id not in ('+location_ids_str+') '\
'and product_id in ('+prod_ids_str+') '\
'and state in ('+states_str+') '\
'and state in ('+states_str+') '+ (date_str and 'and '+date_str+' ' or '') + ''\
'group by product_id,product_uom'
)
results2 = cr.fetchall()
+16 -4
View File
@@ -1252,19 +1252,31 @@
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem action="action_incoterms_tree" id="menu_action_incoterms_tree" parent="menu_stock_configuration"/>
<menuitem action="action_incoterms_tree" id="menu_action_incoterms_tree" parent="menu_stock_configuration"/>
<act_window context="{'location': active_id}" domain="[('type','&lt;&gt;','service')]" id="act_product_location_open" name="Products" res_model="product.product" src_model="stock.location"/>
<act_window context="{'location': active_id}" domain="[('product_id','=',active_id)]" id="act_product_stock_move_open" name="Stock Moves" res_model="stock.move" src_model="product.product"/>
<record id="ir_act_product_location_open" model="ir.values">
<record id="ir_act_product_location_open" model="ir.values">
<field name="key2">tree_but_open</field>
<field name="model">stock.location</field>
<field name="name">Products</field>
<field eval="'ir.actions.act_window,%d'%act_product_location_open" name="value"/>
<field eval="True" name="object"/>
</record>
</record>    
<record id="ir_act_product_location_open" model="ir.values">
<field name="key2">tree_but_open</field>
<field name="model">stock.location</field>
<field name="name">Open Products</field>
<field eval="'ir.actions.wizard,%d'%ref('location_product')" name="value"/>
<field eval="True" name="object"/>
</record>  
     
</data>
</openerp>
+2
View File
@@ -42,5 +42,7 @@
keyword="client_action_multi"
id="wizard_fill_inventory"
/>
<wizard id="location_product" model="stock.location" name="stock.location.products" string="Products by Location"/>
</data>
</openerp>
+1 -1
View File
@@ -37,7 +37,7 @@ import wizard_split_lot_line
import wizard_track_line
import wizard_ups
import wizard_invoice_onshipping
import wizard_move_by_location
import wizard_location_product
import wizard_inventory
import inventory_merge_zero
import inventory_merge
+78
View File
@@ -0,0 +1,78 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
#
# $Id$
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import wizard
import pooler
import time
def _action_open_window(self, cr, uid, data, context):
return {
'view_type': 'form',
"view_mode": 'tree,form',
'res_model': 'product.product',
'type': 'ir.actions.act_window',
'context':{'location': data['ids'][0],'from_date':data['form']['from_date'],'to_date':data['form']['to_date']},
'domain':[('type','<>','service')]
}
class product_by_location(wizard.interface):
form1 = '''<?xml version="1.0"?>
<form string="View Stock of Products">
<field name="from_date"/>
<newline/>
<field name="to_date"/>
</form>'''
form1_fields = {
'from_date': {
'string': 'From',
'type': 'date',
},
'to_date': {
'string': 'To',
'type': 'date',
},
}
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch':form1, 'fields':form1_fields, 'state': [ ('open', 'Open Products'),('end', 'Cancel')]}
},
'open': {
'actions': [],
'result': {'type': 'action', 'action': _action_open_window, 'state':'end'}
}
}
product_by_location('stock.location.products')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -1,61 +0,0 @@
# -*- encoding: utf-8 -*-
import wizard
import pooler
import time
def _action_open_window(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
mod_obj = pool.get('ir.model.data')
act_obj = pool.get('ir.actions.act_window')
result = mod_obj._get_id(cr, uid, 'stock', 'action_move_form2')
id = mod_obj.read(cr, uid, [result], ['res_id'])[0]['res_id']
result = act_obj.read(cr, uid, [id])[0]
location_id = data['ids'][0]
domain = []
# domain += [ '|' ,('location_id', '=', location_id) , ('location_dest_id', '=', location_id)]
if data['form']['from']:
domain += [('date_planned', '>=', data['form']['from'])]
if data['form']['to']:
domain += [('date_planned', '<=', data['form']['to'])]
result['domain'] = str(domain)
# result['context'] = str({'location_id': location_id })
return result
class move_by_location(wizard.interface):
form1 = '''<?xml version="1.0"?>
<form string="View Stock Moves">
<field name="from"/>
<newline/>
<field name="to"/>
</form>'''
form1_fields = {
'from': {
'string': 'From',
'type': 'date',
},
'to': {
'string': 'To',
'type': 'date',
# 'default': lambda *a: time.strftime("%Y-%m-%d"),
},
}
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch':form1, 'fields':form1_fields, 'state': [ ('open', 'Open Moves'),('end', 'Cancel')]}
},
'open': {
'actions': [],
'result': {'type': 'action', 'action': _action_open_window, 'state':'end'}
}
}
move_by_location('stock.location.moves')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: