From 1a62f57084eaea2cfee18ae31bd81451305f2389 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20CHAZALLET?= Date: Thu, 23 May 2013 16:49:27 +0200 Subject: [PATCH] Gestion du domaine principal --- projet.py | 28 +++++++++++++++++++++++----- views/projet.xml | 6 +++--- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/projet.py b/projet.py index 4e2e7a6..8967371 100644 --- a/projet.py +++ b/projet.py @@ -9,10 +9,29 @@ class Projet(osv.Model): _name = "cmmi.projet" + def _get_main_domain(self, cr, uid, ids, field_name=None, arg=None, context=None): + if type(ids) in (int, float): + ids = [ids] + + projects = self.browse(cr, uid, ids, context=context) + + result = {} + + for project in projects: + for domain in project.domains: + if domain.main: + result[project.id] = domain.name + break + else: + result[project.id] = "Any domain is selected as main domain yet" + + return result + + _columns = { "name": fields.char(string="Title", size=64, required=True), "description": fields.text(string="Description"), - "domaines": fields.one2many("cmmi.projet.domaine", + "domains": fields.one2many("cmmi.projet.domaine", "project_id", string="Domaines"), "team_members": fields.many2many("cmmi.partner.teammember", @@ -49,10 +68,9 @@ class Projet(osv.Model): "project_id", string="MOA principale", domaine=[('main', '=', True)]), - "main_domain": fields.one2many("cmmi.projet.domaine", - "project_id", - string="Domaine principal", - domaine=[('main', '=', True)]), + "main_domain": fields.function(_get_main_domain, + type="string", + string="Domaine principal"), } def action_add_domain(self, cr, uid, ids, context=None): diff --git a/views/projet.xml b/views/projet.xml index 3d150aa..bd1199a 100644 --- a/views/projet.xml +++ b/views/projet.xml @@ -18,9 +18,9 @@