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 do I add a domain to a related field?

S'inscrire

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

Cette question a été signalée
domainpaysliprelated_fieldsv11
5 Réponses
10538 Vues
Avatar
Bill Ennals

In Odoo 11 CE, I am trying to customise the Payslip object, "hr.payslip", which has a One2Many relation with the object "hr.payslip.lines" through the field "line_ids".

I have added a custom field to the object hr.payslip.


net_pay = fields.Float(string='Net Pay', related='line_ids.total', domain=[('line_ids.code', 'ilike', "NET")])


The aim of this field is to fetch the value from the field 'total' in the hr.payslip.line where the field 'code' is set to "NET".  There is only one line per payslip with this code.

The problem I'm having is that the domain does not seem to be applied and the net_pay is just returning the 'total' value from the first line (which has the code "GROSS"), and not excluding lines that have a code different to "NET".

What am I doing wrong?

0
Avatar
Ignorer
Bill Ennals
Auteur

EDITED:

I thought I found the answer to my question thanks to this answer by Lan Pham at stackoverflow

https://stackoverflow.com/questions/59534725/odoo-domain-not-working-with-a-related-field

But the code below doesn't fetch the 'amount' from the payslip.line with code 'NET' for the relevant payslip. It seems to get the first possible value from the hr.payslip.line table.

net_pay = fields.Float(string='Net Pay', compute='_get_netpay')

@api.multi

def _get_netpay(self):

for line in self:

line.net_pay = self.env['hr.payslip.line'].search([('code', '=', "NET")], limit=1).amount

How can I make the "net_pay' field fetch from the line that belongs to the payslip?

Avatar
Axel Mendoza
Meilleure réponse

Hi @Bill

Sorry but what you wanna do it's out of the scope of related field and their domain that only will be applied to relational fields, o2m, m2m, m2o to provide a way to filter the values to select at the UI.

What you wanna do it's easily get it done with a computed field that you could program the whole logic to determine the value for the field

1
Avatar
Ignorer
Bill Ennals
Auteur

Hi Axel,

I thought I had it solved but the code above does not pull the 'amount' from the line that belongs to the relevant payslip. It's returning the same value regardless of which payslip I am looking at. Can you suggest how to fix it?

Avatar
Bill Ennals
Auteur Meilleure réponse

For a solution to achieve what I was hoping to do with related fields, but using computed fields instead (as suggested by Axel), see this thread:

https://www.odoo.com/fr_FR/forum/aide-1/question/how-can-i-filter-records-returned-from-a-computed-field-based-on-values-from-a-related-model-173568

0
Avatar
Ignorer
Axel Mendoza

That link is an answer of a very different and specific question. The one on this post was a wrong usage of the domain on a non filterable field

Bill Ennals
Auteur

Yes, you're right Axel. I didn't mean to suggest you hadn't been helpful. I've edited the parts that I can and marked your answer as the best one.

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é
Search() elements from many "One2many" Résolu
domain one2many v11 search()
Avatar
Avatar
2
août 20
3489
How can I create a related field on purchase.order.line to give me the NAME of the product? (Without the Internal Reference Number prepended to it) Résolu
many2one related related_fields v11 Community
Avatar
Avatar
2
sept. 19
6299
naked domain set up Résolu
domain
Avatar
Avatar
Avatar
Avatar
3
juil. 25
6412
Domain name Request
domain
Avatar
0
mai 25
1750
Domain is not working
domain
Avatar
Avatar
2
mars 24
3036
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