mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] Cancel Room Services
This commit is contained in:
@@ -980,6 +980,10 @@ class HotelReservation(models.Model):
|
||||
self.ensure_one()
|
||||
pricelist = self.pricelist_id
|
||||
if self.state == 'cancelled':
|
||||
#REVIEW: Set 0 qty on cancel room services (view constrain service_line_days)
|
||||
for service in self.service_ids:
|
||||
service.service_line_ids.write({'day_qty': 0})
|
||||
service._compute_days_qty()
|
||||
if self.cancelled_reason and pricelist and pricelist.cancelation_rule_id:
|
||||
date_start_dt = fields.Date.from_string(self.real_checkin or self.checkin)
|
||||
date_end_dt = fields.Date.from_string(self.real_checkout or self.checkout)
|
||||
|
||||
@@ -47,3 +47,14 @@ class HotelReservationLine(models.Model):
|
||||
)
|
||||
if duplicated:
|
||||
raise ValidationError(_('Duplicated reservation line date'))
|
||||
|
||||
@api.constrains('state')
|
||||
def constrains_service_cancel(self):
|
||||
for record in self:
|
||||
if record.state == 'cancelled':
|
||||
room_services = record.reservation_id.service_ids
|
||||
for service in room_services:
|
||||
cancel_lines = service.service_line_ids.filtered(
|
||||
lambda r: r.date == record.date
|
||||
)
|
||||
cancel_lines.day_qty = 0
|
||||
|
||||
@@ -30,18 +30,30 @@ class HotelServiceLine(models.Model):
|
||||
related="service_id.discount",
|
||||
readonly=True,
|
||||
store=True)
|
||||
cancel_discount = fields.Float('Discount', compute='_compute_cancel_discount')
|
||||
tax_ids = fields.Many2many('account.tax',
|
||||
string='Taxes',
|
||||
related="service_id.tax_ids",
|
||||
readonly="True")
|
||||
|
||||
def _cancel_discount(self):
|
||||
for record in self:
|
||||
if record.reservation_id:
|
||||
day = record.reservation_id.reservation_line_ids.filtered(
|
||||
lambda d: d.date == record.date
|
||||
)
|
||||
record.cancel_discount = day.cancel_discount
|
||||
|
||||
@api.depends('day_qty', 'service_id.price_total')
|
||||
def _compute_price_total(self):
|
||||
"""
|
||||
Used to reports
|
||||
"""
|
||||
for record in self:
|
||||
record.price_total = (record.service_id.price_total * record.day_qty) / record.service_id.product_qty
|
||||
if record.service_id.product_qty != 0:
|
||||
record.price_total = (record.service_id.price_total * record.day_qty) / record.service_id.product_qty
|
||||
else:
|
||||
record.price_total = 0
|
||||
|
||||
@api.constrains('day_qty')
|
||||
def no_free_resources(self):
|
||||
|
||||
@@ -323,22 +323,30 @@ class FolioAdvancePaymentInv(models.TransientModel):
|
||||
service.service_line_ids.filtered(
|
||||
lambda x: x.date == service_date).day_qty
|
||||
#group_key: if group by reservation, We no need group by room_type
|
||||
group_key = (reservation.id, reservation.room_type_id.id, day.price + extra_price, day.discount)
|
||||
date = fields.Date.from_string(day.date)
|
||||
group_key = (reservation.id, reservation.room_type_id.id,
|
||||
day.price + extra_price, day.discount,
|
||||
day.cancel_discount)
|
||||
if day.cancel_discount == 100:
|
||||
continue
|
||||
discount_factor = 1.0
|
||||
for discount in [day.discount, day.cancel_discount]:
|
||||
discount_factor = (
|
||||
discount_factor * ((100.0 - discount) / 100.0))
|
||||
final_discount = 100.0 - (discount_factor * 100.0)
|
||||
description = folio.name + ' ' + reservation.room_type_id.name + ' (' + \
|
||||
reservation.board_service_room_id.hotel_board_service_id.name + ')' \
|
||||
if board_service else folio.name + ' ' + reservation.room_type_id.name
|
||||
if group_key not in invoice_lines:
|
||||
invoice_lines[group_key] = {
|
||||
'description' : description,
|
||||
'reservation_id': reservation.id,
|
||||
'room_type_id': reservation.room_type_id,
|
||||
'product_id': self.env['product.product'].browse(
|
||||
reservation.room_type_id.product_id.id),
|
||||
'discount': day.discount,
|
||||
'price_unit': day.price + extra_price,
|
||||
'reservation_line_ids': [(4, day.id)]
|
||||
}
|
||||
'description': description,
|
||||
'reservation_id': reservation.id,
|
||||
'room_type_id': reservation.room_type_id,
|
||||
'product_id': self.env['product.product'].browse(
|
||||
reservation.room_type_id.product_id.id),
|
||||
'discount': final_discount,
|
||||
'price_unit': day.price + extra_price,
|
||||
'reservation_line_ids': [(4, day.id)]
|
||||
}
|
||||
else:
|
||||
invoice_lines[group_key][('reservation_line_ids')].append((4,day.id))
|
||||
for group_key in invoice_lines:
|
||||
|
||||
Reference in New Issue
Block a user