In odoo 12 i have created a custom module and added a archive button in the form view. The module has a time field in it. My question is how to automatically archive an object when time of that time field is over. Thank you
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
2
Replies
5046
Views
Hi!
I suggest you to create automated actions ir.cron, schedulers are automated actions that run automatically over a time period and can do a lot of things. They give the ability to execute actions database without needing manual interaction. Odoo makes running a background job easy.
Bellow, an example, adapt it as you need:
<record model="ir.cron" id="check_birthday_cron">
<field name="name">Check Birthday</field>
<field name="model_id" ref="model_my_model"/>
<field name="state">code</field>
<field name="code">model.check_birthday()</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
</record>
class MyModel(models.Model):
_name = 'my.model'
_description = _("My Model")
_order = 'date desc'
@api.model
def check_birthday(self):
partner_ids = self.env['res.partner'].search([('is_member', '=', True)]).filtered(
lambda x: x.birthday.day == fields.Date.today().day and x.birthday.month == fields.Date.today().month)
for partner_id in partner_ids:
partner_id.active = False
Best regards!
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up
Use Automated Action: http://learnopenerp.blogspot.com/2020/05/how-to-create-scheduled-action-in-odoo.html