Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to override base module methods?

By
Pascal Tremblay
on 1/7/15, 5:43 AM 1,237 views

Hello all,

I try to override 2 or 3 methods of the file ../openerp/addons/base/ir/ir_attachment.py.

My goal is to change the name of the stored attachments files on the hard disk.

I already have other custom modules working. 

I have tried many combinaison, I have searched, but it doesn't work now.

__init__.py and __openerp__.py seems to be right since my own ir_attachment.py file is loaded.

My module depends on 'base' :

For the moment, I have this code in ../addons/mymodule/ir/ir_attachment.py : 

from openerp import models, fields

class PTir_attachment(base.ir_attachment):
    _inherit = 'base.ir_attachment'
    _name = 'base.ir_attachment'
    def _get_path(self, cr, uid):
        import pdb; pdb.set_trace()

I always get this error :

    import ir_attachment

  File "/home/odoo/addons/report_lapagept/ir/ir_attachment.py", line 4, in <module>

    class PTir_attachment(openerp.base.ir_attachment):

NameError: name 'openerp' is not defined

 

Could you help me please? I miss something...

 

1
Bruno PLANCHER
On 1/7/15, 5:46 AM

Hello Pascal,

You have 2 errors in your code:

First, ir_attachment is not mean to be 'Python inherited', you may use osv.osv instead of base.ir_attachment. you have to add this import  to use osv.osv synthax: 

from openerp.osv import osv # in V7.0 or greater versions

# from osv import osv # in V6.1 and lower versions

Then, when you define your model _name and _inherit attributes, you may put the original model name, in this case: 'ir.attachment'.

Hope it helps you,,Regards

It works! You are great! Thanks a lot.

Pascal Tremblay
on 1/7/15, 5:48 AM

glad to help you ^^ (i updated my answer to be more precise in osv.osv uses)

Bruno PLANCHER
on 1/7/15, 5:53 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/7/15, 5:43 AM
Seen: 1237 times
Last updated: 3/16/15, 8:10 AM