I'm adding a new server action to my Odoo, but is not working ok. It's supposed to check the n selected items, but only is checking the first one. What I'm missing?
XML
<record id="action_server_validate" model="ir.actions.server">
<field name="name">Validate / Unvalidate</field>
<field name="type">ir.actions.server</field>
<field name="model_id" ref="model_account_voucher"/>
<field name="binding_model_id" ref="model_account_voucher"/>
<field name="state">code</field>
<field name="code">
for obj in object:
obj.validate_invalidate()
</field>
</record>
Python
class AccountVoucher(models.Model):
_inherit = 'account.voucher'
validated = fields.Boolean('Validated', default=False)
payment_mode_id = fields.Many2one(related='payment_line_ids.payment_mode_id')
@api.multi
def validate_invalidate(self):
for rec in self:
if not rec.validated:
rec.validated = True
else:
rec.validated = False
object
is a record on which the action is triggered if there is one, otherwise None (In your example above it should be the last item)
You probably couldn't use records
because of the following error:
ValueError: "name 'records' is not defined
The available locals are:
To call the function on all selected records, you can pass active_ids
to the validate_invalidate
function like the following :
self.validate_invalidate(cr, uid, context.get('active_ids', []), context=context)
Or:
model.browse(context.get('active_ids', [])).validate_invalidate()