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

Where should I save a model wich inherits from another for adding fields?

By
Iván
on 4/15/14, 6:09 PM 1,067 views

Hi there,

My doubt is the following:

I want to add fields to the resource.resource model, so , as I learnt, I have to inherit from resource with the parameters set as below:

_name = 'resource.resource'

_inherit = 'resource.resource'

Then add the fields I want in the _columns parameter.

Until here everything is ok, but then I have some issues I don't know how to solve:

  • Where should I write the new class? Inside resource.py? or should I write a new .py (for example: resource2.py)

  • If I should write a new .py, where should I save it? Inside the resource folder? or in a custom folder? and besides, do I need some imports?

Any other recommendations are welcomed.

Thanks in advance

Code:

class resource_resource(osv.Model):
_name = 'resource.resource'
_inherit = 'resource.resource'
_columns = {
    'name' : fields.function(_get_full_name, type='text', 'Full Name'),
    'x_name' : fields.text('Name'),
    'x_sname' : fields.text('Surname'),
}
def _get_full_name(self,cr,uid,ids,field,arg,context=None):
    aResource = self.browse(cr,uid,ids)
    return (aResource.x_name + ' ' + aResource.x_sname)

Openerp version: 7

Can u paste your code ?

Jagdish Panchal
on 4/16/14, 3:52 AM

Hi, I will edit my post with the code though my question is not about the code itself but more related to where should I put it.

Iván
on 4/16/14, 1:08 PM
3

Dhinesh - Technical Consultant, Sodexis Inc

--Dhinesh - Technical Consultant, Sodexis Inc--
3577
| 5 4 9
Pondicherry, India
--Dhinesh - Technical Consultant, Sodexis Inc--

Passionate coder in Python/OpenERP. Knows Django/Flask MVC frameworks. Did code in Java, PHP.

Contact me at: dvdhinesh.mail@gmail.com

Dhinesh - Technical Consultant, Sodexis Inc
On 4/16/14, 11:34 AM

Hi, You can write in the same py file by creating different class. But its always good to write in new py file which is separated from the base module. Because when performing upgrade there is a chance that your code get deleted.

Thanks for the answer, I would like to create a new .py, Would it be ok if I locate it in a Resource-Custom folder created by myself? Shouldn't I make some imports?

Iván
on 4/16/14, 1:13 PM

You can create a custom module and add the extra fields in the py file of inherited class. Write the _view.xml file only for the field you have newly created and give the ref as <field name="inherit_id" ref="object.yourview" />

Dhinesh - Technical Consultant, Sodexis Inc
on 4/17/14, 2:52 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: 4/15/14, 6:09 PM
Seen: 1067 times
Last updated: 3/16/15, 8:10 AM