Python
from openerp import models, fields, api
from openerp.tools.translate import _
import openerp.addons.decimal_precision as dp
from datetime import datetime
class od_cancellation_wizard(models.TransientModel):
_name = 'od.cancellation.wizard'
_description = 'Cancellation Wizard'
reason = fields.Text(string='Reason',required="1")
active_id = fields.Char(string='Form ID')
active_model = fields.Char(string='Model')
state = fields.Char('State')
def default_get(self, cr, uid, fields, context=None):
res = super(od_cancellation_wizard, self).default_get(cr, uid, fields, context=context)
active_id = context.get('active_ids', [])
state = ''
active_model = context.get('active_model')
if active_model == 'sale.order':
state = self.pool.get('sale.order').browse(cr,uid,active_id,context).state
res.update({'active_id': active_id,'active_model':active_model,'state':state})
elif active_model == 'purchase.order':
state = self.pool.get('purchase.order').browse(cr,uid,active_id,context).state
res.update({'active_id': active_id,'active_model':active_model,'state':state})
elif active_model == 'stock.picking':
state = self.pool.get('stock.picking').browse(cr,uid,active_id,context).state
res.update({'active_id': active_id,'active_model':active_model,'state':state})
elif active_model == 'account.invoice':
state = self.pool.get('account.invoice').browse(cr,uid,active_id,context).state
res.update({'active_id': active_id,'active_model':active_model,'state':state})
elif active_model == 'account.voucher':
state = self.pool.get('account.voucher').browse(cr,uid,active_id,context).state
res.update({'active_id': active_id,'active_model':active_model,'state':state})
return res
def cancel(self, cr, uid, ids, context=None):
obj = self.browse(cr,uid,ids,context)
active_id = int(obj.active_id)
active_model = obj.active_model
reason = obj.reason
if active_model == 'sale.order':
self.pool.get('sale.order').write(cr,uid,[active_id],{'state':'cancel','od_cancel_reason':reason},context)
elif active_model == 'purchase.order':
self.pool.get('purchase.order').action_cancel(cr,uid,[active_id],context)
self.pool.get('purchase.order').write(cr,uid,[active_id],{'od_cancel_reason':reason},context)
elif active_model == 'stock.picking':
self.pool.get('stock.picking').action_cancel(cr,uid,[active_id],context)
self.pool.get('stock.picking').write(cr,uid,[active_id],{'od_cancel_reason':reason},context)
elif active_model == 'account.voucher':
self.pool.get('account.voucher').cancel_voucher(cr,uid,[active_id],context)
self.pool.get('account.voucher').write(cr,uid,[active_id],{'od_cancel_reason':reason},context)
return True
def cancel_confirmed(self, cr, uid, ids, context=None):
obj = self.browse(cr,uid,ids,context)
active_id = int(obj.active_id)
active_model = obj.active_model
reason = obj.reason
if active_model == 'purchase.order':
self.pool.get('purchase.order').action_cancel(cr,uid,[active_id],context)
self.pool.get('purchase.order').write(cr,uid,[active_id],{'od_cancel_reason':reason},context)
elif active_model == 'stock.picking':
self.pool.get('stock.picking').action_cancel(cr,uid,[active_id],context)
self.pool.get('stock.picking').write(cr,uid,[active_id],{'od_cancel_reason':reason},context)
elif active_model == 'sale.order':
self.pool.get('sale.order').action_cancel(cr, uid, [active_id], context)
self.pool.get('sale.order').write(cr,uid,[active_id],{'od_cancel_reason':reason},context)
elif active_model == 'account.voucher':
self.pool.get('account.voucher').cancel_voucher(cr,uid,[active_id],context)
self.pool.get('account.voucher').write(cr,uid,[active_id],{'od_cancel_reason':reason},context)
return True
@api.multi
def action_cancel_for_invoice(self):
active_id = int(self.active_id)
reason= self.reason
acco = self.env['account.invoice'].browse(active_id)
acco.action_cancel()
acco.write({'od_cancel_reason': reason})
return True
XML
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="od_view_cancellation_wizard_form" model="ir.ui.view">
<field name="name">Cancellation Reason</field>
<field name="model">od.cancellation.wizard</field>
<field name="arch" type="xml">
<form string="Transfer details" >
<p style="color:blue;font-size:10pt;">
Enter the cancellation reason for this document.
</p>
<group>
<field name="reason" nolabel="1" placeholder="Type Here...."/>
<field name="active_id" invisible="1"/>
<field name="active_model" invisible="1"/>
<field name="state" invisible="1"/>
</group>
<footer>
<p style="color:red;font-size:10pt;">
Are you sure you want to cancel this document?
<button name="cancel" string="Yes" type="object" attrs="{'invisible': ['|',('state', '!=', 'draft'),('active_model', '=', 'account.invoice')]}" class="oe_link"/>
<button name="cancel_confirmed" string="Yes" type="object" class="oe_link" attrs="{'invisible': ['|',('state', '=', 'draft'),('active_model', '=', 'account.invoice')]}" />
<button name="action_cancel_for_invoice" string="Yes" type="object" attrs="{'invisible': [('active_model','!=','account.invoice')]}" class="oe_link"/>
or
<button string="No" class="oe_link" special="cancel"/>
</p>
</footer>
</form>
</field>
</record>
<record id="action_od_view_cancellation_wizard" model="ir.actions.act_window">
<field name="name">Cancellation Reason</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">od.cancellation.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="od_view_cancellation_wizard_form"/>
<field name="target">new</field>
</record>
</data>
</openerp>
Button
<button name="%(action_od_view_cancellation_wizard)d" states="manual,progress" string="Cancel Order" type="action" groups="base.group_user"/>
def action_add(self, cr, uid, ids, context=None):
context['mo_id'] = ids[0]
return {
'name': _('Product Enquiry'),
'view_type': 'form',
'view_mode': 'form',
'res_model': 'od.product.enquiry',
'context':context,
'target': 'new',
'type': 'ir.actions.act_window',
}
<button name="action_add" string="Consumption" icon="STOCK_ADD" type="object"/>