Odoo Help

Welcome!

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.

0

How to make buttons invisible based on a condition

By
Arjun Khode
on 3/19/15, 1:57 AM 2,926 views

I have two buttons in a view. I want to add a third button called 'Mark as done'. Pressing this button should make the other two buttons invisible or greyed out. And the 'Mark as done' button itself should also become invisible

How to add the conditions for this?

Here is my code:

XML:

BUTTON ACTIONS:

<record id="register_payment_button_action" model="ir.actions.act_window">

<field name="name">Register Payment</field>

<field name="res_model">account.voucher</field>

<field name="view_type">form</field>

<field name="view_mode">form</field>

<field name="domain">[('journal_id.type', 'in', ['bank', 'cash']), ('type','=','receipt')]</field>

<field name="context">{'type':'receipt'}</field>

<field name="view_id" ref="account_voucher.view_vendor_receipt_form"/>

<!-- <field name="view_id" ref="account_voucher.view_vendor_receipt_dialog_form"/> -->

<field name="target">new</field>

</record>

<record id="pay_investor_button_action" model="ir.actions.act_window">

<field name="name">Pay Investor</field>

<field name="res_model">account.voucher</field>

<field name="view_type">form</field>

<field name="view_mode">form</field>

<field name="domain">[('journal_id.type', 'out', ['bank', 'cash']), ('type','=','receipt')]</field>

<field name="context">{'type':'receipt'}</field>

<field name="view_id" ref="account_voucher.view_vendor_receipt_form"/>

<field name="target">new</field>

</record>

BUTTONS:

<record id="record_form_view" model="ir.ui.view">

<field name="name">record.form.view</field>

<field name="view_type">form</field>

<field name="model">record</field>

<field name="arch" type="xml">

<form string="Record">

<group>

<field name="investment_id"/>

<field name="investor_id" domain="[('is_investor','=',True)]"/>

<field name="start_date"/>

<!-- <field name="end_date"/> -->

<field name="roi"/>

<field name="amount"/>

<field name="returns"/>

<!-- <button name="action_compute_returns" string="Compute Returns" type="object"/> -->

<button name="%(register_payment_button_action)d" context="{'default_amount': amount,'default_partner_id': investor_id'}" string="Register Payment" type="action"/>

<button name="%(pay_investor_button_action)d" context="{'default_amount': (returns * -1),'default_partner_id': investor_id'}" string="Pay Investor" type="action"/>

<!-- mark as done button code goes here -->

</group>

</form>

</field>

</record>

PYTHON:

_columns={

'investment_id':fields.many2one('investment.model','Name of Investment'),

'investor_id':fields.many2one('res.partner','Investor Name'),

'start_date':fields.date('Start Date'),

#'end_date':fields.date('End Date'),

'amount':fields.float('Amount Invested'),

#'status_paid':fields.boolean('Total Amount Paid'),

#'status_returned':fields.boolean('Total Amount Returned'),

'done':fields.boolean('Mark As Done',invisible=True),

'roi':fields.float('Rate of Interest in fraction'),

'monthly_interest':fields.float('Cumulative Monthly Interest'),

'returns':fields.function(_amount_returns, digits_compute=dp.get_precision('Account'), string='Amount to be returned',

store={

'record': (lambda self, cr, uid, ids, c={}: ids, ['amount', 'roi'], 10),

},),

2

Vasanth

--Vasanth--
3458
| 5 3 8
Pondicherry, India
--Vasanth--
Vasanth
On 3/19/15, 2:28 AM

hi,

you can do this in xml view:

<button name="%(register_payment_button_action)d" attrs="{'invisible':[('done','=',True)]}" context="{'default_amount': amount,'default_partner_id': investor_id'}" string="Register Payment" type="action"/>

<button name="%(pay_investor_button_action)d" attrs="{'invisible':[('done','=',True)]}" context="{'default_amount': (returns * -1),'default_partner_id': investor_id'}" string="Pay Investor" type="action"/>

<button name="mark_as_done" string="Mark as Done" type="object"/>

In py:

    def mark_as_done(self, cr, uid, ids, context=None):
        for record in self.browse(cr, uid, ids, context):
            if record:
                self.write(cr, uid, ids, {'done': True}, context=context)
        return True

0
soso
On 9/8/15, 2:34 AM

i have done this  by stages, so write  the stages u need, and atach each button to each stage or howeever  u wish, have a big  choice, and dot the changes in  xlm attrs, and in py  like this:


try to change attrs="{'invisible':[('done','=',True)]}  in this   attrs="{'invisible':[('state','=',done)]} 

and in py:  change {'done': True}  with  "stage':done,  depends how  you will write rest the script

hope it will help

0
Arjun Khode
On 3/19/15, 2:54 AM

Hi Vasanth, my py is showing "undefined variable wizard'.

What do I need to import to get rid of it?

and I'm getting this error:

Error: Unknown field done in domain [["done","=",true]]

i edited my answer.Process it

Vasanth
on 3/20/15, 2:39 AM

I'm still getting this error despite trying the updated code: Error: Unknown field done in domain [["done","=",true]]

Arjun Khode
on 3/22/15, 6:19 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

1 follower(s)

Stats

Asked: 3/19/15, 1:57 AM
Seen: 2926 times
Last updated: 9/8/15, 2:34 AM