return result
+ def _get_main_moa(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 moa in project.moa_ids:
+ if moa.main:
+ result[project.id] = moa.name
+ break
+ else:
+ result[project.id] = "Any moa is selected as main moa yet"
+
+ return result
+
+
_columns = {
"name": fields.char(string="Title", size=64, required=True),
"description": fields.text(string="Description"),
"project_id",
string="MOE principale",
domaine=[('main', '=', True)]),
- "moa_id": fields.one2many("cmmi.projet.moa",
- "project_id",
- string="MOA principale",
- domaine=[('main', '=', True)]),
+ "moa_id": fields.function(_get_main_moa,
+ type="string",
+ string="MOA principale"),
"main_domain": fields.function(_get_main_domain,
type="string",
string="Domaine principal"),
}
+
def create(self, cr, uid, vals, context=None):
project_id = osv.Model.create(self, cr, uid, vals, context=context)
}
def onchange_main(self, cr, uid, ids, project, moa, main, context=None):
- pass
+ if not main:
+ return {'value': {'main': True},
+ 'warning': {
+ 'title' : "Integrity Warning",
+ 'message' : "Une des MOA doit ĂȘtre la MOA principale",
+ }
+ }
+ ids = self.search(
+ cr,
+ uid,
+ [
+ ('project_id', '=', project),
+ ('moa_id', '!=', moa),
+ ],
+ context=context,
+ )
+ current_id = self.search(
+ cr,
+ uid,
+ [
+ ('project_id', '=', project),
+ ('moa_id', '=', moa),
+ ],
+ context=context,
+ )
+ self.write(cr, uid, ids, {'main': False}, context=context)
+ self.write(cr, uid, current_id, {'main': True}, context=context)
+
+ return {'value': {'main': True}}
class ProjetPhase(osv.Model):