Se rendre au contenu
Menu
Cette question a été signalée
4 Réponses
38450 Vues

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

},),

Avatar
Ignorer

<button name="credit_approve" type="object" string="Credit Approve" class="oe_highlight" attrs="{'invisible':['|','|','|','|',('credit_approved','=',True),('is_available','=',False),('credit_customer','=',False),('credit_customer','=',True)]}"/>

Meilleure réponse

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

Avatar
Ignorer
Meilleure réponse

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

Avatar
Ignorer
Meilleure réponse




Avatar
Ignorer
Auteur Meilleure réponse

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]]

Avatar
Ignorer

i edited my answer.Process it

Auteur

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

Publications associées Réponses Vues Activité
1
janv. 18
4837
1
avr. 24
2433
2
mars 23
10103
2
mars 23
2495
1
déc. 22
6754