This commit is contained in:
parent
64e911dda1
commit
8db81e40ea
@ -187,12 +187,22 @@ class HmsBookings(models.Model):
|
|||||||
booking_status = fields.Many2one(comodel_name="hms.booking.status", string="Booking Status", compute="_compute_checkin_checkout_date", store=True)
|
booking_status = fields.Many2one(comodel_name="hms.booking.status", string="Booking Status", compute="_compute_checkin_checkout_date", store=True)
|
||||||
status = fields.Many2one(comodel_name="hms.status", string="Status", compute="_compute_checkin_checkout_date", store=True)
|
status = fields.Many2one(comodel_name="hms.status", string="Status", compute="_compute_checkin_checkout_date", store=True)
|
||||||
|
|
||||||
|
booking_status_text = fields.Char(string="Booking Status ", compute="_compute_checkin_checkout_date", store=True)
|
||||||
|
show_booking_status = fields.Boolean(string="Show Booking Status", compute="_compute_checkin_checkout_date", store=True)
|
||||||
|
|
||||||
|
status_text = fields.Char(string="Status ", compute="_compute_checkin_checkout_date", store=True)
|
||||||
|
show_status = fields.Boolean(string="Show Status", compute="_compute_checkin_checkout_date", store=True)
|
||||||
|
|
||||||
@api.depends('roomStays', 'payment_ids')
|
@api.depends('roomStays', 'payment_ids')
|
||||||
def _compute_checkin_checkout_date(self):
|
def _compute_checkin_checkout_date(self):
|
||||||
for booking in self:
|
for booking in self:
|
||||||
# Status fields
|
# Status fields
|
||||||
|
booking.show_booking_status = False
|
||||||
|
booking.show_status = False
|
||||||
if booking.roomStays.filtered(lambda stay: stay.bookingStatus.name == 'Confirmed'):
|
if booking.roomStays.filtered(lambda stay: stay.bookingStatus.name == 'Confirmed'):
|
||||||
booking.booking_status = self.env['hms.booking.status'].search([('name', '=', 'Confirmed')]).id
|
booking.booking_status = self.env['hms.booking.status'].search([('name', '=', 'Confirmed')]).id
|
||||||
|
booking.booking_status_text = f"Confirmed {len(booking.roomStays.filtered(lambda stay: stay.bookingStatus.name == 'Confirmed'))} / {len(booking.roomStays)}"
|
||||||
|
booking.show_booking_status = True
|
||||||
elif not booking.roomStays.filtered(lambda stay: stay.bookingStatus.name != 'Cancelled'):
|
elif not booking.roomStays.filtered(lambda stay: stay.bookingStatus.name != 'Cancelled'):
|
||||||
booking.booking_status = self.env['hms.booking.status'].search([('name', '=', 'Cancelled')]).id
|
booking.booking_status = self.env['hms.booking.status'].search([('name', '=', 'Cancelled')]).id
|
||||||
elif not booking.roomStays.filtered(lambda stay: stay.bookingStatus.name != 'Pending'):
|
elif not booking.roomStays.filtered(lambda stay: stay.bookingStatus.name != 'Pending'):
|
||||||
@ -201,9 +211,15 @@ class HmsBookings(models.Model):
|
|||||||
if not booking.roomStays.filtered(lambda stay: stay.status.name == 'CheckedIn') and not booking.roomStays.filtered(lambda stay: stay.status.name == 'CheckedOut') and booking.roomStays.filtered(lambda stay: stay.status.name == 'New'):
|
if not booking.roomStays.filtered(lambda stay: stay.status.name == 'CheckedIn') and not booking.roomStays.filtered(lambda stay: stay.status.name == 'CheckedOut') and booking.roomStays.filtered(lambda stay: stay.status.name == 'New'):
|
||||||
booking.status = self.env['hms.status'].search([('name', '=', 'Upcoming')]).id
|
booking.status = self.env['hms.status'].search([('name', '=', 'Upcoming')]).id
|
||||||
elif booking.roomStays.filtered(lambda stay: stay.status.name == 'CheckedIn'):
|
elif booking.roomStays.filtered(lambda stay: stay.status.name == 'CheckedIn'):
|
||||||
booking.status = self.env['hms.status'].search([('name', '=', 'CheckedIn')]).id
|
checked_in_records = self.env['hms.status'].search([('name', '=', 'CheckedIn')])
|
||||||
|
booking.status = checked_in_records.id
|
||||||
|
booking.status_text = f"CheckedIn ({len(booking.roomStays.filtered(lambda stay: stay.status.name == 'CheckedIn'))} / {len(booking.roomStays)})"
|
||||||
|
booking.show_status = True
|
||||||
elif booking.roomStays.filtered(lambda stay: stay.status.name == 'CheckedOut'):
|
elif booking.roomStays.filtered(lambda stay: stay.status.name == 'CheckedOut'):
|
||||||
booking.status = self.env['hms.status'].search([('name', '=', 'CheckedOut')]).id
|
checked_out_records = self.env['hms.status'].search([('name', '=', 'CheckedOut')])
|
||||||
|
booking.status = checked_out_records.id
|
||||||
|
booking.status_text = f"CheckedOut ({len(booking.roomStays.filtered(lambda stay: stay.status.name == 'CheckedOut'))} / {len(booking.roomStays)})"
|
||||||
|
booking.show_status = True
|
||||||
elif not booking.roomStays.filtered(lambda stay: stay.status.name != 'Cancelled'):
|
elif not booking.roomStays.filtered(lambda stay: stay.status.name != 'Cancelled'):
|
||||||
booking.status = self.env['hms.status'].search([('name', '=', 'Cancelled')]).id
|
booking.status = self.env['hms.status'].search([('name', '=', 'Cancelled')]).id
|
||||||
elif not booking.roomStays.filtered(lambda stay: stay.status.name != 'No Show'):
|
elif not booking.roomStays.filtered(lambda stay: stay.status.name != 'No Show'):
|
||||||
@ -311,6 +327,15 @@ class HmsBookings(models.Model):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# @api.model
|
||||||
|
# def _get_contextual_booking(self):
|
||||||
|
# ctx = self.env.context
|
||||||
|
# if self.env.context.get('booking_id') is not None:
|
||||||
|
# return self.browse(ctx.get('booking_id'))
|
||||||
|
# if self.env.context.get('default_booking_id') is not None:
|
||||||
|
# return self.browse(ctx.get('default_booking_id'))
|
||||||
|
# return False
|
||||||
|
|
||||||
|
|
||||||
class HmsStatus(models.Model):
|
class HmsStatus(models.Model):
|
||||||
_name = 'hms.status'
|
_name = 'hms.status'
|
||||||
@ -318,6 +343,41 @@ class HmsStatus(models.Model):
|
|||||||
|
|
||||||
name = fields.Char(string="Status", required=True)
|
name = fields.Char(string="Status", required=True)
|
||||||
|
|
||||||
|
# total_roomstays = fields.Integer(string="Total Roomstays", compute="_compute_roomstays")
|
||||||
|
# checkedin_count = fields.Integer(string="CheckedIn", compute="_compute_roomstays")
|
||||||
|
# checkedout_count = fields.Integer(string="CheckedOut", compute="_compute_roomstays")
|
||||||
|
|
||||||
|
# def requested_display_name(self):
|
||||||
|
# return self._context.get('status_display_name', True) and self._context.get('booking_id')
|
||||||
|
|
||||||
|
# @api.depends_context('booking_id', 'default_booking_id')
|
||||||
|
# def _compute_roomstays(self):
|
||||||
|
# booking_id = self.env['hms.bookings']._get_contextual_booking()
|
||||||
|
# if booking_id:
|
||||||
|
# if booking_id.roomStays:
|
||||||
|
# total_roomstays = len(booking_id.roomStays)
|
||||||
|
# checkedin_count = len(booking_id.roomStays.filtered(lambda stay: stay.status.name == 'CheckedIn'))
|
||||||
|
# checkedout_count = len(booking_id.roomStays.filtered(lambda stay: stay.status.name == 'CheckedOut'))
|
||||||
|
# else:
|
||||||
|
# total_roomstays = 0
|
||||||
|
# checkedin_count = 0
|
||||||
|
# checkedout_count = 0
|
||||||
|
# self.total_roomstays = total_roomstays
|
||||||
|
# self.checkedin_count = checkedin_count
|
||||||
|
# self.checkedout_count = checkedout_count
|
||||||
|
|
||||||
|
# @api.depends('total_roomstays', 'checkedin_count', 'checkedin_count')
|
||||||
|
# @api.depends_context('status_display_name', 'booking_id', 'default_booking_id')
|
||||||
|
# def _compute_display_name(self):
|
||||||
|
# if not self.requested_display_name():
|
||||||
|
# return super()._compute_display_name()
|
||||||
|
# for record in self:
|
||||||
|
# if record.name == 'CheckedIn':
|
||||||
|
# name = _("%(name)s (%(time)g checkedin out of %(maximum)g days)", name=record.name, time=record.checkedin_count, maximum=record.total_roomstays)
|
||||||
|
# elif record.name == 'CheckedOut':
|
||||||
|
# name = _("%(name)s (%(time)g checkedout out of %(maximum)g days)", name=record.name, time=record.checkedout_count, maximum=record.total_roomstays)
|
||||||
|
# record.display_name = name
|
||||||
|
|
||||||
|
|
||||||
class HmsBookingStatus(models.Model):
|
class HmsBookingStatus(models.Model):
|
||||||
_name = 'hms.booking.status'
|
_name = 'hms.booking.status'
|
||||||
|
|||||||
@ -62,8 +62,15 @@
|
|||||||
<field name="to_be_paid"/>
|
<field name="to_be_paid"/>
|
||||||
<field name="expected_payment"/>
|
<field name="expected_payment"/>
|
||||||
<field name="currency" invisible="1"/>
|
<field name="currency" invisible="1"/>
|
||||||
<field name="booking_status"/>
|
|
||||||
<field name="status"/>
|
<field name="booking_status" invisible="booking_status_text == True" options="{'no_open': True, 'no_create': True, 'no_create_edit': True, 'no_quick_create': True}"/>
|
||||||
|
<field name="booking_status_text" invisible="booking_status_text == False"/>
|
||||||
|
|
||||||
|
<field name="status" invisible="show_status == True" options="{'no_open': True, 'no_create': True, 'no_create_edit': True, 'no_quick_create': True}"/>
|
||||||
|
<field name="status_text" invisible="show_status == False"/>
|
||||||
|
|
||||||
|
<field name="show_status" invisible="1"/>
|
||||||
|
<field name="booking_status_text" invisible="1"/>
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
@ -143,6 +150,8 @@
|
|||||||
<field name="view_ids" eval="[(5, 0, 0),
|
<field name="view_ids" eval="[(5, 0, 0),
|
||||||
(0, 0, {'view_mode': 'list', 'view_id': ref('view_hms_bookings_tree')}),
|
(0, 0, {'view_mode': 'list', 'view_id': ref('view_hms_bookings_tree')}),
|
||||||
(0, 0, {'view_mode': 'form', 'view_id': ref('view_hms_bookings_form')})]"/>
|
(0, 0, {'view_mode': 'form', 'view_id': ref('view_hms_bookings_form')})]"/>
|
||||||
|
<field name="context">{
|
||||||
|
'status_display_name': False}</field>
|
||||||
<field name="help" type="html">
|
<field name="help" type="html">
|
||||||
<p class="o_view_nocontent_smiling_face">
|
<p class="o_view_nocontent_smiling_face">
|
||||||
Create your first booking record.
|
Create your first booking record.
|
||||||
|
|||||||
@ -65,8 +65,15 @@
|
|||||||
<field name="to_be_paid"/>
|
<field name="to_be_paid"/>
|
||||||
<field name="expected_payment"/>
|
<field name="expected_payment"/>
|
||||||
<field name="currency" invisible="1"/>
|
<field name="currency" invisible="1"/>
|
||||||
<field name="booking_status"/>
|
|
||||||
<field name="status"/>
|
<field name="booking_status" invisible="booking_status_text == True" options="{'no_open': True, 'no_create': True, 'no_create_edit': True, 'no_quick_create': True}"/>
|
||||||
|
<field name="booking_status_text" invisible="booking_status_text == False"/>
|
||||||
|
|
||||||
|
<field name="status" invisible="show_status == True" options="{'no_open': True, 'no_create': True, 'no_create_edit': True, 'no_quick_create': True}"/>
|
||||||
|
<field name="status_text" invisible="show_status == False"/>
|
||||||
|
|
||||||
|
<field name="show_status" invisible="1"/>
|
||||||
|
<field name="booking_status_text" invisible="1"/>
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user