This question has been flagged
4 Replies
9721 Views

hi ,

In my module i need to add contact persons such as company as well as person. How the existing person information to be included in my module? Pls provide some examples too.

Thanks, Praveen

Here is my work files . I didn't able create the view for partner

i tried that one but it doesn't give any results. I will give my work files to you.

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'), }

dealer()

dealer_view.xml

<openerp> <data>

<menuitem id="dealer_main_menu" name="Dealer"/>
<record id="dealer_dealer_tree_view" model="ir.ui.view">
    <field name="name">dealer.dealer.tree</field>
    <field name="model">dealer</field>
    <field name="arch" type="xml">
        <tree string="Regions">
            <field name="name"/>
            <field name="region_id"/>
        </tree>
    </field>
</record>
<record id="dealer_dealer_form_view" model="ir.ui.view">
    <field name="name">dealer.dealer.form</field>
    <field name="model">dealer</field>
    <field name="arch" type="xml">
        <form string="dealer">
    <field name="street"/>#inherited from partner module. I need all information from partner table like this
                <field name="name"/>
    <field name="region_id"/>       
       </form>
    </field>
</record>
<record id="dealer_normal_action" model="ir.actions.act_window">
    <field name="name">Dealer</field>
    <field name="res_model">dealer</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree,form</field>
</record>

<menuitem id="section_main_menu" parent="dealer_main_menu" name="dealer Information"/> <menuitem id="dealer_real_menu" parent="section_main_menu" action="dealer_normal_action" name="dealer"/> </data> </openerp>

Avatar
Discard

Hello, CAN you describe what you Want to achieve in your module ? I don't understand your need

Author

hi Nicolas, i am planning to include a dealer module. So i need to add their contact information in the partner table and other information in my dealer module. So i want to include the contact information in my module and get this partnerid in my table. How to do this?

i need to keep all contact information as like a customer and some additional information in the dealer table. I need the customer contact views and store the contact info in partner table and other info in dealer table . Keep the partner id in dealer table.

Best Answer

hello,

You need to use inherit mecanism (like res.user do with res.partner)

Define your object like this:

class dealer(osv.osv):

    _inherits = {
        'res.partner': 'partner_id',
    }
    _name = "dealer"
    _description = 'Dealer'

Now if you query dealer, you have dealer field + res.partner field. If you query res.partner, you have only partner field.

Check in openobject-server/openerp/addons/base/res/res_users.py to see an example of this.

For the view, you can add a new view on dealer like other object, or you can copy view you like for res.partner for exemple. Just say that you want a view on your new object (with technical group check on administrator):

image description

  • Settings -> technical -> useer interface Views
  • Create

And fill the form like this in your case:

image description

  1. Name of the view
  2. Name of your inherited object if you want all field to be available.
  3. You can use all fields from res.partner and dealer model like:

  4. name, street, email etc ..

Avatar
Discard
Author

i tried that one. But the difficulty faced by me was, how to set up the views for inherited object. Please give some clarification about setting up of views for this inherited object

I had this explain on my answer, tell me if it's ok for you, and check answered if it's ok :)

Author

i tried that one but it doesn't give any results. My work files are added to the question pls verify it and give me instruction to how to create such kind of views.

In my use case I needed entities for vendor and vendor contacts but found inheriting from partner problematic due to access rules. My solution is to create entirely separate entities and give the parent a many2one field for res.user. Now I have entities which will not be interfered with by partner access rules but which can still be associated to partner through res.user. Now it is simple to make custom views which inherit from either if the association exists.

Author

Hi Nicolas r u noticed my updates. Pls help me if you know it

Yes I add this to me answer .. your update about view ?

Author

Nicolas how to create views for my module. When i am tried to include the fields of partner module as like my updated view it will generates an error. how to solve it.

Can you put the error message ? I will try to create a small module with a working example. Be careful, I think you have set up 2 times the field name (res.partner already has it). The one of dealer will replace res.partner. I think you should use dealer_name.

Author

ok i will try that and the error is error - ValidateError Error occurred while validating the field(s) arch: Invalid XML for View Architecture!

Ok the view definition is incorrect, can you past it here I will give you the correct syntaxe :)

Author

The xml code is included with the question. Pls note that and give me correct syntax. i already change my name to dealer_name but the same error occurs when i put the name field in view.

Hi Praveen, pliz past the entire error message because all you need is written in it. I need the complete traceback to be able to help you.

Author

Nicolas when i am trying to install that module i will get this error as an alert box ValidateError

Error occurred while validating the field(s) arch: Invalid XML for View Architecture!

no other explanation is there.

Best Answer

Hello !

If I understand correct, you want to display all existing customers list in your form and you want to select any one from existing.
If this is the case then you have to define field in your class like,
'partner_id': fields.many2one('res.partner', 'Customers')

If something else then please specify your requirement in details.

Thanks,
Acespritech Solutions Pvt. Ltd.
www.acespritech.com
Mail: info@acespritech.com
Skype: acespritech
Blog: http://acespritechblog.wordpress.com

Avatar
Discard
Author

I didn't want the existing customer. I am planning to introduce a new entity Dealer. So i need to store their contact information. How its possible with the help of partner module?

Best Answer

And what is the difference between a dealer and a normal partner? Maybe it's enough to add a tag 'Dealer' on some partners. And add some fields if needed. If you need a lot of changes in attributes and functions, you can inherit a new object from partner.

Avatar
Discard

in fact he clearly says: "i need to keep all contact information as like a customer and some additional information in the dealer table. I need the customer contact views and store the contact info in partner table and other info in dealer table . Keep the partner id in dealer table."

Author Best Answer

Hi Nicolas, Here is my work files

dealer.py

from openerp.osv import osv,fields

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

dealer_view.xml

<openerp>

<data>

<menuitem id="dealer_main_menu" name="Dealer"/>
<record id="dealer_dealer_tree_view" model="ir.ui.view">
    <field name="name">dealer.dealer.tree</field>
    <field name="model">dealer</field>
    <field name="arch" type="xml">
        <tree string="Regions">
            <field name="dealer_name"/>
            <field name="region_id"/>
        </tree>
    </field>
</record>

<record id="dealer_dealer_form_view" model="ir.ui.view">
    <field name="name">dealer.dealer.form</field>
    <field name="model">dealer</field>

    <field name="arch" type="xml">

        <form string="dealer">
                <field name="name"/>
                <field name="dealer_name"/>
                <field name="region_id"/>
       </form>
    </field>
</record>

<record id="dealer_normal_action" model="ir.actions.act_window">
    <field name="name">Dealer</field>
    <field name="res_model">dealer</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree,form</field>
</record>

<menuitem id="section_main_menu" parent="dealer_main_menu" name="dealer Information"/>

<menuitem id="dealer_real_menu" parent="section_main_menu" action="dealer_normal_action" name="dealer"/>

</data>

</openerp>

Avatar
Discard