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.

1

Problem with many2one field in models which inerit res.partner

By
ghofrane
on 5/15/13, 12:00 PM 5,499 views

Hi all,

I want to add new field (many2one) in form view of res.partner but i got ERROR DataError: invalid input syntax for integer: "default" LINE 1: ...om.id FROM "travel_room" WHERE travel_room.id IN ('default')... :


in my model i create partner.py :

from osv import osv,fields

class partner(osv.osv):

_inherit = 'res.partner'
_columns = {
    'hotel' : fields.boolean('Hotel'),
    'type' : fields.many2one('travel.room', 'type de la chambre', change_default=True, select=True, track_visibility='always', ondelete="cascade"),
}

partner()


and my partner_view.xml :

<openerp> <data> <record model="ir.ui.view" id="partner_hotel_form_view">

    <field name="name">partner.hotel.name</field>
    <field name="model">res.partner</field>  
    <field name="inherit_id" ref="base.view_partner_form" />    
    <field name="arch" type="xml">
   <data>
   <field name="supplier" position="after">
    <field name="hotel" />
   </field>
       <field name="customer" position="after">
    <field name="type" />
   </field>
   </data>
    </field>        
</record>

</data> </openerp>


and here my class travel_room :

class travel_room(osv.osv):

_name = 'travel.room'

_columns = {
    'product_id' : fields.many2one('product.product', 'Type de la chambre', required=True, change_default=True, select=True, track_visibility='always', ondelete="cascade"),
    'name' : fields.related('product_id', 'name', type='char', size=128, string='Product Name'),
    'room_desc' : fields.many2one('product.category', 'Descripcion', required=True, ondelete='cascade'),
    'cost_price' : fields.float('Prix de revient', digits=(6,3), help="Prix de revient"),
    'sale_price' : fields.float('Prix d\'achat', digits=(6,3), help="Prix d'achat"),
}
_defaults = {
}

travel_room()

any one can help me Please! Thank you

Any reason for the blank _defaults dictionary? What version are you running? You could run the server with the command line option --log-sql to expand on what that full statement is.

Brett Lehrer
on 5/15/13, 3:30 PM

Hi Brett, i'm using version 7 of openerp , I removed the blank _defaults dictionary and I got same error : 2013-05-16 09:14:46,340 6896 ERROR test openerp.sql_db: bad query: SELECT travel_room."product_id",travel_room."sale_price",travel_room."cost_price",travel_room."room_desc",travel_room.id FROM "travel_room" WHERE travel_room.id IN ('default') ORDER BY id Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130331_231656-py2.7.egg/openerp/sql_db.py", line 22

ghofrane
on 5/16/13, 6:38 AM
0

Brett Lehrer

--Brett Lehrer--
1252
| 5 4 8
Milwaukee, United States
--Brett Lehrer--
Director of IT and open source enthusiast.
Brett Lehrer
On 5/16/13, 12:32 PM

The problem is that the field 'type' already exists in res.partner. Not normally a big deal, but it's also given default values from the base module, which means that if you inherit res.partner and define 'type' differently but don't change the _defaults dictionary to stop inserting 'contact' or 'default', this error will occur.

Just change the name of your 'type' field to something like 'hotel_type' - it's more explicit and pythonic anyway, but also fixes your problem. Also cleaned up the view a bit for organization so that the hotel_type is hidden when 'hotel' is False.

partner.py: from openerp.osv import osv,fields

class partner(osv.Model):
    _inherit = 'res.partner'
    _columns = {
        'hotel': fields.boolean('Hotel'),
        'hotel_type': fields.many2one('travel.room', 'type de la chambre', change_default=True, select=True, ondelete='cascade'),
    }
partner()

partner_view.xml:

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="partner_hotel_form_view">
    <field name="name">partner.hotel.name</field>
    <field name="model">res.partner</field>  
    <field name="inherit_id" ref="base.view_partner_form" />
    <field name="arch" type="xml">
        <data>
            <xpath expr="//group/field[@name='supplier']" position="after">
                <field name="hotel" />
                <field name="hotel_type" attrs="{'invisible': [('hotel','=',False)]}"/>
            </xpath>
        </data>
    </field>
</record>
</data>
</openerp>

Thank you very much Brett for your answer but when i add or change any field in partner.py i see this ERROR! 2013-05-16 14:40:46,119 16911 ERROR test openerp.netsvc: column res_partner.hotel_type does not exist LINE 1: ..._partner."debit_limit",res_partner."signup_token",res_partne... it's from yestreday :( Please have you a solution for this Error ?

ghofrane
on 5/16/13, 12:48 PM

Even when i add any other field in my partner.py i get the same Error, i can't understand why ?!

ghofrane
on 5/16/13, 12:50 PM

Have you reloaded your module? Changing the field after it's initialized means it needs to be reloaded. Or if that doesn't work, try on a fresh database to see what happens.

Brett Lehrer
on 5/16/13, 1:01 PM

with a fresh database it work! Brett Please can you tell me if there is a possibility to clean the database after i delete any field from .py file ? because every time i delete a field and i check the database with pgadmin3 i see the column named with the that field and with the word _moved1 or _moved_2 ... for example type_moved1 !

ghofrane
on 5/16/13, 1:14 PM

and Thank you very much again :))

ghofrane
on 5/16/13, 1:20 PM

I don't think it's possible to automatically do that, since it tends to just ignore unused columns rather than drop them completely. It's fine to leave them in as you're developing and testing, just make a new database and import data once you're ready to move to production. If you really want to drop a column, you'd have to do it manually in pgAdmin through the menus or with this SQL statement format: "ALTER TABLE my_table DROP my_obsolete_field;"

Brett Lehrer
on 5/16/13, 1:21 PM

Thank you Brett for your quick and good answer :)

ghofrane
on 5/16/13, 1:25 PM
0
ghofrane
On 5/16/13, 7:27 AM

Hi Brett, i'm using version 7 of openerp , I removed the blank _defaults dictionary and I got same error : 2013-05-16 09:14:46,340 6896 ERROR test openerp.sql_db: bad query: SELECT travel_room."product_id",travel_room."sale_price",travel_room."cost_price",travel_room."room_desc",travel_room.id FROM "travel_room" WHERE travel_room.id IN ('default') ORDER BY id Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20130331_231656-py2.7.egg/openerp/sql_db.py", line 226, in execute res = self._obj.execute(query, params) DataError: invalid input syntax for integer: "default" LINE 1: ...om.id FROM "travel_room" WHERE travel_room.id IN ('default')...

Please can anyoune help me! i just want to know if it's possible to add field.many2one('my.model') in class which inherit res.partner knowing that 'my.model' contain field.many2one('product.product'). i(m using version 7 of openerp

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: 5/15/13, 12:00 PM
Seen: 5499 times
Last updated: 3/16/15, 8:10 AM