Hello, i would like to know how to apply updates in a custom field once at the end of every month?
thanks in advance.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Hello, i would like to know how to apply updates in a custom field once at the end of every month?
thanks in advance.
Hi,
You could do this through a server action or an automated action. An example:
<?xml version="1.0"?> <odoo> <data noupdate="1"> <!-- Scheduler for updating field once a month --> <record forcecreate="True" id="ir_cron_custom_monthly_update" model="ir.cron"> <field name="name">Custom: update own field on monthly basis</field> <field name="model_id" ref="model_your_model"/> <field name="state">code</field> <field name="code">model.update_records()</field> <field eval="True" name="active"/> <field name="user_id" ref="base.user_root"/> <field name="interval_number">1</field> <field name="interval_type">months</field> <field name="numbercall">-1</field> <field eval="False" name="doall" /> </record> </data> </odoo>
Then write a Python function that binds to this scheduler and executes the code you'd like:
@api.model def update_records(self): records = self.env['your.model'].search([]) for record in record:
record.write({'your_field': 'new_value'})
Regards,
Yenthe
Thank you so much guys for your help
Hello Mazen,
use write method on your model
@api.multi
def write(self, vals):
if vals.get('your custom field', false):
##here you can update some other log table or do your logic
return super(your calss name, self).write(vals)
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up
please explain in detail what you want to update.