[IMP]pms: replace reservation sequence by folio + compute sequence

This commit is contained in:
Darío Lodeiros
2022-04-07 19:10:29 +02:00
parent 19029b4f4d
commit 2e5f4f4447
7 changed files with 15 additions and 47 deletions

View File

@@ -67,13 +67,6 @@ class PmsProperty(models.Model):
copy=False,
comodel_name="ir.sequence",
)
reservation_sequence_id = fields.Many2one(
string="Reservation Sequence",
help="The sequence that formed the name of the reservation.",
check_company=True,
copy=False,
comodel_name="ir.sequence",
)
checkin_sequence_id = fields.Many2one(
string="Checkin Sequence",
help="Field used to create the name of the checkin partner",
@@ -510,20 +503,6 @@ class PmsProperty(models.Model):
}
)
vals.update({"folio_sequence_id": folio_sequence.id})
if "reservation_sequence_id" not in vals or not vals.get(
"reservation_sequence_id"
):
reservation_sequence = self.env["ir.sequence"].create(
{
"name": "PMS Reservation " + name,
"code": "pms.reservation",
"prefix": "R/%(y)s",
"suffix": "%(sec)s",
"padding": 4,
"company_id": vals.get("company_id"),
}
)
vals.update({"reservation_sequence_id": reservation_sequence.id})
if "checkin_sequence_id" not in vals or not vals.get("checkin_sequence_id"):
checkin_sequence = self.env["ir.sequence"].create(
{

View File

@@ -26,6 +26,11 @@ class PmsReservation(models.Model):
help="Reservation Code Identification",
readonly=True,
)
folio_sequence = fields.Integer(
string="Folio Sequence",
help="Techinal field to get reservation name",
readonly=True,
)
priority = fields.Integer(
string="Priority",
help="Priority of a reservation",
@@ -1878,14 +1883,13 @@ class PmsReservation(models.Model):
else:
raise ValidationError(_("The Property are mandatory in the reservation"))
if vals.get("name", _("New")) == _("New") or "name" not in vals:
pms_property_id = (
self.env.user.get_active_property_ids()[0]
if "pms_property_id" not in vals
else vals["pms_property_id"]
folio_sequence = (
max(folio.mapped("reservation_ids.folio_sequence")) + 1
if folio.reservation_ids
else 1
)
pms_property = self.env["pms.property"].browse(pms_property_id)
vals["name"] = pms_property.reservation_sequence_id._next_do()
vals["folio_sequence"] = folio_sequence
vals["name"] = folio.name + "/" + str(folio_sequence)
if not vals.get("reservation_type"):
vals["reservation_type"] = (
folio.reservation_type if folio.reservation_type else "normal"

View File

@@ -781,5 +781,8 @@ class ResPartner(models.Model):
"pms", "various_pms_partner"
)
if various_partner_id in self.ids:
raise ValidationError(_("The partner 'Various Clients' cannot be deleted"))
various_partner = self.browse(various_partner_id)
raise ValidationError(
_("The partner %s cannot be deleted"), various_partner.name
)
return super().unlink()