Add revenue forecast

This commit is contained in:
oscar alvarez 2022-12-19 15:35:02 -05:00
parent 5c91e7067b
commit 64bce42915
8 changed files with 53 additions and 42 deletions

View File

@ -60,7 +60,7 @@ def register():
booking.SelectRoomsAsk,
booking.BookingVoucher,
booking.RoomsOccupancyStart,
booking.BookingForecastStart,
booking.RevenueForecastStart,
booking.UpdateHolderStart,
booking.BookingChannelCommision,
booking.BillBookingStart,
@ -101,7 +101,7 @@ def register():
module='hotel', type_='model')
Pool.register(
booking.BookingReport,
booking.BookingForecastReport,
booking.RevenueForecastReport,
booking.RoomsOccupancyReport,
booking.BookingStatusReport,
booking.ManagerReport,
@ -117,7 +117,7 @@ def register():
module='hotel', type_='report')
Pool.register(
booking.SelectRooms,
booking.BookingForecast,
booking.RevenueForecast,
booking.RoomsOccupancy,
booking.BookingStatus,
booking.UpdateHolder,

View File

@ -1383,14 +1383,14 @@ class BookingStatementLine(ModelSQL):
__name__ = 'hotel.booking-statement.line'
_table = 'hotel_booking_statement_line_rel'
booking = fields.Many2One('hotel.booking', 'Booking',
ondelete='CASCADE', select=True, required=True)
ondelete='CASCADE', select=True, required=True)
statement_line = fields.Many2One('account.statement.line',
'Statement Line', ondelete='CASCADE', required=True)
class BookingForecastStart(ModelView):
'Booking Forecast Start'
__name__ = 'hotel.print_booking_forecast.start'
class RevenueForecastStart(ModelView):
'Revenue Forecast Start'
__name__ = 'hotel.print_revenue_forecast.start'
date = fields.Date('Start Date', required=True)
company = fields.Many2One('company.company', 'Company', required=True)
@ -1404,16 +1404,16 @@ class BookingForecastStart(ModelView):
return Transaction().context.get('company')
class BookingForecast(Wizard):
'Booking Forecast'
__name__ = 'hotel.print_booking_forecast'
class RevenueForecast(Wizard):
'Revenue Forecast'
__name__ = 'hotel.print_revenue_forecast'
start = StateView(
'hotel.print_booking_forecast.start',
'hotel.print_booking_forecast_start_view_form', [
'hotel.print_revenue_forecast.start',
'hotel.print_revenue_forecast_start_view_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Print', 'print_', 'tryton-print', default=True),
])
print_ = StateReport('hotel.booking_forecast.report')
print_ = StateReport('hotel.revenue_forecast.report')
def do_print_(self, action):
company = self.start.company
@ -1427,13 +1427,13 @@ class BookingForecast(Wizard):
return 'end'
class BookingForecastReport(Report):
__name__ = 'hotel.booking_forecast.report'
class RevenueForecastReport(Report):
__name__ = 'hotel.revenue_forecast.report'
@classmethod
def get_context(cls, records, header, data):
report_context = super().get_context(records, header, data)
MAX_DAYS = 30
MAX_DAYS = 31
pool = Pool()
Company = pool.get('company.company')
Room = pool.get('hotel.room')
@ -1442,6 +1442,8 @@ class BookingForecastReport(Report):
rooms = Room.search([])
alldays = {}
alldays_convert = {}
data['revenue'] = 0
data['occupancy_rate'] = 0
for nd in range(MAX_DAYS):
day_n = 'day' + str((nd + 1))
tdate = data['date'] + timedelta(nd)
@ -1455,19 +1457,21 @@ class BookingForecastReport(Report):
date_init = data['date']
date_limit = data['date'] + timedelta(MAX_DAYS)
dom = [['OR', [
dom = [
['OR', [
('arrival_date', '<=', date_init),
('departure_date', '>=', date_init),
], [
('arrival_date', '>=', date_init),
('arrival_date', '<=', date_limit),
],
], ('booking.state', 'not in', ['no_show', 'cancelled'])]
], ('booking.state', 'not in', ['no_show', 'cancelled'])]
lines = BookingFolio.search(dom)
drooms = {}
available_nights = len(rooms) * MAX_DAYS
nights = 0
for room in rooms:
drooms[room.id] = {'name': room.name}
drooms[room.id].update(alldays.copy())
@ -1478,17 +1482,24 @@ class BookingForecastReport(Report):
dt = line.arrival_date + timedelta(i)
if dt >= date_init and dt < date_limit \
and dt >= data['date']:
revenue_day = float(line.unit_price) / 1000000
dayn = alldays_convert[dt]
drooms[line.room.id][dayn] = "X"
drooms[line.room.id][dayn] = revenue_day
data['total_' + dayn] += 1
data['revenue_' + dayn] += float(line.unit_price) / 1000000
data['revenue_' + dayn] += revenue_day
data['revenue'] += float(line.unit_price)
nights += 1
for i in range(MAX_DAYS):
day_n = 'day' + str((i + 1))
data['rate_' + day_n] = (data['total_' + day_n] * 100.0) / len(rooms)
if nights > 0:
data['occupancy_rate'] = float(available_nights / nights)
report_context['records'] = list(drooms.values())
report_context['date'] = data['date']
report_context['company'] = Company(data['company']).party.name
report_context['company'] = Company(data['company'])
return report_context

View File

@ -95,16 +95,16 @@ this repository contains the full copyright notices and license terms. -->
<field name="name">booking_folio_form</field>
</record>
<record model="ir.ui.view" id="booking_forecast_view_tree">
<field name="model">hotel.booking_forecast</field>
<!-- <record model="ir.ui.view" id="revenue_forecast_view_tree">
<field name="model">hotel.revenue_forecast</field>
<field name="type">tree</field>
<field name="name">booking_forecast_tree</field>
<field name="name">revenue_forecast_tree</field>
</record>
<record model="ir.ui.view" id="booking_forecast_view_form">
<field name="model">hotel.booking_forecast</field>
<record model="ir.ui.view" id="revenue_forecast_view_form">
<field name="model">hotel.revenue_forecast</field>
<field name="type">form</field>
<field name="name">booking_forecast_form</field>
</record>
<field name="name">revenue_forecast_form</field>
</record> -->
<record model="ir.model.button" id="booking_cancel_button">
<field name="name">cancel</field>
@ -218,24 +218,24 @@ this repository contains the full copyright notices and license terms. -->
<menuitem parent="hotel.menu_reporting" id="menu_rooms_occupancy"
action="wizard_print_rooms_occupancy"/>
<record model="ir.action.report" id="report_booking_forecast">
<field name="name">Booking Forecast Report</field>
<record model="ir.action.report" id="report_revenue_forecast">
<field name="name">Revenue Forecast Report</field>
<field name="model"></field>
<field name="report_name">hotel.booking_forecast.report</field>
<field name="report">hotel/booking_forecast.fods</field>
<field name="report_name">hotel.revenue_forecast.report</field>
<field name="report">hotel/revenue_forecast.fods</field>
<field name="template_extension">ods</field>
</record>
<record model="ir.ui.view" id="print_booking_forecast_start_view_form">
<field name="model">hotel.print_booking_forecast.start</field>
<record model="ir.ui.view" id="print_revenue_forecast_start_view_form">
<field name="model">hotel.print_revenue_forecast.start</field>
<field name="type">form</field>
<field name="name">booking_forecast_start_form</field>
<field name="name">revenue_forecast_start_form</field>
</record>
<record model="ir.action.wizard" id="wizard_print_booking_forecast">
<field name="name">Booking Forecast</field>
<field name="wiz_name">hotel.print_booking_forecast</field>
<record model="ir.action.wizard" id="wizard_print_revenue_forecast">
<field name="name">Renevue Forecast</field>
<field name="wiz_name">hotel.print_revenue_forecast</field>
</record>
<menuitem parent="hotel.menu_reporting" id="menu_booking_forecast"
action="wizard_print_booking_forecast"/>
<menuitem parent="hotel.menu_reporting" id="menu_revenue_forecast"
action="wizard_print_revenue_forecast"/>
<record model="ir.action.report" id="report_guests_list">
<field name="name">Guests List Report</field>

Binary file not shown.

Binary file not shown.

BIN
revenue_forecast.fods Normal file

Binary file not shown.

View File

@ -1,5 +1,5 @@
[tryton]
version=6.0.62
version=6.0.63
depends:
party
company