Newer
Older
# Copyright 2020-2022 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
cout_id = self.env["adefpat.project.cout"].search(
[
("project_id", "=", self.env.context["default_project_id"]),
("partner_id", "!=", False),
],
limit=1,
)
return cout_id.partner_id.id
@api.model
def _default_participant_ids(self):
if "default_project_id" in self.env.context:
project_id = self.env["project.project"].browse(
if project_id.exists().membre_ids:
participant_ids = project_id.porteurs_projets_ids.mapped(lambda p: (0, 0, {
"porteur_id": p.porteur_id.id,
"lastname": p.lastname,
"firstname": p.firstname,
"commune": p.commune,
"mobile": p.mobile,
"fixe": p.fixe,
"email": p.email,
"eligible": p.eligible,
}))
self.update({"participant_ids": participant_ids})
return participant_ids
default=lambda self: self.env.uid,
index=True,
("active", "=", True),
("is_company", "=", False),
("is_consultant_form", "=", True),
"|",
("reference", "=", "reference"),
("reference", "=", "prereference"),
],
)
duree_jr = fields.Selection(
[
("demi_journee", "Demi journée"),
("journee", "Journée"),
duree_hr = fields.Float("Durée (int)", compute="_compute_duree_hr", store=True)
comodel_name="res.partner.porteur.project",
inverse_name="task_id",
string="Participants",
default=_default_participant_ids,
)
cout_seance = fields.Float("Coût de la séance", compute="_compute_cout_seance")
date_account = fields.Date("Date de la facture")
@api.multi
def _compute_duree_hr(self):
for task in self:
if task.duree_jr == "demi_journee":
task.duree_hr = 0.5
@api.multi
def _compute_cout_seance(self):
for task in self:
if task.formateur_id:
formateur_proj = self.env["adefpat.project.cout"].search(
[
("project_id", "=", task.project_id.id),
("partner_id", "=", task.formateur_id.id),
],
limit=1,
)
task.cout_seance = formateur_proj.cout_jour * task.duree_hr