diff --git a/addons/event/__terp__.py b/addons/event/__terp__.py index bd61f486a05..3e76b9d19a2 100644 --- a/addons/event/__terp__.py +++ b/addons/event/__terp__.py @@ -41,7 +41,6 @@ 'depends': ['crm', 'base_contact', 'account'], 'init_xml': ['event_data.xml'], 'update_xml': [ - 'event_wizard.xml', 'wizard/event_confirm_registration_view.xml', 'event_view.xml', 'event_sequence.xml', @@ -49,7 +48,7 @@ 'security/ir.model.access.csv', 'wizard/event_registration_view.xml', 'wizard/event_registrations_partner.xml', - + 'wizard/event_make_invoice_view.xml', ], 'demo_xml': ['event_demo.xml'], 'installable': True, diff --git a/addons/event/event_wizard.xml b/addons/event/event_wizard.xml deleted file mode 100644 index 7042b4e67b5..00000000000 --- a/addons/event/event_wizard.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - diff --git a/addons/event/wizard/__init__.py b/addons/event/wizard/__init__.py index b151b760d9f..81191b5a2f9 100644 --- a/addons/event/wizard/__init__.py +++ b/addons/event/wizard/__init__.py @@ -20,7 +20,7 @@ ############################################################################## import event_registration -import make_invoice +import event_make_invoice import event_registrations_partner import event_confirm_registration # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/event/wizard/event_make_invoice.py b/addons/event/wizard/event_make_invoice.py new file mode 100644 index 00000000000..1df4d2f2277 --- /dev/null +++ b/addons/event/wizard/event_make_invoice.py @@ -0,0 +1,140 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from osv import fields, osv + +class event_make_invoice(osv.osv_memory): + """ + Make Invoices + """ + _name = "event.make.invoice" + _description = "Event Make Invoice" + _columns = { + 'inv_created': fields.char('Invoice Created', size=32, readonly=True), + 'inv_rejected': fields.char('Invoice Rejected', size=32, readonly=True), + 'inv_rej_reason': fields.text('Error Messages', readonly=True), +# 'invoice_ids': fields.char('Invoice Ids', size=128), # Improve me + } + + def _makeInvoices(self, cr, uid, context={}): + invoices = {} + invoice_ids = [] + create_ids=[] + tax_ids=[] + inv_create = 0 + inv_reject = 0 + inv_rej_reason = "" + list_inv = [] + obj_event_reg = self.pool.get('event.registration') + obj_lines = self.pool.get('account.invoice.line') + inv_obj = self.pool.get('account.invoice') + data_event_reg = obj_event_reg.browse(cr,uid, context['active_ids'], context=context) + + for reg in data_event_reg: + if reg.state=='draft': + inv_reject = inv_reject + 1 + inv_rej_reason += "ID "+str(reg.id)+": Invoice cannot be created if the registration is in draft state. \n" + continue + if (not reg.tobe_invoiced): + inv_reject = inv_reject + 1 + inv_rej_reason += "ID "+str(reg.id)+": Registration is set as 'Cannot be invoiced'. \n" + continue + if reg.invoice_id: + inv_reject = inv_reject + 1 + inv_rej_reason += "ID "+str(reg.id)+": Registration already has an invoice linked. \n" + continue + if not reg.event_id.product_id: + inv_reject = inv_reject + 1 + inv_rej_reason += "ID "+str(reg.id)+": Event related doesn't have any product defined. \n" + continue + if not reg.partner_invoice_id: + inv_reject = inv_reject + 1 + inv_rej_reason += "ID "+str(reg.id)+": Registration doesn't have any partner to invoice. \n" + continue + partner_address_list = reg.partner_invoice_id and self.pool.get('res.partner').address_get(cr, uid, [reg.partner_invoice_id.id], adr_pref=['invoice']) + partner_address_id = partner_address_list['invoice'] + if not partner_address_id: + inv_reject = inv_reject + 1 + inv_rej_reason += "ID "+str(reg.id)+": Registered partner doesn't have an address to make the invoice. \n" + continue + + inv_create = inv_create + 1 + value = obj_lines.product_id_change(cr, uid, [], reg.event_id.product_id.id,uom =False, partner_id=reg.partner_invoice_id.id, fposition_id=reg.partner_invoice_id.property_account_position.id) + data_product = self.pool.get('product.product').browse(cr,uid,[reg.event_id.product_id.id]) + for tax in data_product[0].taxes_id: + tax_ids.append(tax.id) + + vals = value['value'] + vals.update({ + 'name': reg.name, + 'price_unit': reg.unit_price, + 'quantity': reg.nb_register, + 'product_id':reg.event_id.product_id.id, + 'invoice_line_tax_id': [(6, 0, tax_ids)], + }) + inv_line_ids = obj_event_reg._create_invoice_lines(cr, uid, [reg.id], vals) + + inv = { + 'name': reg.invoice_label, + 'origin': reg.invoice_label, + 'type': 'out_invoice', + 'reference': False, + 'account_id': reg.partner_invoice_id.property_account_receivable.id, + 'partner_id': reg.partner_invoice_id.id, + 'address_invoice_id':partner_address_id, + 'address_contact_id':partner_address_id, + 'invoice_line': [(6,0,[inv_line_ids])], + 'currency_id' :reg.partner_invoice_id.property_product_pricelist.currency_id.id, + 'comment': "", + 'payment_term':reg.partner_invoice_id.property_payment_term.id, + 'fiscal_position': reg.partner_invoice_id.property_account_position.id + } + + inv_id = inv_obj.create(cr, uid, inv) + list_inv.append(inv_id) + obj_event_reg.write(cr, uid, reg.id, {'invoice_id': inv_id, 'state': 'done'}) + obj_event_reg._history(cr, uid, [reg.id], 'Invoiced', history=True) + +# {'inv_created' : str(inv_create) , 'inv_rejected' : str(inv_reject), 'invoice_ids': str(list_inv), 'inv_rej_reason': inv_rej_reason} + return {'inv_created' : str(inv_create) , 'inv_rejected' : str(inv_reject), 'inv_rej_reason': inv_rej_reason} + + def default_get(self, cr, uid, fields_list, context=None): + res = super(event_make_invoice, self).default_get(cr, uid, fields_list, context) + res.update(self._makeInvoices(cr, uid, context=context)) + return res + + def confirm(self, cr, uid, ids, context={}): + obj_model = self.pool.get('ir.model.data') + data_inv = self.read(cr, uid, ids, [], context)[0] + model_data_ids = obj_model.search(cr,uid,[('model','=','ir.ui.view'),('name','=','invoice_form')]) + resource_id = obj_model.read(cr,uid,model_data_ids,fields=['res_id'])[0]['res_id'] + return { +# 'domain': "[('id','in', ["+','.join(map(str,data_inv['invoice_ids']))+"])]", + 'name': 'Invoices', + 'view_type': 'form', + 'view_mode': 'tree,form', + 'res_model': 'account.invoice', + 'views': [(False,'tree'),(resource_id,'form')], + 'context': "{'type':'out_invoice'}", + 'type': 'ir.actions.act_window' + } + +event_make_invoice() +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/event/wizard/event_make_invoice_view.xml b/addons/event/wizard/event_make_invoice_view.xml new file mode 100644 index 00000000000..0f4c7c9c152 --- /dev/null +++ b/addons/event/wizard/event_make_invoice_view.xml @@ -0,0 +1,39 @@ + + + + + + event.make.invoice + event.make.invoice + form + +
+ + + + +