diff --git a/addons/delivery/delivery_wizard.xml b/addons/delivery/delivery_wizard.xml index c998199f0de..fe9047eef9b 100644 --- a/addons/delivery/delivery_wizard.xml +++ b/addons/delivery/delivery_wizard.xml @@ -2,20 +2,12 @@ - - + string="Add delivery line" + model="sale.order" + name="delivery.sale.order" + id="wizard_deliver_line_add" + keyword="client_action_multi"/> diff --git a/addons/delivery/stock.py b/addons/delivery/stock.py index 8048ce9f076..c79db52e516 100644 --- a/addons/delivery/stock.py +++ b/addons/delivery/stock.py @@ -6,14 +6,65 @@ from osv import fields,osv class stock_picking(osv.osv): _name = "stock.picking" _description = "Picking list" - _inherit = 'stock.picking' + _inherit = 'stock.picking' _columns = { - 'carrier_id':fields.many2one("delivery.carrier","Carrier"), + 'carrier_id':fields.many2one("delivery.carrier","Carrier"), 'volume': fields.float('Volume'), 'weight': fields.float('Weight'), - } + def action_invoice_create(self, cursor, user, ids, journal_id=False, + group=False, type='out_invoice', context=None): + invoice_obj = self.pool.get('account.invoice') + picking_obj = self.pool.get('stock.picking') + carrier_obj = self.pool.get('delivery.carrier') + grid_obj = self.pool.get('delivery.grid') + invoice_line_obj = self.pool.get('account.invoice.line') + result = super(stock_picking, self).action_invoice_create(cursor, user, + ids, journal_id=journal_id, group=group, type=type, + context=context) + + picking_ids = result.keys() + invoice_ids = result.values() + + invoices = {} + for invoice in invoice_obj.browse(cursor, user, invoice_ids, + context=context): + invoices[invoice.id] = invoice + + for picking in picking_obj.browse(cursor, user, picking_ids, + context=context): + if not picking.carrier_id: + continue + grid_id = carrier_obj.grid_get(cursor, user, [picking.carrier_id.id], + picking.address_id.id, context=context) + if not grid_id: + raise osv.except_osv('Warning', + 'The carrier %s (id: %d) has no delivery grid!' \ + % (picking.carrier_id.name, + picking.carrier_id.id)) + invoice = invoices[result[picking.id]] + price = grid_obj.get_price_from_picking(cursor, user, grid_id, + invoice.amount_untaxed, picking.weight, picking.volume, + context=context) + account_id = picking.carrier_id.product_id.product_tmpl_id\ + .property_account_income.id + if not account_id: + account_id = picking.carrier_id.product_id.categ_id\ + .property_account_income_categ.id + invoice_line_obj.create(cursor, user, { + 'name': picking.carrier_id.name, + 'invoice_id': invoice.id, + 'uos_id': picking.carrier_id.product_id.uos_id.id, + 'product_id': picking.carrier_id.product_id.id, + 'account_id': account_id, + 'price_unit': price, + 'quantity': 1, + 'invoice_line_tax_id': [(6, 0, + [x.id for x in (picking.carrier_id.product_id.taxes_id + or [])])], + }) + return result stock_picking() diff --git a/addons/delivery/wizard/__init__.py b/addons/delivery/wizard/__init__.py index 937cfe21bff..96fca6b2d13 100644 --- a/addons/delivery/wizard/__init__.py +++ b/addons/delivery/wizard/__init__.py @@ -26,4 +26,3 @@ ############################################################################## import delivery_sale_order -import delivery_invoice_onshipping diff --git a/addons/delivery/wizard/delivery_invoice_onshipping.py b/addons/delivery/wizard/delivery_invoice_onshipping.py deleted file mode 100644 index 5ad964e84d8..00000000000 --- a/addons/delivery/wizard/delivery_invoice_onshipping.py +++ /dev/null @@ -1,149 +0,0 @@ -############################################################################## -# -# 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'}) - invoice = pool.get('account.invoice').browse(cr, uid, inv_id, context) - picking = pool.get('stock.picking').browse(cr, uid, pick_id, context) - if not picking.carrier_id: - continue - grid_id = pool.get('delivery.carrier').grid_get(cr, uid, [picking.carrier_id.id], picking.address_id.id, context) - if not grid_id: - raise wizard.except_wizard('Warning', 'The carrier %s (id: %d) as no delivery grid.'% (picking.carrier_id.name, picking.carrier_id.id) ) - price = pool.get('delivery.grid').get_price_from_picking(cr, uid, grid_id, - invoice.amount_untaxed, picking.weight, - picking.volume, context) or 0.0 - account_id = picking.carrier_id.product_id.product_tmpl_id.property_account_income.id - if not account_id: - account_id = picking.carrier_id.product_id.categ_id.property_account_income_categ.id - pool.get('account.invoice.line').create(cr, uid, { - 'name':picking.carrier_id.name, - 'invoice_id': inv_id, - 'uos_id': picking.carrier_id.product_id.uos_id.id, - 'product_id':picking.carrier_id.product_id.id, - 'account_id':account_id, - 'price_unit': price, - 'quantity': 1, - 'invoice_line_tax_id': [(6,0,[x.id for x in (picking.carrier_id.product_id.taxes_id or []) ])], - 'note': '', - }) - 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("delivery.invoice_onshipping") - diff --git a/addons/stock/wizard/wizard_invoice_onshipping.py b/addons/stock/wizard/wizard_invoice_onshipping.py index bb788029ed0..30cd19b22e7 100644 --- a/addons/stock/wizard/wizard_invoice_onshipping.py +++ b/addons/stock/wizard/wizard_invoice_onshipping.py @@ -44,84 +44,110 @@ invoice_form = """ """ invoice_fields = { - 'journal_id' : { - 'string':'Destination Journal', - 'type':'many2one', - 'relation':'account.journal', - 'required':True + 'journal_id': { + 'string': 'Destination Journal', + 'type': 'many2one', + 'relation': 'account.journal', + 'required': True + }, + 'group': { + 'string': 'Group by partner', + 'type':'boolean' + }, + 'type': { + 'string': 'Type', + 'type': 'selection', + 'selection': [ + ('out_invoice', 'Customer Invoice'), + ('in_invoice', 'Supplier Invoice'), + ('out_refund', 'Customer Refund'), + ('in_refund', 'Supplier Refund'), + ], + '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): +def _get_type(obj, cr, uid, data, context): picking_obj=pooler.get_pool(cr.dbname).get('stock.picking') - pick=picking_obj.browse(cr, uid, [data['id']])[0] + + pick=picking_obj.browse(cr, uid, data['id']) 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): + 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' + return {'type': type} + +def _create_invoice(obj, 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 + mod_obj = pool.get('ir.model.data') + act_obj = pool.get('ir.actions.act_window') + + type = data['form']['type'] + + res = picking_obj.action_invoice_create(cr, uid, data['ids'], + journal_id=data['form']['journal_id'],group=data['form']['group'], + type=type, context= context) + + pick_ids = res.keys() + invoice_ids = res.values() + + pool.get('stock.picking').write(cr, uid, pick_ids, + {'invoice_state': 'invoiced'}) + + if not invoice_ids: + return {} + + if type == 'out_invoice': + xml_id = 'action_invoice_tree5' + elif type == 'in_invoice': + xml_id = 'action_invoice_tree8' + elif type == 'out_refund': + xml_id = 'action_invoice_tree10' + else: + xml_id = 'action_invoice_tree12' + + result = mod_obj._get_id(cr, uid, 'account', xml_id) + id = mod_obj.read(cr, uid, result, ['res_id'])['res_id'] + result = act_obj.read(cr, uid, id) + result['res_id'] = invoice_ids + return result -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') ]} + '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'} + 'create_invoice': { + 'actions': [], + 'result': { + 'type': 'action', + 'action': _create_invoice, + 'state': 'end' + } }, } + make_invoice_onshipping("stock.invoice_onshipping") - -