OpenERP 7 | Is there an on_submit like event and a way to figure out if there was a change on any of the form fields?

StackOverflow https://stackoverflow.com/questions/23126653

  •  05-07-2023
  •  | 
  •  

Pregunta

SCENARIO:

I've got my application which needs to do data synchronization with OpenERP. I am planning to achieve that by:

  • Creating a date-time field on the OpenERP models I need to get data synced.
  • Every time the OpenERP model gets updated, that date-time field value changes to the current date-time.
  • From my Application stand point, I will do a cron job in a given interval. I wont actually use cron jobs, for the sake of simplicity lets stick with cron jobs.
  • My Application will request a search for all entries that has the date-time field value greater than the last checking time.

QUESTIONS

  • Is there some kind of event that let me call my custom function upon a form submission?
  • From my function scope, when a model's entry is being edited, is it possible to find out if any of the form field values had been changed?
¿Fue útil?

Solución

The OpenERP ORM has a create and write method. You will need to override both as they both act as on_submit type methods but are called for new or existing records.

All you do is override one or both methods and call super to make sure the record is actually written then do whatever you want. You can also intercept the write and make changes. For a create the code would be:

def create (self, cr, uid, values, context = None):
    new_id = super(MyObject, self).create(cr, uid, values, context = context)
    # Do stuff here.  Can look in values dict to see what has changed
    return new_id

The write method is much the same except you also get the ids to be written.

OpenERP already has create and write dates but those are there for OpenERP auditing and locking and you should probably implement your own date/time marker. The easiest would be to make it a functional field and set store=True so it is recalculated and stored everytime the record is written

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top