Skip to content

Commit

Permalink
Merge pull request #146 from core-initiative/devel
Browse files Browse the repository at this point in the history
fix: Audit Report showing Reservation with Reserved status
  • Loading branch information
anhilmy authored May 6, 2024
2 parents 571713e + 8aad7d3 commit c0142cd
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 58 deletions.
3 changes: 1 addition & 2 deletions inn/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

__version__ = '1.1.2'

__version__ = '1.1.3'
126 changes: 70 additions & 56 deletions inn/inn_hotels/report/audit_report/audit_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from datetime import date

FILTER_FIELD_DATE = "expected_arrival"
FILTER_FIELD_STATUS = "status"
STATUS_RESERVED = "Reserved"
TRANSACTION_TYPE_ROOM_REVENUE = ""
TRANSACTION_TYPE_COMISSION = ""
TRANSACTION_TYPE_BREAKFAST_REVENUE = ""
Expand All @@ -10,106 +12,115 @@
BREAKFAST_REVENUE_ACCOUNT = ""
ROOM_REVENUE_ACCOUNT = ""


def execute(filters=None):
columns= [
columns = [
{
'fieldname': 'rsv',
'label': 'RSV',
'fieldtype': 'Data',
'width': 150,
'width': 150,
},
{
"fieldname": "status",
"label": "status",
"fieldtype": "Data",
"width": 150,
},
{
'fieldname': 'customer',
'label': 'Customer',
'fieldtype': 'Data',
'width': 150,
'width': 150,
},
{
'fieldname': 'room_type',
'label': 'Room Type',
'fieldtype': 'Data',
'width': 150,
'width': 150,
},
{
'fieldname': 'actual_room',
'label': 'Actual Room',
'fieldtype': 'Data',
'width': 150,
'width': 150,
},
{
'fieldname': 'actual_room_rate',
'label': 'Actual Room Rate',
'fieldtype': 'Currency',
'width': 150,
'width': 150,
},
{
'fieldname': 'actual_room_nett',
'label': 'Actual Room Nett',
'fieldtype': 'Currency',
'width': 150,
'width': 150,
},
{
'fieldname': 'bf_revenue',
'label': 'BF Revenue',
'fieldtype': 'Currency',
'width': 150,
'width': 150,
},
{
'fieldname': 'payment_by',
'label': 'Payment By',
'fieldtype': 'Data',
'width': 150,
'width': 150,
},
{
'fieldname': 'status',
'label': 'Status',
'fieldtype': 'Data',
'width': 150,
'width': 150,
},
{
'fieldname': 'mode_of_payment',
'label': 'Mode of Payment',
'fieldtype': 'Data',
'width': 150,
'width': 150,
},
{
'fieldname': 'total_amount',
'label': 'Total Amount',
'fieldtype': 'Currency',
'width': 150,
'width': 150,
},
{
'fieldname': 'paid_date',
'label': 'Paid Date',
'fieldtype': 'Date',
'width': 150,
'width': 150,
},
{
'fieldname': 'remark',
'label': 'Remark',
'fieldtype': 'Data',
'width': 150,
'width': 150,
}
]

data = get_data(filters)

return columns, data


def get_data(filters):
if filters.date == None:
filters.date = date.today().isoformat()

return get_data_detail(filters.date)


def get_data_detail(start_date):

query = f"""
select ir.name, ir.customer_id, ir.room_type, ir.actual_room_id, ir.channel, ir.actual_room_rate, if.name as folio, if.bill_instructions
select ir.name, ir.status, ir.customer_id, ir.room_type, ir.actual_room_id, ir.channel, ir.actual_room_rate, if.name as folio, if.bill_instructions
from `tabInn Reservation` as ir
left join `tabInn Folio` as `if`
on if.reservation_id = ir.name
where {FILTER_FIELD_DATE} = '{start_date}'
where {FILTER_FIELD_DATE} = '{start_date}' and {FILTER_FIELD_STATUS} != '{STATUS_RESERVED}'
"""

reservation = frappe.db.sql(query=query, as_dict=1)
Expand All @@ -119,42 +130,43 @@ def get_data_detail(start_date):
folio_name = tuple([x.folio for x in reservation])
folio_detail = get_folio_detail(folio_name)


res = [
[x.name,
x.customer_id,
x.room_type,
x.actual_room_id,
x.actual_room_rate,
folio_detail[x.folio]["actual_room_nett"],
folio_detail[x.folio]["breakfast_revenue"],
x.channel,
"",
folio_detail[x.folio]["mode_of_payment"][:-2],
[x.name,
x.customer_id,
x.room_type,
x.actual_room_id,
x.actual_room_rate,
folio_detail[x.folio]["actual_room_nett"],
folio_detail[x.folio]["breakfast_revenue"],
x.channel,
"",
folio_detail[x.folio]["mode_of_payment"][:-2],
folio_detail[x.folio]["total_amount"],
folio_detail[x.folio]["payment_date"],
folio_detail[x.folio]["payment_date"],
x.bill_instructions
]
for x in reservation]
]
for x in reservation]
return res


def get_folio_detail(folio_id: list):
# folio detail
# need data:
# need data:
# actual room nett, breakfast revenue, mode of payment, total_amount (payment_amount?), payment_date

fill_setting_data()
transaction_type_list = (TRANSACTION_TYPE_COMISSION, TRANSACTION_TYPE_ROOM_REVENUE, TRANSACTION_TYPE_BREAKFAST_REVENUE, TRANSACTION_TYPE_PAYMENT, TRANSACTION_TYPE_ROOM_PAYMENT)
transaction_type_list = (TRANSACTION_TYPE_COMISSION, TRANSACTION_TYPE_ROOM_REVENUE,
TRANSACTION_TYPE_BREAKFAST_REVENUE, TRANSACTION_TYPE_PAYMENT, TRANSACTION_TYPE_ROOM_PAYMENT)
query = f"""
select parent, transaction_type, amount, mode_of_payment, creation
from `tabInn Folio Transaction` as ift
where ift.parent in {folio_id}
and
ift.transaction_type in {transaction_type_list}
"""
"""
folio_detail = frappe.db.sql(query=query, as_dict=1)
res = { folio :{
"actual_room_nett" : 0,
res = {folio: {
"actual_room_nett": 0,
"breakfast_revenue": 0,
"mode_of_payment": "",
"total_amount": 0,
Expand All @@ -166,52 +178,54 @@ def get_folio_detail(folio_id: list):
if data.transaction_type == TRANSACTION_TYPE_ROOM_REVENUE:
res[data.parent]["actual_room_nett"] += data.amount
elif data.transaction_type == TRANSACTION_TYPE_PAYMENT or data.transaction_type == TRANSACTION_TYPE_ROOM_PAYMENT:
res[data.parent]["mode_of_payment"] += f"BY {data.mode_of_payment} {data.amount:,}".replace(",", ".") + ", "
res[data.parent]["mode_of_payment"] += f"BY {data.mode_of_payment} {data.amount:,}".replace(
",", ".") + ", "
res[data.parent]["total_amount"] += data.amount
res[data.parent]["payment_date"] += f"{data.creation}, "
elif data.transaction_type == TRANSACTION_TYPE_BREAKFAST_REVENUE:
res[data.parent]["breakfast_revenue"] += data.amount

return res




def fill_setting_data():
# get data setting
global TRANSACTION_TYPE_COMISSION, TRANSACTION_TYPE_ROOM_REVENUE, TRANSACTION_TYPE_BREAKFAST_REVENUE,TRANSACTION_TYPE_PAYMENT, TRANSACTION_TYPE_ROOM_PAYMENT, BREAKFAST_REVENUE_ACCOUNT, ROOM_REVENUE_ACCOUNT
transaction_type = frappe.db.get_values_from_single(fields=["profit_sharing_transaction_type", "room_revenue_transaction_type", "breakfast_revenue_transaction_type", "customer_payment_transaction_type", "customer_room_payment_transaction_type", "breakfast_revenue_account", "room_revenue_account"], filters="", doctype="Inn Hotels Setting", as_dict=True)[0]
global TRANSACTION_TYPE_COMISSION, TRANSACTION_TYPE_ROOM_REVENUE, TRANSACTION_TYPE_BREAKFAST_REVENUE, TRANSACTION_TYPE_PAYMENT, TRANSACTION_TYPE_ROOM_PAYMENT, BREAKFAST_REVENUE_ACCOUNT, ROOM_REVENUE_ACCOUNT
transaction_type = frappe.db.get_values_from_single(fields=["profit_sharing_transaction_type", "room_revenue_transaction_type", "breakfast_revenue_transaction_type", "customer_payment_transaction_type",
"customer_room_payment_transaction_type", "breakfast_revenue_account", "room_revenue_account"], filters="", doctype="Inn Hotels Setting", as_dict=True)[0]
if transaction_type.profit_sharing_transaction_type == None:
TRANSACTION_TYPE_COMISSION = "Comission Channel"
else:
else:
TRANSACTION_TYPE_COMISSION = transaction_type.profit_sharing_transaction_type

if transaction_type.room_revenue_transaction_type == None:
TRANSACTION_TYPE_ROOM_REVENUE = "Room Charge"
else:
else:
TRANSACTION_TYPE_ROOM_REVENUE = transaction_type.room_revenue_transaction_type

if transaction_type.breakfast_revenue_transaction_type == None:
TRANSACTION_TYPE_BREAKFAST_REVENUE = "Breakfast Charge"
else:
else:
TRANSACTION_TYPE_BREAKFAST_REVENUE = transaction_type.breakfast_revenue_transaction_type

if transaction_type.customer_payment_transaction_type == None:
TRANSACTION_TYPE_PAYMENT = "Payment"
else:
TRANSACTION_TYPE_PAYMENT = transaction_type.customer_payment_transaction_type
else:
TRANSACTION_TYPE_PAYMENT = transaction_type.customer_payment_transaction_type

if transaction_type.customer_room_payment_transaction_type == None:
TRANSACTION_TYPE_ROOM_PAYMENT = "Room Payment"
else:
TRANSACTION_TYPE_ROOM_PAYMENT = transaction_type.customer_room_payment_transaction_type
else:
TRANSACTION_TYPE_ROOM_PAYMENT = transaction_type.customer_room_payment_transaction_type

if transaction_type.breakfast_revenue_account == None:
raise ImportError("Breakfast Revenue Account in Inn Hotels Setting not set yet")
else:
BREAKFAST_REVENUE_ACCOUNT = transaction_type.breakfast_revenue_account

raise ImportError(
"Breakfast Revenue Account in Inn Hotels Setting not set yet")
else:
BREAKFAST_REVENUE_ACCOUNT = transaction_type.breakfast_revenue_account

if transaction_type.room_revenue_account == None:
raise ImportError("Room Revenue Account in Inn Hotels Setting not set yet")
else:
ROOM_REVENUE_ACCOUNT = transaction_type.room_revenue_account
raise ImportError(
"Room Revenue Account in Inn Hotels Setting not set yet")
else:
ROOM_REVENUE_ACCOUNT = transaction_type.room_revenue_account

0 comments on commit c0142cd

Please sign in to comment.