result[project.id] = moa.name
break
else:
- result[project.id] = "Any moa is selected as main moa yet"
+ result[project.id] = "Any MOA is selected as main MOA yet"
+
+ return result
+
+
+ def _get_main_moe(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 moe in project.moe_ids:
+ if moe.main:
+ result[project.id] = moe.name
+ break
+ else:
+ result[project.id] = "Any MOE is selected as main MOE yet"
return result
"moa_ids": fields.one2many("cmmi.projet.moa",
"project_id",
string="MOAs"),
- "moe_id": fields.one2many("cmmi.projet.moe",
- "project_id",
- string="MOE principale",
- domaine=[('main', '=', True)]),
+ "moe_id": fields.function(_get_main_moe,
+ type="string",
+ string="MOE principale"),
"moa_id": fields.function(_get_main_moa,
type="string",
string="MOA principale"),
}
def onchange_main(self, cr, uid, ids, project, moe, main, context=None):
- pass
+ if not main:
+ return {'value': {'main': True},
+ 'warning': {
+ 'title' : "Integrity Warning",
+ 'message' : "Une des MOE doit ĂȘtre la MOE principale",
+ }
+ }
+ ids = self.search(
+ cr,
+ uid,
+ [
+ ('project_id', '=', project),
+ ('moe_id', '!=', moe),
+ ],
+ context=context,
+ )
+ current_id = self.search(
+ cr,
+ uid,
+ [
+ ('project_id', '=', project),
+ ('moe_id', '=', moe),
+ ],
+ 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 ProjetMoa(osv.Model):