This is my code---
I want to visible this button based on payment method(journal_id) from Supplier Payment like If it is a Cash then ,this button should visible,otherwise(if its a bank not visible this button ),How Its Possible,need a help...
====================================================================================================
from osv import osv,fields
from openerp.tools.translate import _
class customer_payments(osv.osv):
_inherit='account.voucher'
def _amount_all(self, cr, uid, ids, name, args, context=None):
res = {}
for invoice in self.browse(cr, uid, ids, context=context):
res[invoice.id] = {
'amount_total': 0.0
}
for line in invoice.line_dr_ids:
res[invoice.id]['amount_total'] += line.amount
return res
def cash_payment_popup(self, cr, uid, ids, context=None):
if not ids: return []
dummy, view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid,'customer_payments', 'customer_payment_wizard_form_view')
inv = self.browse(cr, uid, ids[0], context=context)
return {
'name':_("Customer Payments"),
'view_mode': 'form',
'view_id': view_id,
'view_type': 'form',
'res_model': 'customer.payment.wizard',
'type': 'ir.actions.act_window',
'nodestroy': True,
'target': 'new',
'domain': '[]',
'context': {
'default_supplier_name': self.pool.get('res.partner')._find_accounting_partner(inv.partner_id).id,
'default_amount': inv.amount_total,
'default_date': inv.date,
# 'default_currency': self.pool.get('account.invoice')._get_currency(inv.currency_id).id,
# 'default_company_name': self.pool.get('res.partner')._find_accounting_partner(inv.company_id).id,
'default_cash_payment_order_no':inv.reference,
'default_document': inv.document,
'default_date_location': inv.date_location,
'default_purpose': inv.purpose,
'default_enclosure': inv.enclosure,
# 'default_amount_words':inv.amount_words,
# 'default_accounts':inv.ren_period,
}
}
customer_payments()
==============================================================================
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="supplier_payment_inherited" model="ir.ui.view">
<field name="name">supplier.payment.view.form</field>
<field name="model">account.voucher</field>
<field name="type">form</field>
<field name="inherit_id" ref="account_voucher.view_vendor_payment_form"/>
<field name="arch" type="xml">
<xpath expr="/form/sheet/field[3]" position="after">
<button name="cash_payment_popup" string="Cash Payment Order" type="object" class="oe_right oe_highlight"/>
</xpath>
<xpath expr="/form/sheet/group/group[1]/field[4]" position="after">
<field name="date_location"/>
<field name="enclosure"/>
</xpath>
<xpath expr="/form/sheet/group/group[2]/field[4]" position="after">
<field name="document"/>
<field name="purpose"/>
</xpath>
</field>
</record>
</data>
</openerp>
It may be resolved by additional boolean field and onchange method of journal_id. for complete solution please refer to my answer below.