Skip to Content
Menu
This question has been flagged

Hello, I hope you can help me.

I have a controller that receives notifications to convert it as a database table's register, then I search that registers by a field called "resource", if it exists I update it that record, if don't I create it the record.
The mean problem is that my controller can receive an specific resource many times at the same time when there is an update.
Another problem is in the system this notifications are processed also at the same time and not in line, this causes when I search by resource I don't find it and therefore I create the record several times if the notifications is received several times in parallel. I have a idea that consists in create a constraint to validate the uniqueness of the field "resource", but I want to know if there is a way to force the system to process this notifications in line, because I have a similar problem when I create an invoice and execute different methods, I hope to process the invoice creation and the proccess the sending information.


Example:

@http.route('/ml_notifications', type='json', auth='public', methods=['POST'], cors='*', csrf=False)
def ml_notifications(self):
..data_raw = request.jsonrequest
......

..notification = request.env['ml.notifications'].with_user(SUPERUSER_ID)
..data = self.process_raw(data_raw)
..notification_id = notification.search([('resource', '=', data_raw['resource'])])
..if notification_id:
notification_id.write(data)
..else:
    notification_id = notification.create(data)
......


I appreciate your help



Avatar
Discard
Related Posts Replies Views Activity
0
Aug 22
1420
2
Oct 19
6598
0
Mar 15
2431
2
Mar 15
3935
1
Feb 24
381