mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
@@ -763,11 +763,10 @@ class PmsFolio(models.Model):
|
||||
@api.depends("reservation_ids", "reservation_ids.commission_amount")
|
||||
def _compute_commission(self):
|
||||
for folio in self:
|
||||
folio.commission = 0
|
||||
for reservation in folio.reservation_ids:
|
||||
if reservation.commission_amount != 0:
|
||||
folio.commission += reservation.commission_amount
|
||||
else:
|
||||
folio.commission = 0
|
||||
folio.commission = folio.commission + reservation.commission_amount
|
||||
|
||||
@api.depends("agency_id")
|
||||
def _compute_channel_type_id(self):
|
||||
|
||||
@@ -1204,13 +1204,22 @@ class PmsReservation(models.Model):
|
||||
else:
|
||||
reservation.commission_percent = 0
|
||||
|
||||
@api.depends("commission_percent", "price_total")
|
||||
@api.depends("commission_percent", "price_total", "service_ids")
|
||||
def _compute_commission_amount(self):
|
||||
for reservation in self:
|
||||
if reservation.commission_percent > 0:
|
||||
reservation.commission_amount = (
|
||||
reservation.price_total * reservation.commission_percent / 100
|
||||
)
|
||||
if reservation.service_ids:
|
||||
for service in reservation.service_ids:
|
||||
if service.is_board_service:
|
||||
reservation.commission_amount = (
|
||||
reservation.commission_amount
|
||||
+ service.price_total
|
||||
* reservation.commission_percent
|
||||
/ 100
|
||||
)
|
||||
else:
|
||||
reservation.commission_amount = 0
|
||||
|
||||
|
||||
@@ -133,8 +133,6 @@ class TestPmsFolio(TestPms):
|
||||
"""
|
||||
# ARRANGE
|
||||
self.create_sale_channel_scenario()
|
||||
commission = (20 + 20 + 20) * 0.15
|
||||
|
||||
# ACT
|
||||
folio1 = self.env["pms.folio"].create(
|
||||
{
|
||||
@@ -175,9 +173,151 @@ class TestPmsFolio(TestPms):
|
||||
],
|
||||
}
|
||||
)
|
||||
self.commission = 0
|
||||
for reservation in folio1.reservation_ids:
|
||||
self.commission = (
|
||||
self.commission
|
||||
+ reservation.price_total * self.agency1.default_commission / 100
|
||||
)
|
||||
|
||||
# ASSERT
|
||||
self.assertEqual(
|
||||
commission, folio1.commission, "The folio compute commission is wrong"
|
||||
self.commission, folio1.commission, "The folio compute commission is wrong"
|
||||
)
|
||||
|
||||
def test_folio_commission(self):
|
||||
"""
|
||||
Check commission of a folio with several reservations that have commission
|
||||
"""
|
||||
# ARRANGE
|
||||
self.create_sale_channel_scenario()
|
||||
|
||||
# ACT
|
||||
folio1 = self.env["pms.folio"].create(
|
||||
{
|
||||
"agency_id": self.agency1.id,
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
}
|
||||
)
|
||||
|
||||
self.env["pms.reservation"].create(
|
||||
{
|
||||
"folio_id": folio1.id,
|
||||
"room_type_id": self.room_type_double.id,
|
||||
"reservation_line_ids": [
|
||||
(
|
||||
0,
|
||||
False,
|
||||
{
|
||||
"date": fields.date.today(),
|
||||
"price": 20,
|
||||
},
|
||||
),
|
||||
],
|
||||
}
|
||||
)
|
||||
self.env["pms.reservation"].create(
|
||||
{
|
||||
"folio_id": folio1.id,
|
||||
"room_type_id": self.room_type_double.id,
|
||||
"reservation_line_ids": [
|
||||
(
|
||||
0,
|
||||
False,
|
||||
{
|
||||
"date": fields.date.today(),
|
||||
"price": 40,
|
||||
},
|
||||
),
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
self.commission = 0
|
||||
for reservation in folio1.reservation_ids:
|
||||
if reservation.commission_amount != 0:
|
||||
self.commission = (
|
||||
self.commission
|
||||
+ reservation.price_total * self.agency1.default_commission / 100
|
||||
)
|
||||
self.folio_commission = folio1.commission
|
||||
# ASSERT
|
||||
self.assertEqual(
|
||||
self.commission,
|
||||
self.folio_commission,
|
||||
"The folio compute commission is wrong",
|
||||
)
|
||||
|
||||
def test_folio_commission_with_reservations_without_commission(self):
|
||||
"""
|
||||
Check commission of a folio with several reservations,
|
||||
of which the last hasn't commission
|
||||
|
||||
--- folio1:
|
||||
-reservation1: commission 15% --> commission amount 3.00
|
||||
-reservation2: commission 0% --> commission amount 0.00
|
||||
|
||||
folio1 commission --> 3.00
|
||||
"""
|
||||
# ARRANGE
|
||||
self.create_sale_channel_scenario()
|
||||
|
||||
# ACT
|
||||
|
||||
folio1 = self.env["pms.folio"].create(
|
||||
{
|
||||
"agency_id": self.agency1.id,
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
}
|
||||
)
|
||||
|
||||
self.env["pms.reservation"].create(
|
||||
{
|
||||
"folio_id": folio1.id,
|
||||
"room_type_id": self.room_type_double.id,
|
||||
"reservation_line_ids": [
|
||||
(
|
||||
0,
|
||||
False,
|
||||
{
|
||||
"date": fields.date.today(),
|
||||
"price": 20,
|
||||
},
|
||||
),
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
self.env["pms.reservation"].create(
|
||||
{
|
||||
"folio_id": folio1.id,
|
||||
"room_type_id": self.room_type_double.id,
|
||||
"reservation_line_ids": [
|
||||
(
|
||||
0,
|
||||
False,
|
||||
{
|
||||
"date": fields.date.today(),
|
||||
"price": 40,
|
||||
},
|
||||
),
|
||||
],
|
||||
"commission_percent": 0,
|
||||
}
|
||||
)
|
||||
self.commission = 0
|
||||
for reservation in folio1.reservation_ids:
|
||||
if reservation.commission_amount != 0:
|
||||
self.commission = (
|
||||
self.commission
|
||||
+ reservation.price_total * self.agency1.default_commission / 100
|
||||
)
|
||||
self.folio_commission = folio1.commission
|
||||
# ASSERT
|
||||
self.assertEqual(
|
||||
self.commission,
|
||||
self.folio_commission,
|
||||
"The folio compute commission is wrong",
|
||||
)
|
||||
|
||||
def test_reservation_agency_without_partner(self):
|
||||
|
||||
@@ -90,6 +90,18 @@ class TestPmsReservations(TestPms):
|
||||
self.id_category = self.env["res.partner.id_category"].create(
|
||||
{"name": "DNI", "code": "D"}
|
||||
)
|
||||
self.sale_channel1 = self.env["pms.sale.channel"].create(
|
||||
{"name": "saleChannel1", "channel_type": "indirect"}
|
||||
)
|
||||
self.agency1 = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "partner1",
|
||||
"is_agency": True,
|
||||
"invoice_to_agency": True,
|
||||
"default_commission": 15,
|
||||
"sale_channel_id": self.sale_channel1.id,
|
||||
}
|
||||
)
|
||||
|
||||
def test_reservation_dates_not_consecutive(self):
|
||||
"""
|
||||
@@ -3619,3 +3631,96 @@ class TestPmsReservations(TestPms):
|
||||
msg="A partner must be added to the reservation",
|
||||
):
|
||||
several_partners_wizard.add_partner()
|
||||
|
||||
@freeze_time("1991-11-10")
|
||||
def test_commission_amount_with_board_service(self):
|
||||
"""
|
||||
Check if commission in reservation is correctly calculated
|
||||
when reservation has services and board_services
|
||||
|
||||
Create a service that isn't board service.
|
||||
Create a service that is board service.
|
||||
Create a reservation with that service and board_service.
|
||||
|
||||
In this case when the reservation is made through an agency
|
||||
that has a default commission, this commission is applied to the
|
||||
price of the room and the price of services that correspond with
|
||||
board service.
|
||||
|
||||
"""
|
||||
# ARRANGE
|
||||
self.product1 = self.env["product.product"].create(
|
||||
{
|
||||
"name": "Product test1",
|
||||
"per_day": True,
|
||||
"consumed_on": "after",
|
||||
"is_extra_bed": True,
|
||||
}
|
||||
)
|
||||
self.service = self.env["pms.service"].create(
|
||||
{
|
||||
"is_board_service": False,
|
||||
"product_id": self.product1.id,
|
||||
}
|
||||
)
|
||||
self.service.flush()
|
||||
self.product_test1 = self.env["product.product"].create(
|
||||
{
|
||||
"name": "Test Product 1",
|
||||
"per_day": True,
|
||||
"consumed_on": "after",
|
||||
}
|
||||
)
|
||||
self.board_service_test = self.env["pms.board.service"].create(
|
||||
{
|
||||
"name": "Test Board Service",
|
||||
"default_code": "TPS",
|
||||
}
|
||||
)
|
||||
self.env["pms.board.service.line"].create(
|
||||
{
|
||||
"pms_board_service_id": self.board_service_test.id,
|
||||
"product_id": self.product_test1.id,
|
||||
"amount": 8,
|
||||
}
|
||||
)
|
||||
self.board_service_room_type = self.env["pms.board.service.room.type"].create(
|
||||
{
|
||||
"pms_room_type_id": self.room_type_double.id,
|
||||
"pms_board_service_id": self.board_service_test.id,
|
||||
}
|
||||
)
|
||||
checkin = fields.date.today()
|
||||
checkout = checkin + datetime.timedelta(days=11)
|
||||
reservation_vals = {
|
||||
"checkin": checkin,
|
||||
"checkout": checkout,
|
||||
"room_type_id": self.room_type_double.id,
|
||||
"partner_id": self.partner1.id,
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"agency_id": self.agency1.id,
|
||||
"service_ids": [self.service.id],
|
||||
}
|
||||
# ACT
|
||||
reservation = self.env["pms.reservation"].create(reservation_vals)
|
||||
|
||||
reservation.write(
|
||||
{
|
||||
"board_service_room_id": self.board_service_room_type.id,
|
||||
}
|
||||
)
|
||||
|
||||
self.commission = (
|
||||
reservation.price_total * self.agency1.default_commission / 100
|
||||
)
|
||||
for service in reservation.service_ids:
|
||||
if service.is_board_service:
|
||||
self.commission = (
|
||||
self.commission
|
||||
+ service.price_total * self.agency1.default_commission / 100
|
||||
)
|
||||
self.assertEqual(
|
||||
self.commission,
|
||||
reservation.commission_amount,
|
||||
"Reservation commission is wrong",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user