Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


How to visible a button based on payement_method(journal_id) from supplier Payment in Accounting For a Custom Module?.

on 9/30/14, 1:28 AM 933 views

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):

    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_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,



<?xml version="1.0" encoding="utf-8"?>
            <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 expr="/form/sheet/group/group[1]/field[4]" position="after">
                        <field name="date_location"/>
                        <field name="enclosure"/>
                    <xpath expr="/form/sheet/group/group[2]/field[4]" position="after">
                        <field name="document"/>
                        <field name="purpose"/>



It may be resolved by additional boolean field and onchange method of journal_id. for complete solution please refer to my answer below.

on 9/30/14, 10:06 AM


| 6 5 7
Tbilisi, Georgia
On 9/30/14, 9:53 AM


Try following changes:

# .PY========


class customer_payments(osv.osv):

    _columns = {
            'cash_payment_popup_visible': fields.boolean('Cash Popup Visible'),
    _defaults = {
            'cash_payment_popup_visible': False,

    def onchange_journal(self, cr, uid, ids, journal_id, line_ids, tax_id, partner_id, date, amount, ttype, company_id, context=None):
        res = super(customer_payments, self).onchange_journal(cr, uid, ids, journal_id, line_ids, tax_id, partner_id, date, amount, ttype, company_id, context)
        if res and journal_id:
            account_journal_obj = self.pool.get('account.journal').browse(cr,uid,journal_id, context)
            if account_journal_obj.type == 'cash':
                res['value']['cash_payment_popup_visible'] = True
        elif not res:
            res = {'value':{}}
        res['value']['cash_payment_popup_visible'] = res['value'].get('cash_payment_popup_visible', False)
        return res

    def _amount_all(self, cr, uid, ids, name, args, context=None):
        res = {}


# .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" attrs="{'invisible':[('cash_payment_popup_visible','=',False)]}" />
    <field name="cash_payment_popup_visible"  invisible="1" />




Thanks Temur... will chk

on 9/30/14, 11:20 AM

If it worked for you, please mark this answer as accepted.

on 10/1/14, 2:58 AM

Ludo - Neobis

--Ludo - Neobis--
| 2 2 5
Hoogvliet, Netherlands
--Ludo - Neobis--


Ludo - Neobis
On 9/30/14, 3:21 AM

What have you tried to make it invisible? 

Have you tried using the "attrs" tag in the XML code?

How to write XML for this in journal_id .(if its a cash then the button visible),How to write .I tried but effect

on 9/30/14, 5:05 AM

If journal_id is cash(from supplier payement ) then only my custom button(cash_payment_popup) should visible

on 9/30/14, 5:06 AM

Did you check the original source for attrs in xml? If so, post you code in the original question and someone will check what was wrong with it.

Ludo - Neobis
on 9/30/14, 6:02 AM

Yes I Checked,It resolved Thx Ludo..4 rply

on 9/30/14, 11:43 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)


Asked: 9/30/14, 1:28 AM
Seen: 933 times
Last updated: 3/16/15, 8:10 AM