Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEL]pms: delete priority reservation/folio compute field #305

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions pms/data/cron_jobs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,6 @@
<field name="code">model.auto_departure_delayed()</field>
</record>

<record model="ir.cron" id="priority_reservations">
<field name="name">Recompute priority on reservations</field>
<field name="interval_number">1</field>
<field name="user_id" ref="base.user_root" />
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False" />
<field name="state">code</field>
<field name="model_id" ref="model_pms_reservation" />
<field
name="nextcall"
eval="(DateTime.now() + timedelta(days=1)).strftime('%Y-%m-%d 05:30:00')"
/>
<field name="code">model.update_daily_priority_reservation()</field>
</record>
<!-- Scheduler for send confirmed email -->
<!-- <record model="ir.cron" id="send_confirmation_email_folio">
<field name="name">Send Confirmation Email</field>
Expand Down
14 changes: 1 addition & 13 deletions pms/models/pms_folio.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,12 +485,6 @@
compute="_compute_amount_all",
tracking=True,
)
max_reservation_priority = fields.Integer(
string="Max reservation priority on the entire folio",
help="Max reservation priority on the entire folio",
compute="_compute_max_reservation_priority",
store=True,
)
invoice_status = fields.Selection(
string="Invoice Status",
help="Invoice Status; it can be: invoiced, to invoice, to confirm, no",
Expand Down Expand Up @@ -1368,12 +1362,6 @@
}
return vals

@api.depends("reservation_ids", "reservation_ids.priority")
def _compute_max_reservation_priority(self):
for record in self.filtered("reservation_ids"):
reservation_priors = record.reservation_ids.mapped("priority")
record.max_reservation_priority = max(reservation_priors)

def _compute_checkin_partner_count(self):
for record in self:
if (
Expand Down Expand Up @@ -2196,7 +2184,7 @@
# Review: force to autoreconcile payment with invoices already created
pay.flush()
for move in folio.move_ids:
move._autoreconcile_folio_payments()
move.sudo()._autoreconcile_folio_payments()

Check warning on line 2187 in pms/models/pms_folio.py

View check run for this annotation

Codecov / codecov/patch

pms/models/pms_folio.py#L2187

Added line #L2187 was not covered by tests

# Automatic register payment in cash register
# TODO: cash_register to avoid flow in the new api (delete it in the future)
Expand Down
77 changes: 0 additions & 77 deletions pms/models/pms_reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ class PmsReservation(models.Model):
help="Techinal field to get reservation name",
readonly=True,
)
priority = fields.Integer(
string="Priority",
help="Priority of a reservation",
store="True",
compute="_compute_priority",
)
preferred_room_id = fields.Many2one(
string="Room",
help="It's the preferred room assigned to reservation, "
Expand Down Expand Up @@ -772,71 +766,6 @@ def _compute_check_adults(self):
for record in self:
record.check_adults = True

@api.depends(
"checkin",
"checkout",
"state",
"folio_payment_state",
"to_assign",
)
def _compute_priority(self):
# TODO: Notifications priority
for record in self:
if record.to_assign or record.state in (
"arrival_delayed",
"departure_delayed",
):
record.priority = 1
elif record.state == "cancel":
record.priority = record.cancel_priority()
elif record.state == "onboard":
record.priority = record.onboard_priority()
elif record.state in ("draf", "confirm"):
record.priority = record.reservations_future_priority()
elif record.state == "done":
record.priority = record.reservations_past_priority()

def cancel_priority(self):
self.ensure_one()
if self.folio_pending_amount > 0:
return 2
elif self.checkout >= fields.date.today():
return 100
else:
return 1000 * (fields.date.today() - self.checkout).days

def onboard_priority(self):
self.ensure_one()
days_for_checkout = (self.checkout - fields.date.today()).days
if self.folio_pending_amount > 0:
return days_for_checkout
else:
return 3 * days_for_checkout

def reservations_future_priority(self):
self.ensure_one()
days_for_checkin = (self.checkin - fields.date.today()).days
if days_for_checkin < 3:
return 2 * days_for_checkin
elif days_for_checkin < 20:
return 3 * days_for_checkin
else:
return 4 * days_for_checkin

def reservations_past_priority(self):
self.ensure_one()
if self.folio_pending_amount > 0:
return 3
days_from_checkout = (fields.date.today() - self.checkout).days
if days_from_checkout <= 1:
return 6
elif days_from_checkout < 15:
return 5 * days_from_checkout
elif days_from_checkout <= 90:
return 10 * days_from_checkout
elif days_from_checkout > 90:
return 100 * days_from_checkout

@api.depends("pricelist_id", "room_type_id")
def _compute_board_service_room_id(self):
for reservation in self:
Expand Down Expand Up @@ -2341,12 +2270,6 @@ def autocheckout(self, reservation):
)
return True

@api.model
def update_daily_priority_reservation(self):
reservations = self.env["pms.reservation"].search([("priority", "<", 1000)])
reservations._compute_priority()
return True

def action_confirm(self):
for record in self:
vals = {}
Expand Down
35 changes: 0 additions & 35 deletions pms/tests/test_pms_folio.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,41 +363,6 @@ def test_reservation_agency_without_partner(self):
reservation1.agency_id, folio1.partner_id, "Agency has to be the partner"
)

# TestCases: Priority

def test_compute_folio_priority(self):
"""
Check the priority of a folio based on its reservations
#TODO: Commented test waiting to redefine the priority calculation
"""
# reservation1 = self.env["pms.reservation"].create(
# {
# "checkin": fields.date.today(),
# "checkout": fields.date.today() + datetime.timedelta(days=1),
# "room_type_id": self.room_type_double.id,
# "partner_id": self.env.ref("base.res_partner_12").id,
# "pms_property_id": self.property.id,
# }
# )
# reservation1.allowed_checkin = False

# self.env["pms.reservation"].create(
# {
# "folio_id": reservation1.folio_id.id,
# "checkin": fields.date.today(),
# "checkout": fields.date.today() + datetime.timedelta(days=1),
# "room_type_id": self.room_type_double.id,
# "partner_id": self.env.ref("base.res_partner_12").id,
# "pms_property_id": self.property.id,
# }
# )

# self.assertEqual(
# reservation1.priority,
# reservation1.folio_id.max_reservation_priority,
# "The max. reservation priority on the whole folio is incorrect",
# )

# TestCases: Payments
@freeze_time("2000-02-02")
def test_full_pay_folio(self):
Expand Down
Loading
Loading