[ADD] Event: Conver osv memory wizard create invoice from registration to osv memory type wizard
bzr revid: mra@tinyerp.com-20100401052338-ja6bzhgi8wush7xe
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" ?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<wizard string="Make Invoice"
|
||||
model="event.registration"
|
||||
name="event.reg_make_invoice"
|
||||
id="event_reg_invoice"
|
||||
menu="True"
|
||||
/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -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:
|
||||
@@ -0,0 +1,140 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
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:
|
||||
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="view_event_make_invoice" model="ir.ui.view">
|
||||
<field name="name">event.make.invoice</field>
|
||||
<field name="model">event.make.invoice</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Make Invoices">
|
||||
<field name="inv_created" />
|
||||
<field name="inv_rejected" />
|
||||
<field name="inv_rej_reason" colspan="4"/>
|
||||
<group colspan="4" col="6">
|
||||
<button icon="gtk-cancel" special="cancel" string="_Ok"/>
|
||||
<button icon="gtk-ok" name="confirm" string="Open" type="object"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_event_confirm_registration" model="ir.actions.act_window">
|
||||
<field name="name">Make Invoices</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">event.make.invoice</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="view_event_make_invoice"/>
|
||||
<field name="context">{'record_id' : active_id}</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<act_window id="action_make_invoices"
|
||||
key2 = "client_action_multi" name="Make Invoice"
|
||||
res_model="event.make.invoice" src_model="event.registration"
|
||||
view_mode="form" target="new" view_type="form" />
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -1,158 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import wizard
|
||||
import netsvc
|
||||
import pooler
|
||||
|
||||
from osv import fields, osv
|
||||
form = """<?xml version="1.0"?>
|
||||
<form string="Create Invoices">
|
||||
<newline />
|
||||
<field name="inv_created"/>
|
||||
<newline />
|
||||
<field name="inv_rejected"/>
|
||||
<newline />
|
||||
<field name="inv_rej_reason" width="400"/>
|
||||
</form>
|
||||
"""
|
||||
fields = {
|
||||
'inv_created': {'string':'Invoice Created', 'type':'char', 'readonly':True},
|
||||
'inv_rejected': {'string':'Invoice Rejected', 'type':'char', 'readonly':True},
|
||||
'inv_rej_reason': {'string':'Error Messages', 'type':'text', 'readonly':True},
|
||||
}
|
||||
|
||||
def _makeInvoices(self, cr, uid, data, context):
|
||||
invoices = {}
|
||||
invoice_ids = []
|
||||
create_ids=[]
|
||||
tax_ids=[]
|
||||
pool_obj=pooler.get_pool(cr.dbname)
|
||||
|
||||
inv_create = 0
|
||||
inv_reject = 0
|
||||
inv_rej_reason = ""
|
||||
list_inv = []
|
||||
obj_event_reg=pool_obj.get('event.registration')
|
||||
data_event_reg=obj_event_reg.browse(cr,uid,data['ids'])
|
||||
obj_lines=pool_obj.get('account.invoice.line')
|
||||
|
||||
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 pool_obj.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=pool_obj.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_obj = pool_obj.get('account.invoice')
|
||||
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)
|
||||
|
||||
return {'inv_created' : str(inv_create) , 'inv_rejected' : str(inv_reject) , 'invoice_ids': list_inv, 'inv_rej_reason': inv_rej_reason}
|
||||
|
||||
class make_invoice(wizard.interface):
|
||||
|
||||
def _list_invoice(self, cr, uid, data, context):
|
||||
pool_obj = pooler.get_pool(cr.dbname)
|
||||
model_data_ids = pool_obj.get('ir.model.data').search(cr,uid,[('model','=','ir.ui.view'),('name','=','invoice_form')])
|
||||
resource_id = pool_obj.get('ir.model.data').read(cr,uid,model_data_ids,fields=['res_id'])[0]['res_id']
|
||||
return {
|
||||
'domain': "[('id','in', ["+','.join(map(str,data['form']['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'
|
||||
}
|
||||
|
||||
states = {
|
||||
'init' : {
|
||||
'actions' : [_makeInvoices],
|
||||
'result': {'type': 'form', 'arch': form, 'fields': fields, 'state':[('end','Ok'),('open','Open')]}
|
||||
},
|
||||
|
||||
'open': {
|
||||
'actions': [],
|
||||
'result': {'type':'action', 'action':_list_invoice, 'state':'end'}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
make_invoice("event.reg_make_invoice")
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
Reference in New Issue
Block a user