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

Compute field V8

S'inscrire

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

Cette question a été signalée
openerpopenerp8odooodooV8odoo8.0
3 Réponses
19641 Vues
Avatar
Helmi Dhaoui

I have to set a field that compute the difference between the old and the new value of a float field, I defined an auxiliary field that contain the old value, but the problem that the value of auxiliary field replaced by the new value then the diff always Zero.

   @api.multi
def _computeVar(self): for record in self: 
            record .val_aux= record .val
            record .val_diff= record .val-record.val_aux

    val=fields.Float(string='val')
val_aux=fields.Float(string='val aux',compute='_computediff', readonly=True) val_diff= fields.Float(string='val diff',compute='_computediff', readonly=True)


 And when wereplace the order of line of the fuction we will have a problem : field used before calculated.
How to solve this problem
0
Avatar
Ignorer
Rihene

you cant calculate them because your fields are readonly as i think

Avatar
Axel Mendoza
Meilleure réponse

You just need to reorder your calculation of the fields to not override the old values. This should work:


    @api.multi
def _computeVar(self):
for record in self:
record.val_diff= record.val - record.val_aux
            record.val_aux= record.val
val=fields.Float(string='val')
val_aux=fields.Float(string='val aux',compute='_computediff', readonly=True)
val_diff= fields.Float(string='val diff',compute='_computediff', readonly=True)


1
Avatar
Ignorer
Avatar
Tarek Mohamed Ibrahim
Meilleure réponse

The above code normally must give zero value in the difference field 'val_diff'

to achieve your request

I have to set a field that compute the difference between the old and the new value of a float field

I suggest the following solution instead of the one defined above,

@api.one
@api.depends('val','old_val') 
def _computediff(self):
    self.val_diff= self.val-self.old_val

val=fields.Float(string='val') 
old_val=fields.Float(string='Old Value') 
val_diff= fields.Float(string='val diff',compute='_computediff', readonly=True)

the old_val field should be updated in the write method as follows

def write(self,cr,uid,ids,vals,context=None):
    ....
    """before calling the super(<your_class_name>,self).write(cr,uid,ids,vals,context),
        gt the old_val field from the persistent database """
    o = self.pool.get('your_class_name').browse(cr,uid,ids[0])
    vals['old_val'] = o.val
    ...
    res = super(<your_class_name>,self).write(cr,uid,ids,vals,context)
    return res

you have to set the initial value of the field 'old_val' to be 0.0, this will be updated in the create method so you are sure that the _computediff will work correctly


I replaced the @api.multi with @api.one based on this link, check Computed fields and default values

 Note :I used in the openERP 7 notation for the write method

1
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é
TransactionRollbackError: could not serialize access due to concurrent update
openerp odoo odooV8 odoo8.0
Avatar
0
déc. 15
7702
How to upgrade openerp 7 database to odoo 8?
openerp odoo odooV8 odoo8.0
Avatar
Avatar
5
nov. 15
6616
How to override the create function with the new api
openerp odoo odooV8 odoo8.0
Avatar
Avatar
1
juil. 15
8353
How to calculate total amount sub total in Purchase Order and Invoice based on a new field..
inheritance openerp odoo odooV8 odoo8.0
Avatar
0
oct. 17
10575
Function is not getting called in openerp
openerp7 openerp odoo odooV8 odoo8.0
Avatar
Avatar
1
févr. 16
4744
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