diff --git a/addons/delivery/delivery.py b/addons/delivery/delivery.py index da4bd854b10..e4b0cd88837 100644 --- a/addons/delivery/delivery.py +++ b/addons/delivery/delivery.py @@ -27,19 +27,34 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################## - +import time import netsvc from osv import fields,osv,orm from tools.translate import _ class delivery_carrier(osv.osv): _name = "delivery.carrier" - _description = "Carrier and delivery grids" + _description = "Carrier and delivery grids" + + def get_price(self, cr, uid, ids, field_name, arg=None, context={}): + res={} + sale_obj=self.pool.get('sale.order') + grid_obj=self.pool.get('delivery.grid') + for carrier in self.browse(cr,uid,ids,context): + order_id=context.get('order_id',False) + price=False + if order_id: + order = sale_obj.browse(cr, uid, [order_id])[0] + carrier_grid=self.grid_get(cr,uid,[carrier.id],order.partner_shipping_id.id,context) + price=grid_obj.get_price(cr, uid, carrier_grid, order, time.strftime('%Y-%m-%d'), context) + res[carrier.id]=price + return res _columns = { 'name': fields.char('Carrier', size=64, required=True), 'partner_id': fields.many2one('res.partner', 'Carrier Partner', required=True), 'product_id': fields.many2one('product.product', 'Delivery Product', required=True), 'grids_id': fields.one2many('delivery.grid', 'carrier_id', 'Delivery Grids'), + 'price' : fields.function(get_price, method=True,string='Price'), 'active': fields.boolean('Active') } _defaults = { @@ -89,9 +104,8 @@ class delivery_grid(osv.osv): total = 0 weight = 0 - volume = 0 - - for line in order.order_line: + volume = 0 + for line in order.order_line: if not line.product_id: continue total += line.price_subtotal or 0.0 @@ -151,6 +165,5 @@ class delivery_grid_line(osv.osv): delivery_grid_line() - # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/delivery/delivery_view.xml b/addons/delivery/delivery_view.xml index 282c33b8921..307f9128ed0 100644 --- a/addons/delivery/delivery_view.xml +++ b/addons/delivery/delivery_view.xml @@ -12,6 +12,7 @@ + @@ -125,7 +126,7 @@ - + @@ -176,7 +177,7 @@ stock.picking ir.actions.act_window form - tree,form + tree,form [('invoice_state','=','2binvoiced'),('state','=','done'),('type','=','out')] diff --git a/addons/delivery/wizard/delivery_sale_order.py b/addons/delivery/wizard/delivery_sale_order.py index 4a8dcaa6d38..8b56145639c 100644 --- a/addons/delivery/wizard/delivery_sale_order.py +++ b/addons/delivery/wizard/delivery_sale_order.py @@ -37,7 +37,7 @@ from tools.translate import _ delivery_form = """
- + """ @@ -48,9 +48,11 @@ delivery_fields = { def _delivery_default(self, cr, uid, data, context): order_obj = pooler.get_pool(cr.dbname).get('sale.order') order = order_obj.browse(cr, uid, data['ids'])[0] + if not order.state in ('draft'): raise wizard.except_wizard(_('Order not in draft state !'), _('The order state have to be draft to add delivery lines.')) + carrier_id = order.partner_id.property_delivery_carrier.id return {'carrier_id': carrier_id} diff --git a/addons/sale/sale_view.xml b/addons/sale/sale_view.xml index d4b6f973de8..68cf27bddf5 100644 --- a/addons/sale/sale_view.xml +++ b/addons/sale/sale_view.xml @@ -231,6 +231,7 @@ form tree,form,calendar,graph [('user_id','=',uid)] + diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 3fb81c22195..e655c52ef64 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -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() diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml index d935858d35e..5e7d96ff2e4 100644 --- a/addons/stock/stock_view.xml +++ b/addons/stock/stock_view.xml @@ -1252,19 +1252,31 @@ form tree,form - + - - + + tree_but_open stock.location Products - +     + + + + tree_but_open + stock.location + Open Products + + +   + +       + diff --git a/addons/stock/stock_wizard.xml b/addons/stock/stock_wizard.xml index 4bbba3808d5..1e04921ea3c 100644 --- a/addons/stock/stock_wizard.xml +++ b/addons/stock/stock_wizard.xml @@ -42,5 +42,7 @@ keyword="client_action_multi" id="wizard_fill_inventory" /> + + diff --git a/addons/stock/wizard/__init__.py b/addons/stock/wizard/__init__.py index 0064614f005..4689425cee5 100644 --- a/addons/stock/wizard/__init__.py +++ b/addons/stock/wizard/__init__.py @@ -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 diff --git a/addons/stock/wizard/wizard_location_product.py b/addons/stock/wizard/wizard_location_product.py new file mode 100755 index 00000000000..0083c0e9863 --- /dev/null +++ b/addons/stock/wizard/wizard_location_product.py @@ -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 = ''' +
+ + + + ''' + + 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: diff --git a/addons/stock/wizard/wizard_move_by_location.py b/addons/stock/wizard/wizard_move_by_location.py deleted file mode 100755 index 3c1d025e721..00000000000 --- a/addons/stock/wizard/wizard_move_by_location.py +++ /dev/null @@ -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 = ''' -
- - - - ''' - - 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: \ No newline at end of file