Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

Problem with many2one field in models which inerit res.partner

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
many2oneinherit
2 Réponses
17224 Vues
Avatar
ghofrane

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

1
Avatar
Ignorer
Brett Lehrer

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.

ghofrane
Auteur

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

Avatar
Brett Lehrer
Meilleure réponse

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>
0
Avatar
Ignorer
ghofrane
Auteur

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
Auteur

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

Brett Lehrer

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.

ghofrane
Auteur

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
Auteur

and Thank you very much again :))

Brett Lehrer

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

ghofrane
Auteur

Thank you Brett for your quick and good answer :)

Avatar
ghofrane
Auteur Meilleure réponse

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

0
Avatar
Ignorer
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
many2one field in inherited class ?
many2one inherit
Avatar
0
mars 15
4807
value not pass from many2one field to form
many2one
Avatar
Avatar
Avatar
Avatar
3
sept. 25
2430
Display values of dropdown in a many2one field Résolu
many2one
Avatar
Avatar
2
févr. 25
7075
How to do Prototpye inherit in odoo
inherit
Avatar
Avatar
Avatar
Avatar
Avatar
4
mars 24
4598
Inheritance for account.financial.report model?
inherit
Avatar
Avatar
1
oct. 23
6573
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now