Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
16206 Widoki

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

Awatar
Odrzuć

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.

Autor

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

Najlepsza odpowiedź

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>
Awatar
Odrzuć
Autor

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 ?

Autor

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

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.

Autor

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 !

Autor

and Thank you very much again :))

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;"

Autor

Thank you Brett for your quick and good answer :)

Autor Najlepsza odpowiedź

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
mar 15
4190
2
lut 25
5789
1
gru 24
1372
4
mar 24
3335
1
paź 23
5305