Whow to overrride a méthod in Openerp

Asked by EL HADJ MIMOUNE Mourad

Hi everybody,

I want override a method price_get of the pricelist class to custom price computing.
So I make this by inheritance (see code below). The problem is still the original method that is triggered!

What's wrong ?

class product_pricelist(osv.osv):
    _name = 'product.pricelist'
    _inherit = 'product.pricelist'

    def price_get(self, cr, uid, ids, prod_id, qty, partner=None, context=None):
        re = super(product_pricelist, self).price_get(cr, uid, ids, prod_id, qty, partner, context)
        res_multi = self.price_get_multi(cr, uid, pricelist_ids=ids, products_by_qty_by_partner=[(prod_id, qty, partner)], context=context)
        res = res_multi[prod_id]
        res.update({'item_id': {ids[-1]: ids[-1]}})
        return res

Thank you for your help

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Addons (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
EL HADJ MIMOUNE Mourad
Solved:
Last query:
Last reply:
Revision history for this message
James Jesudason (jamesj) said :
#1

Make sure you have added your custom python to the __init__.py file, and also that you have instantiated the class:

class product_pricelist(osv.osv):
     <snip>
     ...
     </snip>

product_pricelist() # this instantiates the class

Revision history for this message
Nhomar - Vauxoo (nhomar) said :
#2

HEllo.

If you use:

_name = 'product.pricelist'

You are creating a new model that overriveenterally the old one, don't use this and you will override JUST the method.

Revision history for this message
EL HADJ MIMOUNE Mourad (melhadjmimoune) said :
#3

Thank's for your response.

in the __init__ I have set
import product_pricelist_test (which is the name of the python file)

And class product_pricelist() are still initializied.

I delete the line _name = 'product.pricelist' but no thing changed.
I searched for many time without find a solution.

All suggestion are welocome

Revision history for this message
OpenBMS JSC (openbmsjsc) said :
#4

Did you restart the server? I've found that when you modify .py files, you will need to delete the .pyc and restart the server, so that the old classes are not cached in memory.

Revision history for this message
Nhomar - Vauxoo (nhomar) said :
#5

2011/10/4 OpenBMS JSC <email address hidden>

> Question #173072 on OpenERP Addons changed:
> https://answers.launchpad.net/openobject-addons/+question/173072
>
> Status: Open => Answered
>
> OpenBMS JSC proposed the following answer:
> Did you restart the server? I've found that when you modify .py files,
> you will need to delete the .pyc and restart the server,

You just need to restart, the pyc almost always regenerate.

> so that the old
> classes are not cached in memory.
>
> --
> You received this question notification because you are a member of
> OpenERP Committers, which is an answer contact for OpenERP Addons.
>

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

Nhomar G. Hernandez M.
+58-414-4110269
Skype: nhomar00
Web-Blog: http://geronimo.com.ve
Servicios IT: http://openerp.com.ve
Linux-Counter: 467724
Correos:
<email address hidden>
<email address hidden>
twitter @nhomar

Revision history for this message
EL HADJ MIMOUNE Mourad (melhadjmimoune) said :
#6

Hello,
Thanks for your responses.
I resolved my problem with deleting the line:
 re = super(product_pricelist, self).price_get(cr, uid, ids, prod_id, qty, partner, context)
and with adding Link to my module folder.
In fact, when I run openerp-server from Eclipse (debug mode), it use de folder bin/addons.
For updating module I used --addons-path=... option. So module was installed but not used.

To make link
cd server/bin/addons
ln -s ../../../addons/* .

Best regards