from openerp.osv import osv, fields
from datetime import date, timedelta, datetime
-
+# ================================ MESURABLE ================================ #
class Mesurable(osv.Model):
_name = "cmmi.axes.mesurable"
_description = "Table de reference des mesusrables."
- _statuts = [("cree", "Crée"), ("encours", "En cours"),
+ _states = [("cree", "Crée"), ("encours", "En cours"),
("termine", "Terminé"), ("abandonne", "Abandonné"),
("suspendu", "Suspendu"), ("generique", "Générique")]
"name": fields.char(string="Title", size=64, required=True),
"description": fields.text(string="Description"),
"commentaire": fields.text(string="Commentaire"),
- "statut": fields.selection(_statuts, string="Statut"),
+ "state": fields.selection(_states, string="State"),
"version": fields.char(string="Version", size=16),
"date_jalon": fields.date(string="Jalon"),
"date_init_deb": fields.date(string="Init début"),
"date_plan_fin": fields.date(string="Plan fin"),
"date_reel_deb": fields.date(string="Réel début"),
"date_reel_fin": fields.date(string="Réel fin"),
- "nb_jours_projets": fields.function(_nb_jours_init,
+ "nb_jours_initial": fields.function(_nb_jours_init,
type="integer",
string="Nombre de jour"),
}
+ _defaults = {
+ "state": "cree",
+ }
+
_sql_constraints = [
(
"date_init_deb_before_date_init_fin",
- "CHECK(date_init_deb<> date_init_fin)",
+ "CHECK(date_init_deb <= date_init_fin)",
"The date_init_deb should be previous date_init_fin",
),
(
"date_plan_deb_before_date_plan_fin",
- "CHECK(date_plan_deb <> date_plan_fin)",
+ "CHECK(date_plan_deb <= date_plan_fin)",
"The date_plan_deb should be previous date_plan_fin",
),
(
"date_reel_deb_before_date_reel_fin",
- "CHECK(date_reel_deb<> date_reel_fin)",
+ "CHECK(date_reel_deb <= date_reel_fin)",
"The date_reel_deb should be previous date_reel_fin",
),
]
-#==================== TRAVAIL CALCUL JOURS OUVRES =============================
-
+ def commencer(self, cr, uid, ids, context=None):
+ if type(ids) == list:
+ if len(ids) != 1:
+ return
+ ids = ids[0]
+
+ palier = self.read(cr, uid, ids, ['date_plan_deb', 'date_plan_fin', 'state'], context)
+
+ if palier['state'] != 'cree':
+ return {
+ 'warning': { # FIXME: ne fonctionne pas
+ 'title' : "Warning: not a list",
+ 'message' : "You cannot have negative number of seats",
+ },
+ }
+
+ self.write(
+ cr,
+ uid,
+ ids, {
+ 'date_init_deb' : palier['date_plan_deb'],
+ 'date_init_fin' : palier['date_plan_fin'],
+ 'state': 'encours'
+ },
+ context)
+ return self
+
+
+ def suspendre(self, cr, uid, ids, context=None):
+ if type(ids) == list:
+ if len(ids) != 1:
+ return # TODO: message d'avertissement
+ ids = ids[0]
+
+ mesurable = self.read(cr, uid, ids, ['state'], context, context)
+ if mesurable['state'] != 'encours':
+ return
+ self.write(
+ cr,
+ uid,
+ ids,
+ {'state': 'suspendu'},
+ context,
+ )
+ return self
+
+ def terminer(self, cr, uid, ids, context=None):
+ if type(ids) == list:
+ if len(ids) != 1:
+ return # TODO: message d'avertissement
+ ids = ids[0]
+
+ mesurable = self.read(cr, uid, ids, ['state'], context, context)
+ if mesurable['state'] != 'encours':
+ return
+ self.write(
+ cr,
+ uid,
+ ids,
+ {'state': 'termine'},
+ context,
+ )
+ return self
+
+ def abandonner(self, cr, uid, ids, context=None):
+ if type(ids) == list:
+ if len(ids) != 1:
+ return # TODO: message d'avertissement
+ ids = ids[0]
+
+ mesurable = self.read(cr, uid, ids, ['state'], context, context)
+ if not ('encours', 'cree').__contains__(mesurable['state']):
+ return
+ self.write(
+ cr,
+ uid,
+ ids,
+ {'state': 'abandonne'},
+ context,
+ )
+ return self
+
+ def reprendre(self, cr, uid, ids, context=None):
+ if type(ids) == list:
+ if len(ids) != 1:
+ return # TODO: message d'avertissement
+ ids = ids[0]
+
+ mesurable = self.read(cr, uid, ids, ['state'], context, context)
+ if mesurable['state'] != 'suspendu':
+ return
+ self.write(
+ cr,
+ uid,
+ ids,
+ {'state': 'encours'},
+ context,
+ )
+ return self
+
+#------------ TRAVAIL CALCUL JOURS OUVRES ------------
@staticmethod
def _get_date_paques(annee):
"""
tmp += timedelta(days=1)
return jour_ouvres
-#==============================================================================
+# ================================= PALIER ================================== #
class Palier(osv.Model):
_name = "cmmi.axes.palier"
string="Phases"),
}
+ _defaults = {
+ "type_palier": "normal",
+ }
+
def create(self, cr, uid, vals, context=None):
palier_id = osv.Model.create(self, cr, uid, vals, context=context)
phase_model = self.pool.get("cmmi.projet.phase")
phases_ids = phase_model.search(cr, uid, [('selectionne', '=', True)])
+ palier_model = self.pool.get("cmmi.axes.palier")
+ palier = palier_model.read(cr, uid, palier_id, ['date_plan_deb', 'date_plan_fin'])
+
# Création des PalierPhase
palier_phase_model = self.pool.get("cmmi.axes.palier.phase")
for phase_id in phases_ids:
{
'phase_id': phase_id,
'palier_id': palier_id,
+ 'date_plan_deb': palier['date_plan_deb'],
+ 'date_plan_fin': palier['date_plan_fin'],
}
)
-
return palier_id
+# =============================== PALIER-PHASE ============================== #
class PalierPhase(osv.Model):
_name = "cmmi.axes.palier.phase"
return osv.Model.create(self, cr, uid, vals, context=context)
+# ================================ CHANTIER ================================= #
class Chantier(osv.Model):
_name = "cmmi.axes.chantier"