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

AttributeError: 'my_model_name' object has no attribute 'env'

S'inscrire

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

Cette question a été signalée
inheritanceenvironmentinheritodoo8
1 Répondre
46398 Vues
Avatar
inster

Odoo v8

I have wizard with two fields:

class Roll_wizard(models.TransientModel):

_name = 'roll.wizard'

calc_model = fields.Many2one("techdoc", "Car Model")

calc_year = fields.Many2one("techdoc.year", "Car Year")

I need to display in field calc_model a model of the car, instead of field name, so i decided to override name_get()

The model "techdoc" has fields: 

class Car(models.Model):

_name = 'techdoc'

name = fields.Char(string="Brand", size=30, required=True)

car_model = fields.Char(string="Model", size=30, required=True)

car_year = fields.Integer(string="Year", size=30, required=True)

car_engine = fields.Float(string="Engine size", digits=(3, 1), required=True)

car_transmission = fields.Char(string="Transmission type", size=30, required=True)

car_modify = fields.Char(string="Model Modification", size=30)

def name_get(self,cr,uid,ids,context=None):

model = []

result = self.browse(cr,uid,ids,context=context)

for record in result:

tup=(record.car_model, record.car_model.title())

model.append(tup)

model = list(set(model))

return sorted(model)

But after this in field calc_year i need to display car manufactures years.

I've created a new model, inherit "techdoc" model and overrides name_get() agan to display years

class Car_year(models.Model):

_name = 'techdoc.year'

_inherit= 'techdoc'


def name_get(self,cr,uid,ids,context=None):

model = []

result = self.env['techdoc'].browse(cr,uid,ids,context=context)

for record in result:

tup=(record.car_year, record.car_year)

model.append(tup)

model = list(set(model))

return sorted(model)

And I have an error:

AttributeError: 'techdoc.year' object has no attribute 'env'

I want to use instances from "techdoc" model. 

3
Avatar
Ignorer
Avatar
Pawan
Meilleure réponse

instr,

Your way of your defining a class is as per Odoo 8(new) api:

class Car_year(models.Model):

but the way you are defining the functions inside it are according to odoo7(old) api:   

def name_get(self,cr,uid,ids,context=None):
so here to get a pool and browse on any object you have to use:

 result = self.pool.get('techdoc').browse(cr,uid,ids,context=context)
in place of:
 result = self.env['techdoc'].browse(cr,uid,ids,context=context)

where as if you want to stick to new api only, then you must define your function also according to it only, as:

 def name_get(self ,context=None):
and then you can browse as per new api :
 result = self.env['techdoc'].browse(cr,uid,ids,context=context
for further reference visit this link:

https://www.odoo.com/documentation/8.0/reference/orm.html

Hope it Helps!!

6
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é
How to extend an existing class and include social newtork features in the sub class
inheritance inherit
Avatar
Avatar
3
juil. 18
4682
Inheritance in discuss module (mail)
inheritance inherit discuss
Avatar
0
janv. 22
3412
How to create tree view of sibling models ? Résolu
treeview inheritance inherit
Avatar
1
juil. 15
4555
Change sale module view, treestrings, names, button names
inheritance inherit sale.order
Avatar
0
mars 15
5875
How i can add a new state to PO?
inheritance inherit state
Avatar
Avatar
Avatar
2
mars 15
6966
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