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

how to set many2one field and autofill other fields?

S'inscrire

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

Cette question a été signalée
many2oneon_changeodooV8
2 Réponses
15597 Vues
Avatar
Uppili Arivukkannu

My .py code is

from openerp.osv import fields, osv

class autobuy(osv.osv):

_name = "auto.buy"

_description = "AutoBuy Customers"

_columns = {

'name' : fields.char('Year',required=True),

'make': fields.char('Make', required=True),

'model' : fields.char('Model', required=True),

'service': fields.char('Service ID'),

}

class servicesales(osv.osv):

_name = "service.sale"

_description = "service"

_columns = {

'name': fields.char('Year', required=True),

'make': fields.char('Make', required=True),

'model': fields.char('Model', required=True),

'serviceid': fields.many2one('auto.buy','Service ID', select=True),

}

My xml code is

<openerp>

<data>

<record id="auto_buy_form_view" model="ir.ui.view">

<field name="name">auto.buy.form</field>

<field name="model">auto.buy</field>

<field name="type">form</field>

<field name="arch" type="xml">

<form string="Autobuy customer details">

<sheet>

<group>

<field name="service"/>

<field name="name"/>

<field name="make"/>

<field name="model"/>

</group>

</sheet>

</form>

</field>

</record>

<record model="ir.ui.view" id="autobuy_tree_view">

<field name="name">autobuy.tree</field>

<field name="model">auto.buy</field>

<field name="type">tree</field>

<field name="arch" type="xml">

<tree string="Autobuy customer details">

<field name="service"/>

<field name="name"/>

<field name="make"/>

<field name="model"/>

</tree>

</field>

</record>

<record model="ir.actions.act_window" id="auto_buy_form">

<field name="name">Autobuy Customers</field>

<field name="res_model">auto.buy</field>

</record>

<menuitem name="AutoBuy" id="Autobuy_menu"/>

<menuitem name="Autobuy" id="AutoBuy_group_menu" parent="Autobuy_menu"/>

<menuitem name="Autobuy Customers" parent="AutoBuy_group_menu" id="Autobuy_menu_mainform" action="auto_buy_form"/>

<record id="service_form_view" model="ir.ui.view">

<field name="name">service.form</field>

<field name="model">service.sale</field>

<field name="type">form</field>

<field name="arch" type="xml">

<form string="Service">

<sheet>

<group>

<field name="serviceid"/>

<field name="name"/>

<field name="make"/>

<field name="model"/>

</group>

</sheet>

</form>

</field>

</record>

<record model="ir.ui.view" id="service_tree_view">

<field name="name">service.tree</field>

<field name="model">service.sale</field>

<field name="type">tree</field>

<field name="arch" type="xml">

<tree string="Service">

<field name="serviceid"/>

<field name="name"/>

<field name="make"/>

<field name="model"/>

</tree>

</field>

</record>

<record model="ir.actions.act_window" id="service_buy_form">

<field name="name">Service</field>

<field name="res_model">service.sale</field>

</record>

<menuitem name="Sales" id="Sales_group_menu" parent="Autobuy_menu"/>

<menuitem name="Slip" parent="Sales_group_menu" id="Sales_menu_mainform" action="service_buy_form"/>

</data>

</openerp>


I have set the field "serviceid" as many2one to call the to call the above class field "service"

'serviceid': fields.many2one('auto.buy','Service ID', select=True),

but it show the values of the "name" field of previous class and not the field "service"

How can I set this?

My second question is

I want to set a onchange function to auto fill the fields. Once I give the "serviceid" field it must call and auto fill the fields of based on the above class.

I will give all field value in the first class and once I give the "serviceid" all fields related to "serviceid" should be auto filled.

Please help me with the complete onchange function(with searching ID) and in xml.

Thanks


1
Avatar
Ignorer
Uppili Arivukkannu
Auteur

def onchange_serviceid(self, cr, uid,name, serviceid):

result={'value':{'make':False}}

if serviceid:

service = self.pool.get('auto.buy').browse(cr, uid, name)

result['value']={'make':service.make.id}

return result

I have tried this code to auto fill but it shows error as

result['value']={'make':service.make.id}

AttributeError: 'bool' object has no attribute 'id'

How can I solve this

Avatar
ayman mohammed adam
Meilleure réponse

dear Uppili Arivukkannu 

,

 add _rec_name= 'service'                                                       
  like this:

class autobuy(osv.osv):

_name = "auto.buy"

_rec_name= 'service'

_description = "AutoBuy Customers"

_columns = {

'name' : fields.char('Year',required=True),

'make': fields.char('Make', required=True),

'model' : fields.char('Model', required=True),

'service': fields.char('Service ID'),

}



the second question

define the onchange method like this:

def onchange_service(self, cr, uid, ids, serviceid=False, context=None):

     res= {}

     if serviceid:

         service_obj= self.pool.get('auto.buy')

         rec = service_obj.browse(cr, uid, serviceid)

         res= {'value':{'name':rec.name, 'model':rec.model, 'make':rec.make}}

     else:

         res= {'value':{'name':False, 'model':False, 'make':False}}

     return res







Then in xml call the onchange method like this:


<field name="serviceid" on_change="onchange_service(serviceid)"/>




I hoped I helped you


         

0
Avatar
Ignorer
Uppili Arivukkannu
Auteur

Thanks for your answer. It works great.

ayman mohammed adam

Ok

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é
Autofill gives ID number not the field value? Résolu
many2one on_change odooV8
Avatar
Avatar
2
juil. 16
4858
Import many2one fields through export option
export many2one odooV8
Avatar
Avatar
1
avr. 20
5782
How to have more than one many2one field for a method?
fields many2one odooV8
Avatar
Avatar
1
juin 18
4641
AttributeError: 'bool' object has no attribute '_fields' - Odoo v8
many2one related odooV8
Avatar
1
nov. 17
8058
Read all sale.order objects on draft state from a custom module - Odoo v8 Résolu
many2one sale.order odooV8
Avatar
Avatar
1
août 17
4938
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