Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
38455 Lượt xem

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

},),

Ảnh đại diện
Huỷ bỏ

<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)]}"/>

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất




Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ

i edited my answer.Process it

Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 1 18
4837
1
thg 4 24
2434
2
thg 3 23
10104
2
thg 3 23
2495
1
thg 12 22
6754