Skip to content

Commit

Permalink
[IMP]pms: improvement compute pricelist_id in folio and reservation
Browse files Browse the repository at this point in the history
  • Loading branch information
DarioLodeiros committed Oct 23, 2023
1 parent 6022f20 commit 89b4c85
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 4 additions & 2 deletions pms/models/pms_folio.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,14 +882,16 @@ def _compute_company_id(self):
)
def _compute_pricelist_id(self):
for folio in self:
is_new = not folio.pricelist_id or not isinstance(folio.id, models.NewId)
if folio.reservation_type in ("out", "staff"):
folio.pricelist_id = False
elif len(folio.reservation_ids.pricelist_id) == 1:
folio.pricelist_id = folio.reservation_ids.pricelist_id
elif folio.agency_id and folio.agency_id.apply_pricelist:
elif folio.agency_id and folio.agency_id.apply_pricelist and is_new:
folio.pricelist_id = folio.agency_id.property_product_pricelist
elif (
folio.partner_id
is_new
and folio.partner_id
and folio.partner_id.property_product_pricelist
and folio.partner_id.property_product_pricelist.is_pms_available
):
Expand Down
16 changes: 10 additions & 6 deletions pms/models/pms_reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,22 +1018,26 @@ def _compute_service_ids(self):
@api.depends("partner_id", "agency_id")
def _compute_pricelist_id(self):
for reservation in self:
is_new = not reservation.pricelist_id or not isinstance(
reservation.id, models.NewId
)
if reservation.reservation_type in ("out", "staff"):
reservation.pricelist_id = False
elif reservation.agency_id and reservation.agency_id.apply_pricelist:
elif (
is_new
and reservation.agency_id
and reservation.agency_id.apply_pricelist
):
reservation.pricelist_id = (
reservation.agency_id.property_product_pricelist
)
# only change de pricelist if the reservation is not yet saved
# and the partner has a pricelist default
elif (
reservation.partner_id
is_new
and reservation.partner_id
and reservation.partner_id.property_product_pricelist
and reservation.partner_id.property_product_pricelist.is_pms_available
and (
not reservation.pricelist_id
or not isinstance(reservation.id, models.NewId)
)
):
reservation.pricelist_id = (
reservation.partner_id.property_product_pricelist
Expand Down

0 comments on commit 89b4c85

Please sign in to comment.