1
##############################################################################
3
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
5
# WARNING: This program as such is intended to be used by professional
6
# programmers who take the whole responsability of assessing all potential
7
# consequences resulting from its eventual inadequacies and bugs
8
# End users who are looking for a ready-to-use solution with commercial
9
# garantees and support are strongly adviced to contract a Free Software
12
# This program is Free Software; you can redistribute it and/or
13
# modify it under the terms of the GNU General Public License
14
# as published by the Free Software Foundation; either version 2
15
# of the License, or (at your option) any later version.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU General Public License for more details.
22
# You should have received a copy of the GNU General Public License
23
# along with this program; if not, write to the Free Software
24
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
##############################################################################
32
from osv.osv import except_osv
35
invoice_form = """<?xml version="1.0"?>
36
<form string="Create invoices">
37
<separator colspan="4" string="Create invoices" />
38
<field name="journal_id"/>
48
'string':'Destination Journal',
50
'relation':'account.journal',
52
'domain':[('type','=','sale')]
54
'group' : {'string':'Group by partner', 'type':'boolean'}
57
def make_default(val):
58
def fct(obj, cr, uid):
62
def _get_type(self, cr, uid, data, context):
63
picking_obj=pooler.get_pool(cr.dbname).get('stock.picking')
64
pick=picking_obj.browse(cr, uid, [data['id']])[0]
66
usage=pick.loc_move_id.usage
68
usage=pick.move_lines[0].location_id.usage
69
if pick.type=='out' and usage=='supplier':
71
elif pick.type=='out' and usage=='customer':
73
elif pick.type=='in' and usage=='supplier':
75
elif pick.type=='in' and usage=='customer':
79
invoice_fields['type']={'string':'Type', 'type':'selection', 'default':make_default(type),
81
('out_invoice','Customer Invoice'),
82
('in_invoice','Supplier Invoice'),
83
('out_refund','Customer Refund'),
84
('in_refund','Supplier Refund'),
88
def _create_invoice(self, cr, uid, data, context):
89
pool = pooler.get_pool(cr.dbname)
90
picking_obj = pooler.get_pool(cr.dbname).get('stock.picking')
91
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)
92
for pick_id, inv_id in res.items():
93
pool.get('stock.picking').write(cr, uid, [pick_id], {'invoice_state':'invoiced'})
94
invoice = pool.get('account.invoice').browse(cr, uid, inv_id, context)
95
picking = pool.get('stock.picking').browse(cr, uid, pick_id, context)
96
if not picking.carrier_id:
98
grid_id = pool.get('delivery.carrier').grid_get(cr, uid, [picking.carrier_id.id], picking.address_id.id, context)
99
price = pool.get('delivery.grid').get_price_from_picking(cr, uid, grid_id,
100
invoice.amount_untaxed, picking.weight,
101
picking.volume, context) or 0.0
102
a = picking.carrier_id.product_id.product_tmpl_id.property_account_income
104
a = picking.carrier_id.product_id.categ_id.property_account_income_categ
106
pool.get('account.invoice.line').create(cr, uid, {
107
'name':picking.carrier_id.name,
108
'invoice_id': inv_id,
109
'uos_id': picking.carrier_id.product_id.uos_id.id,
110
'product_id':picking.carrier_id.product_id.id,
111
'account_id':account_id,
114
'invoice_line_tax_id': [(6,0,[x.id for x in (picking.carrier_id.product_id.taxes_id or []) ])],
119
def _action_open_window(self, cr, uid, data, context):
120
res = _create_invoice(self, cr, uid, data, context)
124
'domain': "[('id','in', ["+','.join(map(str,iids))+"])]",
127
'view_mode': 'tree,form',
128
'res_model': 'account.invoice',
130
'context': "{'type':'out_invoice'}",
131
'type': 'ir.actions.act_window'
134
class make_invoice_onshipping(wizard.interface):
137
'actions' : [_get_type],
138
'result' : {'type' : 'form',
139
'arch' : invoice_form,
140
'fields' : invoice_fields,
141
'state' : [('end', 'Cancel'),('create_invoice', 'Create invoice') ]}
145
'result' : {'type' : 'action', 'action': _action_open_window, 'state' : 'end'}
148
make_invoice_onshipping("delivery.invoice_onshipping")