mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms:improve cancel and confirm actions
This commit is contained in:
@@ -814,6 +814,7 @@ class PmsFolio(models.Model):
|
||||
"reservation_ids.reservation_line_ids.cancel_discount",
|
||||
"reservation_ids.reservation_line_ids.default_invoice_to",
|
||||
"reservation_ids.tax_ids",
|
||||
"reservation_ids.state",
|
||||
)
|
||||
def _compute_sale_line_ids(self):
|
||||
for folio in self.filtered(lambda f: isinstance(f.id, int)):
|
||||
@@ -1658,7 +1659,7 @@ class PmsFolio(models.Model):
|
||||
)
|
||||
|
||||
if self.env.context.get("confirm_all_reservations"):
|
||||
self.reservation_ids.confirm()
|
||||
self.reservation_ids.action_confirm()
|
||||
|
||||
return True
|
||||
|
||||
@@ -1809,10 +1810,10 @@ class PmsFolio(models.Model):
|
||||
}
|
||||
|
||||
def _message_post_after_hook(self, message, msg_vals):
|
||||
res = super(PmsFolio, self)._message_post_after_hook(message, msg_vals)
|
||||
res = super(PmsFolio, self).sudo()._message_post_after_hook(message, msg_vals)
|
||||
for folio in self:
|
||||
for follower in folio.message_follower_ids:
|
||||
follower.unlink()
|
||||
follower.sudo().unlink()
|
||||
return res
|
||||
|
||||
def action_view_invoice(self):
|
||||
@@ -1954,6 +1955,17 @@ class PmsFolio(models.Model):
|
||||
month_day,
|
||||
)
|
||||
if invoice_date:
|
||||
if (
|
||||
self.company_id.period_lock_date
|
||||
and invoice_date < self.company_id.period_lock_date
|
||||
and not self.user_has_groups("account.group_account_manager")
|
||||
):
|
||||
raise UserError(
|
||||
_(
|
||||
"The period to create this invoice is locked. "
|
||||
"Please contact your administrator to unlock it."
|
||||
)
|
||||
)
|
||||
if invoice_date < datetime.date.today() and not self._context.get(
|
||||
"autoinvoice"
|
||||
):
|
||||
@@ -2017,7 +2029,7 @@ class PmsFolio(models.Model):
|
||||
lambda m: m.amount_total < 0
|
||||
).action_switch_invoice_into_refund_credit_note()
|
||||
for move in moves:
|
||||
move.message_post_with_view(
|
||||
move.sudo().message_post_with_view(
|
||||
"mail.message_origin_link",
|
||||
values={
|
||||
"self": move,
|
||||
@@ -2168,7 +2180,7 @@ class PmsFolio(models.Model):
|
||||
"origin_reference": folio.external_reference,
|
||||
}
|
||||
pay = self.env["account.payment"].create(vals)
|
||||
pay.message_post_with_view(
|
||||
pay.sudo().message_post_with_view(
|
||||
"mail.message_origin_link",
|
||||
values={
|
||||
"self": pay,
|
||||
@@ -2211,7 +2223,7 @@ class PmsFolio(models.Model):
|
||||
or folio.pms_property_id.email_formatted,
|
||||
)
|
||||
for reservation in folio.reservation_ids:
|
||||
reservation.message_post(
|
||||
reservation.sudo().message_post(
|
||||
body=_(
|
||||
"""Payment: <b>%s</b> by <b>%s</b>""",
|
||||
amount,
|
||||
@@ -2260,7 +2272,7 @@ class PmsFolio(models.Model):
|
||||
"state": "draft",
|
||||
}
|
||||
pay = self.env["account.payment"].create(vals)
|
||||
pay.message_post_with_view(
|
||||
pay.sudo().message_post_with_view(
|
||||
"mail.message_origin_link",
|
||||
values={
|
||||
"self": pay,
|
||||
@@ -2298,7 +2310,7 @@ class PmsFolio(models.Model):
|
||||
or folio.pms_property_id.email_formatted,
|
||||
)
|
||||
for reservation in folio.reservation_ids:
|
||||
reservation.message_post(
|
||||
reservation.sudo().message_post(
|
||||
body=_(
|
||||
"""Refund: <b>%s</b> by <b>%s</b>""",
|
||||
amount,
|
||||
|
||||
@@ -1883,6 +1883,10 @@ class PmsReservation(models.Model):
|
||||
raise ValidationError(
|
||||
_("The reservation must be canceled by action: action_cancel")
|
||||
)
|
||||
if record.state == "confirm" and not self.env.context.get("action_confirm"):
|
||||
raise ValidationError(
|
||||
_("The reservation must be confirmed by action: action_confirm")
|
||||
)
|
||||
|
||||
@api.constrains("arrival_hour")
|
||||
def _check_arrival_hour(self):
|
||||
@@ -2131,7 +2135,7 @@ class PmsReservation(models.Model):
|
||||
record = super(PmsReservation, self).create(vals)
|
||||
record._check_capacity()
|
||||
if record.preconfirm and record.state == "draft":
|
||||
record.confirm()
|
||||
record.action_confirm()
|
||||
|
||||
record._check_services(vals)
|
||||
|
||||
@@ -2295,14 +2299,14 @@ class PmsReservation(models.Model):
|
||||
reservations._compute_priority()
|
||||
return True
|
||||
|
||||
def confirm(self):
|
||||
def action_confirm(self):
|
||||
for record in self:
|
||||
vals = {}
|
||||
if record.checkin_partner_ids.filtered(lambda c: c.state == "onboard"):
|
||||
vals.update({"state": "onboard"})
|
||||
else:
|
||||
vals.update({"state": "confirm"})
|
||||
record.write(vals)
|
||||
record.with_context(action_confirm=True).write(vals)
|
||||
record.reservation_line_ids.update({"cancel_discount": 0})
|
||||
# Unlink penalty service if exist
|
||||
record.service_ids.filtered(lambda s: s.is_cancel_penalty).unlink()
|
||||
@@ -2319,9 +2323,10 @@ class PmsReservation(models.Model):
|
||||
record.with_context(action_cancel=True).state = "cancel"
|
||||
record._check_cancel_penalty()
|
||||
record.cancel_datetime = fields.Datetime.now()
|
||||
if all(
|
||||
# If all reservations in the folio are cancelled, cancel the folio
|
||||
if not (
|
||||
record.folio_id.reservation_ids.filtered(
|
||||
lambda r: r.state == "cancel"
|
||||
lambda r: r.state != "cancel"
|
||||
)
|
||||
):
|
||||
record.folio_id.action_cancel()
|
||||
@@ -2447,7 +2452,7 @@ class PmsReservation(models.Model):
|
||||
record.checkin_partner_ids.filtered(
|
||||
lambda check: check.state == "onboard"
|
||||
).action_undo_onboard()
|
||||
record.state = "confirm"
|
||||
record.action_confirm()
|
||||
return True
|
||||
|
||||
def action_checkin_partner_view(self):
|
||||
|
||||
@@ -415,7 +415,7 @@ class PmsReservationLine(models.Model):
|
||||
line.occupies_availability = True
|
||||
|
||||
# TODO: Refact method and allowed cancelled single days
|
||||
@api.depends("reservation_id.cancelled_reason")
|
||||
@api.depends("reservation_id.cancelled_reason", "reservation_id.state")
|
||||
def _compute_cancel_discount(self):
|
||||
for line in self:
|
||||
if line.state == "cancel":
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<field name="to_assign" invisible="1" />
|
||||
<field name="check_adults" invisible="1" />
|
||||
<button
|
||||
name="confirm"
|
||||
name="action_confirm"
|
||||
string="Confirm"
|
||||
class="oe_highlight"
|
||||
type="object"
|
||||
|
||||
Reference in New Issue
Block a user