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):
|
||||
|
||||
Reference in New Issue
Block a user