[Openerp-community] Print a string for EVERY write

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[Openerp-community] Print a string for EVERY write

Francesco Apruzzese
Hi all,

I need to print a string for EVERY write in OpenERP 7. I'm trying to
inherit BaseModel to super the "write" function but this isn't the right
way (I think).

Can anyone help me?

_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] Print a string for EVERY write

Leonardo Pistone - camptocamp
Hi,

as for BaseModel, why not? Does it work?

A module that comes to mind that changes CRUD on all models is
audittrail (removed in v8). Maybe you could give a look?

Also, maybe you could check the code that logs for level debug_rpc.
That should be run for all writes (and more).

On Tue, Oct 14, 2014 at 12:01 PM, Francesco Apruzzese <[hidden email]> wrote:
> Hi all,
>
> I need to print a string for EVERY write in OpenERP 7. I'm trying to inherit
> BaseModel to super the "write" function but this isn't the right way (I
> think).

_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] Print a string for EVERY write

Nhomar Hernández
In reply to this post by Francesco Apruzzese

2014-10-14 5:31 GMT-04:30 Francesco Apruzzese <[hidden email]>:
I need to print a string for EVERY write in OpenERP 7. I'm trying to inherit BaseModel to super the "write" function but this isn't the right way (I think).

did you check the _track attribute? 

It does exactly what you are looking for.

For the change of status.


For the field: (check the track_visibility attribute in declaration of the field).

https://github.com/odoo/odoo/blob/8.0/addons/sale/sale.py#L222

It will send a message related to the model.

I really should like if this behavior return an "Auditable information" and not an "ugly html" but that the new approach, it do the job at the end.

regards.

--
--------------------
Saludos Cordiales
 
 

_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] Print a string for EVERY write

Francesco Apruzzese
In reply to this post by Francesco Apruzzese
Il 14/10/2014 12:24, [hidden email] ha scritto:

Thank you! This is what i'm searching!

> Hi,
>
>     You can use the functionality used at Connector module available
> at OCA(https://github.com/OCA/connector/blob/7.0/connector/producer.py)
>
> from openerp.osv import orm
> write_original = orm.BaseModel.write
> def write(self, cr, uid, ids, vals, context=None):
>     print "Your custom statement"
>     # Create a logger entry here
>     result = write_original(self, cr, uid, ids, vals, context=context)
>     return result
> orm.BaseModel.write = write
>
> Add this python code in your module, then for every WRITE function,
> your custom string will be printed to your console.
>


_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] Print a string for EVERY write

Oscar Alca
that is really tricky thing to do, "Monkey Patch" is not a very good way to go, you should try to inheriting BaseModel as Leonardo says, also, if you want to keep track of the prints in the log file you wont be able to audit them, try logger instead.

On Tue, Oct 14, 2014 at 8:38 AM, Francesco Apruzzese <[hidden email]> wrote:
Il 14/10/2014 12:24, [hidden email] ha scritto:

Thank you! This is what i'm searching!

Hi,

    You can use the functionality used at Connector module available at OCA(https://github.com/OCA/connector/blob/7.0/connector/producer.py)

from openerp.osv import orm
write_original = orm.BaseModel.write
def write(self, cr, uid, ids, vals, context=None):
    print "Your custom statement"
    # Create a logger entry here
    result = write_original(self, cr, uid, ids, vals, context=context)
    return result
orm.BaseModel.write = write

Add this python code in your module, then for every WRITE function, your custom string will be printed to your console.



_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp



--


   

Ing. Oscar Alcalá Rivera
312-107-1704 · [hidden email]

Vauxoo SA
Tlf: 3123111122

Open Source Enthusiast

LinuxCounter:566085

   twitter linkedIn   Google+  

eco No me imprimas si no es necesario. Protejamos el medio ambiente


_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp