Tek Siong, Hock

Mar 1, 20221 min

Odoo - Server Action on Multiple Records

If you have a requirement to perform certain action on multiple records with a single click, eg, approve multiple payments, then you may consider using the server action.

Select and click "Approve" to approve the multiple vendor payments.

Add the server action "ir.actions.server" model in the xml view, to call action_vendor_payment_approve method in the account.payment class.

<record model="ir.actions.server" id="action_vendor_payment_approve">
 
<field name="name">Approve</field>
 
<field name="model_id" ref="account.model_account_payment"/>
 
<field name="binding_model_id" ref="account.model_account_payment" />
 
<field name="state">code</field>
 
<field name="code">
 
if records:
 
action = records.action_vendor_payment_approve()
 
</field>
 
</record>

@api.multi
 
def action_vendor_payment_approve(self):
 
for payment in self:
 
payment.write({'state': 'draft'})
 
payment.approve_by = self.env.user.id
 
payment.approve_date_time = datetime.now()
 
payment.post()

    1810
    0