Newer
Older
# © 2019 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class ScopMembershipOutWizard(models.TransientModel):

Benjamin - Le Filament
a validé
_name = "scop.membership.out.wizard"
_description = "Radiation"
# Default functions
@api.model
def _default_partner_id(self):

Benjamin - Le Filament
a validé
return self.env.context.get("active_id")
comodel_name="res.partner", string="Partner", default=_default_partner_id

Benjamin - Le Filament
a validé
type_all = fields.Boolean(string="Tous types d'adhésion", default=True)

Benjamin - Le Filament
a validé
"scop.membership.type", string="Type d'adhésion", ondelete="restrict"
)
end = fields.Date("Fin d'adhésion", required=True, default=lambda self: fields.Date.today())

Benjamin - Le Filament
a validé
"scop.membership.reason.end",

Benjamin - Le Filament
a validé
ondelete="restrict",
required=True,
)
note = fields.Text("Commentaires")

Benjamin - Le Filament
a validé
# ............................................................

Benjamin - Le Filament
a validé
# ............................................................
# On veut cloture toutes les périodes

Benjamin - Le Filament
a validé
if period.type_all:
last_periods = self.env["scop.membership.period"].search(
[
("partner_id", "=", period.partner_id.id),

Benjamin - Le Filament
a validé
("end", "=", False),
]
)
for lp in last_periods:
period_type_id = lp.type_id.id
period_type_id,
period.end,
period.end_reason_id.id,

Benjamin - Le Filament
a validé
period.note,
)
# On ne veut cloturer qu'une seule période
else:
period_type_id = period.type_id.id
period_type_id,
period.end,
period.end_reason_id.id,

Benjamin - Le Filament
a validé
period.note,
)
self.partner_id.write({"membership_status": "out"})

Benjamin - Le Filament
a validé
# ............................................................

Benjamin - Le Filament
a validé
# ............................................................
def member_out_period(self, partner_id, period_type_id, end, end_reason_id, note):

Benjamin - Le Filament
a validé
last_period = self.env["scop.membership.period"].search(
[
("partner_id", "=", partner_id),
("end", "=", False),
("type_id", "=", period_type_id),
],
limit=1,
)
if last_period:
if end >= last_period.start:

Benjamin - Le Filament
a validé
last_period.write(
{
"end": end,
"end_reason_id": end_reason_id,
"note": note,
}
)
_(
"La date de fin doit être postèrieure à la date de "
+ "début de la dernière période: "
)

Benjamin - Le Filament
a validé
+ str(last_period.start)
)
raise ValidationError(
_("Il n'existe pas de période avec ce type à fermer.")
)