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

Object Inheritance - field image not found in browse_record

By
bvbvbvb
on 3/4/14, 6:54 AM 2,171 views

Actually i try to get more in to detail with openerp. I understand the basics but in some cases it is a little confusing. So i will try to explane the Problem:

I want to add an additional module called parenteral. This Module has some special Person, e.g. agent. This agent should inherit from res.partner. To test the module i do not add an additional field, so it only has the existing fields, inherited from res.partner. In my agent_view.xml i do not inherit a form but i only created an own Form which presents the name of my agent (the only field that is required=True). There is no problem to add an save an agent. Now i change to the Module "Sales" and try to add a customer. But when i like to save the customer i get an errormessage:

field image not found in browse_record(parenteral.agent)

I dont really understand the reason because parenteral.agent should inherit all fields from res.partner.

My agent.py:

from openerp.osv import osv, fields
import time

class agent(osv.osv):
    _name = 'parenteral.agent'
    _description = 'Verwaltung der Vermittler'
    _inherit = 'res.partner'
    _columns = {}
    _default = {}
    _auto = True
agent()

My agent_view.xml:

<openerp>
    <data>
        <record id="agent_view_tree" model="ir.ui.view">
        <field name="name">parenteral.view.tree</field>
        <field name="model">parenteral.agent</field>
        <field name="arch" type="xml">
                <tree string="Vermittler">
                    <field name="name"/>
                </tree>
        </field>
    </record>

        <record id="agent_view_form" model="ir.ui.view">
            <field name="name">parenteral.agent.form</field>
            <field name="model">parenteral.agent</field>
            <field name="arch" type="xml">
                <form string="Vermittler">
            <field name="name"/>
                </form>
            </field>
        </record>

        <record model="ir.actions.act_window" id="action_agent">
            <field name="name">Vermittler</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">parenteral.agent</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="view_id" ref="agent_view_tree"/>
        </record>

        <menuitem id="menu_action_agent"
                  parent="parenteral.menu_parenteral_contact"
                  action="action_agent"
                  />
    </data>
</openerp>

Maybe someone could explane the behaviour and at most a solution.

1
Shiriru Kiriluksen
On 3/4/14, 8:02 AM

Most probably your error is generated because you have installed mail module (Social networking and CRM). Social networking (mail_thread.py) overrides create method in res.partner module and therefore ORM tries and fails to get ids from wrong table - it tries to get the ids from your custom module, not from res.partner. The workaround I found recently is to change the type of model inheritance as to remove _name and _table from your model definition. That way you extend rather than modify res.partner module and everything works smoothly. Be careful with this approach, thou.

If you need Social networking to work properly with your custom module, you should inherit from multiple modules - both rer.partner and mail_thread and to achieve that you're required to add _name = "res.partner" in your custom module in order to show relevant social messages in your custom module. If you don't need Social networking to interact with your custom module, just remove _name and _table from your model definition and adjust your views accordingly.

Hope this helps.

At first, thank you very much for your answer. What you said sounds really plausible. I definitely do not need the social networking. Already I was really excercised that sales depends on it. However. To fix the problem i should remove _name and _table from my model? Do I have to remove it completely from res.partner or what exactely do you mean? Because till now I only inherit from res.partner.

bvbvbvb
on 3/4/14, 9:26 AM

I adapted my module to use the second way you described. I changed _name to res.partner and adapted the related code. And it works good, without an exception! But, when i want to add more than one module that inherits res.partner, is it necessary to inherit all from res.partner? Then every module would add some special fields to the model and I only have to individualize my views. e.g. I have to represent some Person individual: agent, nurse, and doctor (i have to adapt openerp for a pharmaceutic company).

bvbvbvb
on 3/4/14, 10:00 AM

For this purpose you could create a separate class in your custom module to accommodate all custom categories you requite and define a corresponding relationship, or make a selection field in your existing class that provides agent nurse, etc.

Shiriru Kiriluksen
on 3/4/14, 10:18 AM
0
bvbvbvb
On 3/4/14, 8:56 AM

At first, thank you very much for your answer. What you said sounds really plausible. I definitely do not need the social networking. Already I was really excercised that sales depends on it. However. To fix the problem i should remove _name and _table from my model? Do I have to remove it completely from res.partner or what exactely do you mean? Because till now I only inherit from res.partner.

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

0 follower(s)

Stats

Asked: 3/4/14, 6:54 AM
Seen: 2171 times
Last updated: 3/16/15, 8:10 AM