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

Problem creating many2many relationship with product.template

By
Nathan Beck
on 7/27/14, 3:39 PM 2,051 views

I am trying to create a module that allows me to assign products to categories determined by external websites (for example Amazon and eBay categories). Each external category can have many products in it, and each product can be in many categories, one for each external site. Everything works until I try to create a many2many relationship between my external_categories and product.template.

My external_categories class looks a lot like the category class in product, it's name is: _name = "external_categories.category"

The class I am trying to create the many2many relationship in is:

class product_template(osv.osv):
    _inherit = "product.template"
    _columns = {
        'ext_cat_prod_ids': fields.many2many('external_categories.category', 'ext_cat_prod_rel', 'prod_id', 'ext_cat_id', 'External Categories'),
    }

product_template()

I know that I am inheriting product.template, and in the XML sample below I am using the model product.product. I have tried every combination of the two (product.template and product.product) in both locations without luck.

I am trying to add a tab to the product page on the front end. In this tab I will be able to add the product to multiple categories, my XML is:

<record id="product_normal_form_view" model="ir.ui.view">
            <field name="name">product.normal.form.inherit</field>
            <field name="model">product.product</field>
            <field name="priority">6</field>
            <field name="inherit_id" ref="product.product_normal_form_view"/>
            <field name="arch" type="xml">
                <notebook position="inside">
                    <page string="External Categories">
                        <group name="properties">
                            <group>
                                <field name="ext_cat_prod_ids" colspan="2" widget="many2many_tags"/>
                            </group>
                        </group>
                    </page>
                </notebook>
            </field>
        </record>

When I try to install the module I get an error, this is from the log:

2014-07-27 19:33:46,736 1396 ERROR newVeroTemp openerp.osv.orm: Can't find field 'ext_cat_prod_ids' in the following view parts composing the view of object model 'product.product':
 * product.normal.form.inherit

Either you wrongly customized this view, or some modules bringing those views are not compatible with your current data model
2014-07-27 19:33:46,736 1396 ERROR newVeroTemp openerp.addons.base.ir.ir_ui_view: Can't render view  for model: product.product
Traceback (most recent call last):
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\openerp\addons\base\ir\ir_ui_view.py", line 126, in _check_render_view
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\openerp\addons\stock\product.py", line 441, in fields_view_get
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\.\openerp\osv\orm.py", line 2278, in fields_view_get
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\.\openerp\osv\orm.py", line 1955, in __view_look_dom_arch
except_orm: ('View error', u"Can't find field 'ext_cat_prod_ids' in the following view parts composing the view of object model 'product.product':\n * product.normal.form.inherit\n\nEither you wrongly customized this view, or some modules bringing those views are not compatible with your current data model")
2014-07-27 19:33:46,740 1396 ERROR newVeroTemp openerp.tools.convert: Parse error in file:///C:/Program Files (x86)/OpenERP 7.0-20140622-231040/Server/server/openerp/addons/external_categories/external_categories.xml:142: 
<record id="product_normal_form_view" model="ir.ui.view">
            <field name="name">product.normal.form.inherit</field>
            <field name="model">product.product</field>
            <field name="priority">6</field>
            <field name="inherit_id" ref="product.product_normal_form_view"/>
            <field name="arch" type="xml">
                <notebook position="inside">
                    <page string="External Categories">
                        <group name="properties">
                            <group>
                                <field name="ext_cat_prod_ids" colspan="2" widget="many2many_tags"/>
                            </group>
                        </group>
                    </page>
                </notebook>
            </field>
        </record>
Traceback (most recent call last):
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\.\openerp\tools\convert.py", line 852, in parse
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\.\openerp\tools\convert.py", line 819, in _tag_record
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\openerp\addons\base\ir\ir_model.py", line 971, in _update
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\openerp\addons\base\ir\ir_ui_view.py", line 103, in create
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\.\openerp\osv\orm.py", line 4551, in create
  File "C:\Program Files (x86)\OpenERP 7.0-20140622-231040\Server\server\.\openerp\osv\orm.py", line 1562, in _validate
except_orm: ('ValidateError', u'Error occurred while validating the field(s) arch: Invalid XML for View Architecture!')
2014-07-27 19:33:46,740 1396 ERROR newVeroTemp openerp.netsvc: ValidateError
Error occurred while validating the field(s) arch: Invalid XML for View Architecture!

Thank you in advance for any help our guidence you can provide in the use of many2many relationships.

 

0
Nathan Beck
On 7/28/14, 5:47 PM

Thank you Jagdish Panchal. I tried your code. Unfortunately, I still get basically the same error: Can't find field 'ext_cat_prod_ids' in the following view parts composing the view of object model 'product.product'

-- UPDATE, PROBLEM SOLVED --

I updated Odoo from 7 to 8 and everything works fine now with the code exactly as it was before (in the original questions). It must be something wrong with Odoo 7 that was causing the problem.

I have update ans please try it.

Jagdish Panchal
on 7/31/14, 12:28 AM
0

Jagdish Panchal

--Jagdish Panchal--
2674
| 5 3 6
Gandhinagar, India
--Jagdish Panchal--

OpenERP Developer

Jagdish Panchal
On 7/28/14, 12:03 AM

Hi,

Try below code

Py file

class product_product(osv.osv):
    _inherit = "product.product"
    _columns = {
        'ext_cat_prod_ids': fields.many2many('external_categories.category', 'ext_cat_prod_rel', 'prod_id', 'ext_cat_id', 'External Categories'),
    }

product_product()

xml file

<record id="product_normal_form_view" model="ir.ui.view">
            <field name="name">product.normal.form.inherit</field>
            <field name="model">product.product</field>
            <field name="priority">6</field>
            <field name="inherit_id" ref="product.product_normal_form_view"/>
            <field name="arch" type="xml">
                <notebook position="inside">
                    <page string="External Categories">
                        <group name="properties">
                            <group>
                                <field name="ext_cat_prod_ids" colspan="2" widget="many2many_tags"/>
                            </group>
                        </group>
                    </page>
                </notebook>
            </field>
        </record>

 

 

 

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: 7/27/14, 3:39 PM
Seen: 2051 times
Last updated: 3/16/15, 8:10 AM