1
votes

Is there any way to get the list of deleted records in OpenERP? I have heard that openerp records the deleted record list.. but i don't know where to browse for it..

I'm trying to synchronize two databases. So I hardly require the deleted record's model name and id so that i can delete the corresponding record from the other database

4

4 Answers

2
votes

You can make something like a replication_automated_rule based on the base_action_rule model. Look for the code at addons/base_action_rule/base_action_rule.py.

An action rule links server actions to objects (of a given model) that accomplish a given condition (defined by filters). Action rules are very easy to use, even on the administrative interface.

The objects are checked on creation and update but you can inherit from base_action_rule and define the check on delete also. It works by mean of creating custom wrappers to the create and write methods for the memory representation of the model object over it is told to work. You would need to add an _wrap_unlink method based on _wrap_create and adds a line to _register_hook:

model_obj.unlink = self._wrap_unlink(model_obj.unlink, model)

The wrapper method inside _wrap_create and _wrap_update execute the hooks after execute its normal function. When you define the wrapper method inside your _wrap_unlink, you should be care of executing the hooks before the normal function of unlink, given that unlink erase the object and it would not be available for the hooks.

Also, you should define an server action which saves the necessary data for your replication queue or log.

Good luck !!

1
votes

I got the answer.

I inherited the class object_proxy from osv.osv and inside this there is a function named execute,def execute(self, db, uid, model, method, *args, **kw): I just override this function, if the method is unlink then i saved that record_id and model name to a new table in the database

1
votes

When you click Delete from UI in openerp you have access to ORM Menthod UNLINK prototype od method is :

def unlink(self, cr, uid, ids, context=None)
    """
    #Delete records with given ids
    Param cr:  database cursor
    Param uid: current user id
    Param ids: id or list of ids
    Param context:   (optional) context arguments, like lang, time zone
    Return : True
    Raise AccessError:
        if user has no unlink rights on the requested object
        if user tries to bypass access rules for unlink on the requested object
    Raise UserError:

        if the record is default property for other records
    """

Here Ids contains the list of ids to be unlinked so before deleting you can play with them.

But If record are once deleted from OpenERP, you can not have access as they are no more in db.

Optional, mechanism here can be useful is active field. Active field in OE is special field if you define active Boolean field on your model then if any record set to active false, yo can not see that record on view without special efforts, But Tricky part is you still have those record on table with active=False so you can access them very easily using domain.

0
votes

I think jam's suggestion is that you override the unlink() method on any models you want to replicate, and log the deleted ids into a separate table. Then your synchronization process can read and purge that table.

You might also look into replication tools at the database level if you just want to duplicate the entire database.