This question has been flagged
1 Reply
14959 Views

Greetingz,

after i have added many2one field , once i tried to save i got this error : ProgrammingError: can't adapt type 'dict'

File "/opt/odoo/odoo-server/openerp/sql_db.py", line 158, in wrapper return f(self, *args, **kwargs) File "/opt/odoo/odoo-server/openerp/sql_db.py", line 234, in execute res = self._obj.execute(query, params) ProgrammingError: can't adapt type 'dict'

check my code bellow :

PYTHON FILE

from openerp.osv import fields, osv

class product_rolls(osv.osv):
      _name = 'product.template'
      _inherit = "product.template"

      _columns = {
        'product_rolls_id': fields.char('Product Pices'),
    'product_rolls_rolls':fields.many2one('new.roll','roll_id'),
      }

      _defaults ={
        'product_rolls_id': 10
      }
product_rolls()


class new_roll(osv.osv):
   _name='new.roll'
   _columns={
       'roll_id':fields.integer("ID"),
           'roll':fields.char('Roll'),
           'size':fields.char("Size"),
           }
new_roll()

XML FILE :

<?xml version="1.0" encoding="utf-8"?>
    <openerp>
    <data>
    <record model="ir.ui.view" id="product_rolls_product_product">
        <field name="name">product.template.stock.property.form.inherit</field>
        <field name="model">product.template</field>
        <field name="inherit_id" ref="stock.view_template_property_form" />
        <field name="arch" type="xml">
        <xpath expr="//field[@name='qty_available']" position="after">
        <newline/>
        <label for="product_rolls_id" />
            
            <field name="product_rolls_id" on_change="onchange_product_rolls_id(product_rolls_id)" />
            <field name="product_rolls_rolls" widget="one2many_list" colspan="4" nolabel="1">
                <tree editable='bottom'>
                <field name="roll"/>  
                <field name="size"/>                           
                </tree>
                <form>
                <field name="roll"/>
                <field name="size"/>
                </form>
            </field>
        </xpath>
        </field>
    </record>
        </data>
    </openerp>

note : before adding the many2one tree it was working perfectly .

 

Regards

Avatar
Discard

@moayad your field 'product_rolls_rolls' is a 'many2one' field and in 'xml' file you are trying to treat it as one2many field. I am not getting it why? This kind of widgets are used one2many fields not for many2one field. Also another thing, although this thing is not affecting your code but I can see is that you are trying to add "ID" field in the "new_roll" table, because Openerp automatically adds ID field in the table.

Author

Ok , i make it one2many and i removed ID field , now there is no errors but no value saved ! Regrads

@moayad if possible please share your code with latest changes that you have made, which will give better idea to solve the issue.

Best Answer

Try this :

class product_rolls(osv.osv):
      _name = 'product.rolls'
      _inherit = "product.template"

      _columns = {
        'product_rolls': fields.char('Product Pices'),
    'product_rolls_id':fields.many2one('new.roll','Product Roll'),
      }

      _defaults ={
        'product_rolls': 10
      }
product_rolls()


class new_roll(osv.osv):
   _name='new.roll'
   _columns={
       'roll_id':fields.one2many('product.rolls','product_rolls_id','Column Name'),
           'roll':fields.char('Roll'),
           'size':fields.char("Size"),
           }
new_roll()

Avatar
Discard