This question has been flagged

Hello,

I am a developer and I have created some modules for OpenERP v7 that we use in our company. I have a difficult problem that I want to solve and that's why I am willing someone to share some knowledge with me.

I have a module that extends res.partner to add many fields that we need for our customers. The problem with this is that there are many entities or models that depend on res.parther (res.user for instance). When I add fields to res.partner and extend the form view, then views or models that depend on res.partner are also modified, even when they have nothing to do with customers. This is ugly, because providers and users get those new fields, and I don't want that to happen.

A second approach was to use _inherits in order to control an inner partner, but also add the fields that I want:

_name = 'mycompany.customer'
_inherits = {
    'res.partner': 'partner_id',
}
_columns = {
    ...
}

This approach is cleaner. Now my customers have the basic information in res.partner, but I also add extra fields in my mycompany.customer model. The bad thing is that I have to write my own views from the scratch. What I do for this is to copy res.partner views and extend them. The worst part of this is that when an additional module changes res.partner view, then the view for my customer is not modified, so I have to copy the modifications that this module does into my own code.

What is the best way to do what I want? I just want new fields to be added to a customer, but not to a provider nor a user. I thought about adding a "clone" feature to OpenERP to clone views and its modifications. This way I will be able to clone res.partner views and make some changes to include customer fields.

Avatar
Discard

Can't you just extend the form view normally (as you did initially) and make the fields invisible when the partner is not a customer?

Author

Thank you Leonardo, that is a good idea. How can I know when the partner is a customer? Can I just use domain with customer = 1? What I was trying now is to redefine the fields_view_get function, that is supposed to create a view dynamically. I will check your suggestion first, which seems to be easier. Thank you so much :)

Author

Done, thank you so much Leonardo :)

Yes you can use [('customer', '=', 1)] assuming you correctly flagged customers. Personally, I would add a tab in the res_partner form view notebook (called 'Customer info'), with all the customers-only fields, and show that only when partner is a customer.

Author

That is exactly what I had. There where also some minor changes that I made outside that customer notebook, but they were also hidden successfully. Thank you so much again, I was looking for an "Star Wars hiper-complex solution" doing meta programming to extend cloned views (with fields_view_get) but your proposal is just the easiest and most correct way to do it. Thank you again :)