1 ##############################################################################
3 # Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
5 # $Id: make_invoice.py 1070 2005-07-29 12:41:24Z nicoe $
7 # WARNING: This program as such is intended to be used by professional
8 # programmers who take the whole responsability of assessing all potential
9 # consequences resulting from its eventual inadequacies and bugs
10 # End users who are looking for a ready-to-use solution with commercial
11 # garantees and support are strongly adviced to contract a Free Software
14 # This program is Free Software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 ##############################################################################
35 invoice_form = """<?xml version="1.0"?>
36 <form string="Create invoices">
37 <separator colspan="4" string="Do you really want to create the invoices ?" />
38 <field name="grouped" />
43 'grouped' : {'string':'Group the invoices', 'type':'boolean', 'default': lambda *a: False}
46 def _makeInvoices(self, cr, uid, data, context):
47 pool = pooler.get_pool(cr.dbname)
51 #TODO: merge with sale.py/make_invoice
52 def make_invoice(order, lines):
53 a = order.partner_id.property_account_receivable.id
56 'origin': 'SO:'+str(order.id)+':'+order.name,
57 'reference': "P%dSO%d" % (order.partner_id.id, order.id),
59 'partner_id': order.partner_id.id,
60 'address_invoice_id': order.partner_invoice_id.id,
61 'address_contact_id': order.partner_invoice_id.id,
62 'project_id': order.project_id.id,
63 'invoice_line': [(6,0,lines)],
64 'currency_id' : order.pricelist_id.currency_id.id,
66 inv_id = pool.get('account.invoice').create(cr, uid, inv, {'type' : 'customer_invoice'})
69 for line in pool.get('sale.order.line').browse(cr,uid,data['ids']):
71 if not line.order_id.id in factures:
72 factures[line.order_id.id] = []
73 line_id = pool.get('sale.order.line').invoice_line_create(cr, uid, [line.id])
75 factures[line.order_id.id].append((line, lid))
76 pool.get('sale.order.line').write(cr, uid, [line.id], {'invoiced':True})
78 for result in factures.values():
79 order = result[0][0].order_id
80 il = map(lambda x: x[1], result)
81 res = make_invoice(order, il)
82 cr.execute('insert into sale_order_invoice_rel (order_id,invoice_id) values (%d,%d)', (order.id, res))
85 class line_make_invoice(wizard.interface):
89 'result' : {'type' : 'form', 'arch' : invoice_form, 'fields' : invoice_fields, 'state' : [('end', 'Cancel'),('invoice', 'Create invoices') ]}
92 'actions' : [_makeInvoices],
93 'result' : {'type':'state', 'state':'end'}
96 line_make_invoice("sale.order.line.make_invoice")