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 change a boolean field based on another field? (when a many2one is created)

S'inscrire

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

Cette question a été signalée
projectmany2oneone2manytaskonchange
3 Réponses
13466 Vues
Avatar
Skander

Hello everyone, i'm new to odoo developing and this is my first module.

I want to assign material resources to project task.(most of the time vehicles, we have many)

I want to know which cars are free and which ones are assigned to tasks.

So i created a boolean field named assigned to be True when a material resource is added to a task(i.e task_id is no more null), but it is always false when i check the database.So the function i created seems to not work for some reason.

from openerp import models, fields, api
class MaterialResource(models.Model):
    _name = 'material.resource'
    name = fields.Char('Material Resource', required=True)
    description = fields.Selection(string='Description', selection=[('m', 'Mazda'), ('f', 'Ford')])
    task_id = fields.Many2one("project.task", inverse_name="material_resource_ids")
    assigned = fields.Boolean(compute="_get_material_status", store="True")
    @api.one
    @api.depends('task_id')
    def _get_material_status(self):
        if self.task_id is None:
            return False
        else:
            return True
class TaskMaterial(models.Model):
    _inherit = 'project.task'
    material_resource_ids = fields.One2many(comodel_name="material.resource", inverse_name="task_id", string="Material Resource")
0
Avatar
Ignorer
Avatar
Akhil P Sivan
Meilleure réponse

Hi,

Try like this:

from openerp import models, fields, api

class MaterialResource(models.Model):

_name = 'material.resource'

name = fields.Char(string='Material Resource', required=True)

description = fields.Selection(string='Description', selection=[('m', 'Mazda'), ('f', 'Ford')])

task_id = fields.Many2one("project.task", string="Task")

assigned = fields.Boolean(compute="_get_material_status", string="Assigned")

@api.one

@api.depends('task_id')

def _get_material_status(self):

if self.task_id:

self.assigned = True

else:

self.assigned = False

class TaskMaterial(models.Model):

_inherit = 'project.task'

material_resource_ids = fields.One2many("material.resource",'task_id', string="Material Resources")

1
Avatar
Ignorer
Avatar
Emipro Technologies Pvt. Ltd.
Meilleure réponse

Try following:

@api.one    
@api.depends('task_id')
def _get_material_status(self):
if self.task_id:
self.assigend=True
    else:
        self.assigned=False
   



 

1
Avatar
Ignorer
Avatar
Skander
Auteur Meilleure réponse

Thank you i have tried all of these but it's still False.

task_id takes numbers (1,2,3...) which is normal when i execute select * from material_resource;

but when i test it in the view, <field name="task_id"/> shows the name of the task it's very strange i don't understand!

Anyway i've found another solution: i create a filter ( task_id is not set) which syntax is domain="[[u'task_id', u'=', False]]"

i can get the same result with it.

0
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é
Getting project name from task inside a python function
project many2one task
Avatar
Avatar
3
avr. 20
4201
How to give Domain filter for one2many field base on the condition of another field? (Odoo 13) Résolu
many2one one2many onchange domain_filter
Avatar
Avatar
2
juil. 22
12763
odoo onchange function on one2many field Résolu
function fields many2one one2many onchange
Avatar
Avatar
Avatar
Avatar
3
oct. 22
22374
Get id of a new record not saved (odoo.models.NewId object)
project one2many task milestone odoo12
Avatar
0
mars 21
5148
How To Pass Value on Onchange of Many2one field in One2many Résolu
many2one one2many onchange one2many_list odoo9.0
Avatar
Avatar
3
sept. 18
13187
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