Skip to Content
Menu
This question has been flagged
3 Replies
4081 Views

Hello every one. Please, can someone helps me ? i created automate actions based on time condition which is at the next date of preventive maintenance. This automate actions is permit to create a record. But it seems that, this automate actions not worked at this specifically date. so i want to put a domain in order to works at the next date of preventive maintenance which is will be compared to the today date. How do i handle this ? Please.

i make this in domain [["next_action_date","=",context_today()]] but i got error

Avatar
Discard
Best Answer

Hi,

First of all: we cannot provide the domain like you have given.
Currently, It is not possible to set a dynamic domain for the date field in the domain filter.
But, It doesn't matter. You can do it easily with the python code.
If you need to create the maintenance request for the equipments by just comparing the Date of the next preventive maintenance(next_action_date) with current date, you can do it using a scheduled action with code given below(Model: maintenance.equipment, Execute Every: 1 Days):

utc_date_now = datetime.datetime.now()
user_date_now = utc_date_now.astimezone(timezone(user.tz)).date()
equipments_for_maintenance = model.sudo().search([('next_action_date', '=', user_date_now)])
for equipment in equipments_for_maintenance:
env['maintenance.request'].create({
'name': 'Preventive Maintenance - ' + equipment.name,
'equipment_id': equipment.id,
'maintenance_type': 'preventive',
'request_date': equipment.next_action_date,
'schedule_date': equipment.next_action_date,
'duration': record.maintenance_duration
# add the values to the fields in 'maintenance.request'
})

If you need to do the same when we create/ update the Date of the next preventive maintenance(next_action_date), you can create an automated action with the code given below(Model: maintenance.equipment, Trigger: On Creation & Update, Trigger Fields: Date of the next preventive maintenance, Before Update Domain: [], Apply on: [], Action To Do: Execute Python Code):

utc_date_now = datetime.datetime.now()
user_date_now = utc_date_now.astimezone(timezone(user.tz)).date()
if records:
for record in records:
if record.next_action_date == user_date_now:
env['maintenance.request'].create({
'name': 'Preventive Maintenance - ' + record.name,
'equipment_id': record.id,
'maintenance_type': 'preventive',
'request_date': record.next_action_date,
'schedule_date': record.next_action_date,
'duration': record.maintenance_duration
# add the values to the fields in 'maintenance.request'
})





Regards

Avatar
Discard
Author

Thanks a lot . I realy appreciate. But in m'y case , i create automate action whish create request maintenance at the date of thé next préventive maintenance because Odoo generates New request maintenance all Times. So i don't understand the reason. If u Can explain to me, the scheduled action of Odoo on the preventive request maintenance whish is implanted on the System by défault. Thanks very much

The function _cron_generate_requests() is used with the scheduled action(Maintenance: generate preventive maintenance requests) in which the equipments are searched with the domain [('period', '>', 0)]. Then for those equipments, Odoo checks existing maintenance requests, where the maintenance type is 'Preventive', the request is created for the given equipment, the stage of request is not a completed stage, and the request date is the Date of the next preventive maintenance of the equipment. If there is no existing maintenance request, a new one is created using the method: _create_new_request(equipment.next_action_date).
That is, the default scheduled action of Odoo creates maintenance requests for all the maintenance equipment where the Preventive Maintenance Frequency or Days between each preventive maintenance(period) is greater than 0. It doesn't compare the Date of the next preventive maintenance with the current date.
Note: If you are adding the scheduled action or the automated action given here(don't add both), please disable the default one.

Author

Thanks a lot ! i really appreciate ur assistance. It is now, very clear !

Author Best Answer

See.


Avatar
Discard
Best Answer

Hey, 

You can try this one,

[('next_action_date','=',fields.Date.today())]

Avatar
Discard
Author

Thanks for ur support. but its not worked. I use Odoo online so i have to make a domain by interface user.
I'll share u pic. Thanks

Related Posts Replies Views Activity
2
May 21
4781
2
Nov 24
262
1
Oct 24
327
4
Oct 24
321
2
Oct 24
358