This question has been flagged
2 Replies
7533 Views

hi, I am facing issues related to creating views in inherited objects. I am planning to add a dealer module. Here is my python file. How to create views for it?

dealer.py

from openerp.osv import osv,fields

class dealer(osv.Model):
    _name = 'dealer'
    _inherit = { 'res.partner': 'partner_id', } 
    _columns = { 'name': fields.char('Name', size = 30,required=True), 
                   'region_id': fields.many2one('region.region', 'Region'), }

How to include the partner table info in my view. Pls help me with some examples.

Avatar
Discard

can you explain your needs clearly

Author

Hi Parvathy Vijayan,

I am planning to create a new module dealer. I want to treat this dealer as a partner.All his contact info must be saved in partner and other info will be saved in dealer. That's why i am inheriting the partner module. But the problem is that how to include the fields associated with partner in my view. Please give an explanation with some examples. Its similar to res_user but i can't understand the view associated with that module.

Best Answer

Why don't you modify existing res.partner class adding new checkbox 'dealer' instead of creating new model? Here is a good explanation of xml inheritance.

Avatar
Discard
Best Answer

Let me explain you something.

As I see your code you are creating a new object inheriting the res.partner. What you are doing is that you are creating a new class with new record with ANY relation with res.partner.

If you want to create a new place to see the dealers just add a new field on your class.

Like is a company. Is it a dealer?

Then you can create another menu calling the same res_partner_view but with domain filtering only dealers.

Avatar
Discard
Author

hello Grover i need to add some additional info in the dealer table. so i wish to store all the contact info in partner table and other info in dealer table. how it is possible? its similar to res_user but i didn't understand its view structure.

There are many ways to do it.

First you can create new fields on the same res.partner. Inherit but without a new name. You can create a new boolean field as i told you "Is it a dealer?" and other additional fields. Then you can add a new tab page below with attrs invisible when is_it_dealer=False. So if it's a dealer then it's going to have additional info

Another way is creating a new module dealer. But with a many2one field with res.partner. So you can associate a partner to your new module dealer. The new module doesn't need an inheritance of re.partner. You just need a many2one field that links them.

Author

Grover my problem is how to use that existing view. Many2one is not suitable for me. i need to use all fields in res_partner. i can't create views for inherited fields. how its possible?

Well. Maybe if you can give more details about your new view. As I understood is that you are creating a new partner but with more data as a dealer. If that's the case you only have to inherit res.partner and add dealer fields. It's not going to affect the other partners. As I told you you can add a boolean field to check if it's dealer. and depending that field dealer fields are going to be available. That's the way that I see a solution for this. Well that's what I understood.