From 07d8aedb14afffb875d8dea56a46368628dba204 Mon Sep 17 00:00:00 2001 From: ced <> Date: Thu, 15 Feb 2007 13:11:32 +0000 Subject: [PATCH] STOCK-DELIVERY: add wizard invoice_onshipping from delivery to stock bzr revid: ced-8a9a311ad14668b855c7c691b89c7b482273be4d --- addons/delivery/__terp__.py | 2 +- addons/delivery/delivery_wizard.xml | 4 +- addons/stock/stock_wizard.xml | 10 ++ addons/stock/wizard/__init__.py | 1 + .../stock/wizard/wizard_invoice_onshipping.py | 127 ++++++++++++++++++ 5 files changed, 140 insertions(+), 4 deletions(-) create mode 100644 addons/stock/wizard/wizard_invoice_onshipping.py diff --git a/addons/delivery/__terp__.py b/addons/delivery/__terp__.py index 96d92ba7d95..d61f08f5a0c 100644 --- a/addons/delivery/__terp__.py +++ b/addons/delivery/__terp__.py @@ -4,7 +4,7 @@ "author" : "Tiny", "category" : "Generic Modules/Sales & Purchases", "description": "Allows to add delivery methods in sales order and pickings. You can define your own carrier and delivery grids for prices. When creating invoices from pickings, Tiny ERP is able to add and compute the shipping line.", - "depends" : ["sale","purchase"], + "depends" : ["sale","purchase", "stock",], "init_xml" : ["delivery_data.xml"], "demo_xml" : ["delivery_demo.xml"], "update_xml" : ["delivery_view.xml","delivery_wizard.xml"], diff --git a/addons/delivery/delivery_wizard.xml b/addons/delivery/delivery_wizard.xml index 9157e6d5eb4..c998199f0de 100644 --- a/addons/delivery/delivery_wizard.xml +++ b/addons/delivery/delivery_wizard.xml @@ -14,10 +14,8 @@ model="stock.picking" name="delivery.invoice_onshipping" keyword="client_action_multi" - id="wizard_delivery_invoice_onshipping" + id="stock.wizard_invoice_onshipping" /> - - diff --git a/addons/stock/stock_wizard.xml b/addons/stock/stock_wizard.xml index a3af915614f..313b14057dd 100644 --- a/addons/stock/stock_wizard.xml +++ b/addons/stock/stock_wizard.xml @@ -20,5 +20,15 @@ --> + + + + diff --git a/addons/stock/wizard/__init__.py b/addons/stock/wizard/__init__.py index 7de9d47ee03..9778a7faa3d 100644 --- a/addons/stock/wizard/__init__.py +++ b/addons/stock/wizard/__init__.py @@ -35,3 +35,4 @@ import wizard_split_lot_line import wizard_split_track_line import wizard_track_line import wizard_ups +import wizard_invoice_onshipping diff --git a/addons/stock/wizard/wizard_invoice_onshipping.py b/addons/stock/wizard/wizard_invoice_onshipping.py new file mode 100644 index 00000000000..bb788029ed0 --- /dev/null +++ b/addons/stock/wizard/wizard_invoice_onshipping.py @@ -0,0 +1,127 @@ +############################################################################## +# +# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved. +# +# 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 time +import wizard +import ir +import pooler +from osv.osv import except_osv +import netsvc + +invoice_form = """ +
+ + + + + + + +""" + +invoice_fields = { + 'journal_id' : { + 'string':'Destination Journal', + 'type':'many2one', + 'relation':'account.journal', + 'required':True + }, + 'group' : {'string':'Group by partner', 'type':'boolean'} +} + +def make_default(val): + def fct(obj, cr, uid): + return val + return fct + +def _get_type(self, cr, uid, data, context): + picking_obj=pooler.get_pool(cr.dbname).get('stock.picking') + pick=picking_obj.browse(cr, uid, [data['id']])[0] + if pick.loc_move_id: + usage=pick.loc_move_id.usage + else: + usage=pick.move_lines[0].location_id.usage + if pick.type=='out' and usage=='supplier': + type='in_refund' + elif pick.type=='out' and usage=='customer': + type='out_invoice' + elif pick.type=='in' and usage=='supplier': + type='in_invoice' + elif pick.type=='in' and usage=='customer': + type='out_refund' + else: + type='out_invoice' + invoice_fields['type']={'string':'Type', 'type':'selection', 'default':make_default(type), + 'selection':[ + ('out_invoice','Customer Invoice'), + ('in_invoice','Supplier Invoice'), + ('out_refund','Customer Refund'), + ('in_refund','Supplier Refund'), + ], 'required':True} + return {} + +def _create_invoice(self, cr, uid, data, context): + pool = pooler.get_pool(cr.dbname) + picking_obj = pooler.get_pool(cr.dbname).get('stock.picking') + res = picking_obj.action_invoice_create(cr, uid, data['ids'],journal_id=data['form']['journal_id'],group=data['form']['group'], type=data['form']['type'], context= context) + for pick_id, inv_id in res.items(): + pool.get('stock.picking').write(cr, uid, [pick_id], {'invoice_state':'invoiced'}) + return res + +def _action_open_window(self, cr, uid, data, context): + res = _create_invoice(self, cr, uid, data, context) + iids = res.values() + form = data['form'] + return { + 'domain': "[('id','in', ["+','.join(map(str,iids))+"])]", + 'name': 'Invoices', + 'view_type': 'form', + 'view_mode': 'tree,form', + 'res_model': 'account.invoice', + 'view_id': False, + 'context': "{'type':'out_invoice'}", + 'type': 'ir.actions.act_window' + } + +class make_invoice_onshipping(wizard.interface): + states = { + 'init' : { + 'actions' : [_get_type], + 'result' : {'type' : 'form', + 'arch' : invoice_form, + 'fields' : invoice_fields, + 'state' : [('end', 'Cancel'),('create_invoice', 'Create invoice') ]} + }, + 'create_invoice' : { + 'actions' : [], + 'result' : {'type' : 'action', 'action': _action_open_window, 'state' : 'end'} + }, + } +make_invoice_onshipping("stock.invoice_onshipping") + + +