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
    • Intelligence artificielle
    • 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
    • Supermarché
    • Quincaillerie
    • Magasin de jouets
    Restauration & Hôtellerie
    • 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
    • Brasserie
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Commerce
    • Homme à tout faire
    • Matériel informatique & 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
    Parcourir toutes les 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
    • Devenir partenaire
    • Services pour partenaires
    • 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
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

Performing arithmetic on fields

S'inscrire

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

Cette question a été signalée
onchangeInterest
2 Réponses
6174 Vues
Avatar
Arjun Khode

Hi, I'm trying to write a module that calculates interest on a certain principal amount given a rate of interest, and displays the new amount to be returned in a field.

This is my python code:

class record(osv.Model):
    _name="record"
    _columns={
              'investment_id':fields.many2one('investment.model','Name of Investment'),
              'investor_id':fields.many2one('res.partner','Investor Name'),   
              'start_date':fields.date('Start Date'),
              #'end_date':fields.date('End Date'),
              'amount':fields.float('Amount Paid'),
              'roi':fields.float('Rate of Interest in fraction'),
              'returns':fields.float('Amount to be returned')
              }

I want 'returns' field to be like: returns=amount+amount*roi

Here is my XML:       

<record id="record_form_view" model="ir.ui.view">        
            <field name="name">record.form.view</field>
            <field name="view_type">form</field>
            <field name="model">record</field>
            <field name="arch" type="xml">
                <form string="Record">
                <group>
                    <field name="investment_id"/>
                    <field name="investor_id"/>
                    <field name="start_date"/>
                    <!--  <field name="end_date"/> -->
                    <field name="roi"/>
                    <field name="amount"/>
                    <field name="returns"/>
                    <!-- <button name="action_compute_returns" string="Compute Returns" type="object"/> -->
                    <button name="%(register_payment_button_action)d" string="Register Payment" type="action"/>
                    <button name="%(pay_investor_button_action)d"  string="Pay Investor" type="action"/>
                                            
                </group>
                </form>            
               </field>
        </record>

How to write or modify my code so that it will calculate the 'returns' field?
I also want to display the updated value of return.

 

0
Avatar
Ignorer
Avatar
Arjun Khode
Auteur Meilleure réponse

Thankyou Cyril. The solution is perfect. This solved a big problem of mine.

Also, there were two parantheses missing but I added them.

Here's the code with correct parantheses:

import openerp.addons.decimal_precision as dp
from openerp.osv import orm

class record(orm.Model):
    _name="record"

    def _amount_returns(self, cr, uid, ids, field, arg, context=None):
        
        context = context or {}

        res = {}

        for record in self.browse(cr, uid, ids, context=context):

            res[record.id] = (record.amount or 0.0) * (1 + (record.roi or 0.0))
        
        return res

    _columns={
              'investment_id':fields.many2one('investment.model','Name of Investment'),
              'investor_id':fields.many2one('res.partner','Investor Name'),   
              'start_date':fields.date('Start Date'),
              #'end_date':fields.date('End Date'),
              'amount':fields.float('Amount Paid'),
              'roi':fields.float('Rate of Interest in fraction'),
              'returns':fields.function(_amount_returns, digits_compute=dp.get_precision('Account'), string='Amount to be returned',
            store={
                'record': (lambda self, cr, uid, ids, c={}: ids, ['amount', 'roi'], 10),
                   },)
              }

 

0
Avatar
Ignorer
Avatar
Cyril Gaspard (GEM)
Meilleure réponse

Hi, no need to add a button for that, just use a field type function and a store parameter that depends of  2 fields you use to update the field returns when one of this 2 fields changes:


import openerp.addons.decimal_precision as dp

from openerp.osv import orm

class record(orm.Model):
    _name="record"

 

    def _amount_returns(self, cr, uid, ids, field, arg, context=None):

        context = context or {}

        res = {}

        for record in self.browse(cr, uid, ids, context=context:

            res[record.id] = (record.amount or 0.0) * (1 + (record.roi or 0.0))

        return res


    _columns={
              'investment_id':fields.many2one('investment.model','Name of Investment'),
              'investor_id':fields.many2one('res.partner','Investor Name'),   
              'start_date':fields.date('Start Date'),
              #'end_date':fields.date('End Date'),
              'amount':fields.float('Amount Paid'),
              'roi':fields.float('Rate of Interest in fraction'),
              'returns':fields.function(_amount_returns, digits_compute=dp.get_precision('Account'), string='Amount to be returned',
            store={
                'record': (lambda self, cr, uid, ids, c={}: ids, ['amount', 'roi'], 10),},
              }

2
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é
trying to auto correct a wrong users value
onchange
Avatar
Avatar
1
oct. 23
3745
"Wrong value for %s: %r" % (self, value) Résolu
onchange
Avatar
Avatar
2
oct. 23
4041
How to add domain in onchange function for a One2many field Résolu
onchange
Avatar
Avatar
Avatar
2
août 23
6336
How to create dynamic domain on many2one fields with onchange function? Résolu
onchange
Avatar
Avatar
Avatar
Avatar
Avatar
4
août 23
23035
Odoo onchange method is not saving values in readonly fields Résolu
onchange
Avatar
Avatar
Avatar
Avatar
3
oct. 22
13508
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
  • Devenir 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 Svenska ภาษาไทย 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