mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 11:19:09 +00:00
style: bulk format code with black
v13 port because otherwise backports will result in conflicts always
This commit is contained in:
@@ -9,5 +9,6 @@ from frappe.model.document import Document
|
||||
class HotelRoom(Document):
|
||||
def validate(self):
|
||||
if not self.capacity:
|
||||
self.capacity, self.extra_bed_capacity = frappe.db.get_value('Hotel Room Type',
|
||||
self.hotel_room_type, ['capacity', 'extra_bed_capacity'])
|
||||
self.capacity, self.extra_bed_capacity = frappe.db.get_value(
|
||||
"Hotel Room Type", self.hotel_room_type, ["capacity", "extra_bed_capacity"]
|
||||
)
|
||||
|
||||
@@ -5,19 +5,14 @@ import unittest
|
||||
|
||||
test_dependencies = ["Hotel Room Package"]
|
||||
test_records = [
|
||||
dict(doctype="Hotel Room", name="1001",
|
||||
hotel_room_type="Basic Room"),
|
||||
dict(doctype="Hotel Room", name="1002",
|
||||
hotel_room_type="Basic Room"),
|
||||
dict(doctype="Hotel Room", name="1003",
|
||||
hotel_room_type="Basic Room"),
|
||||
dict(doctype="Hotel Room", name="1004",
|
||||
hotel_room_type="Basic Room"),
|
||||
dict(doctype="Hotel Room", name="1005",
|
||||
hotel_room_type="Basic Room"),
|
||||
dict(doctype="Hotel Room", name="1006",
|
||||
hotel_room_type="Basic Room")
|
||||
dict(doctype="Hotel Room", name="1001", hotel_room_type="Basic Room"),
|
||||
dict(doctype="Hotel Room", name="1002", hotel_room_type="Basic Room"),
|
||||
dict(doctype="Hotel Room", name="1003", hotel_room_type="Basic Room"),
|
||||
dict(doctype="Hotel Room", name="1004", hotel_room_type="Basic Room"),
|
||||
dict(doctype="Hotel Room", name="1005", hotel_room_type="Basic Room"),
|
||||
dict(doctype="Hotel Room", name="1006", hotel_room_type="Basic Room"),
|
||||
]
|
||||
|
||||
|
||||
class TestHotelRoom(unittest.TestCase):
|
||||
pass
|
||||
|
||||
@@ -9,12 +9,10 @@ from frappe.model.document import Document
|
||||
class HotelRoomPackage(Document):
|
||||
def validate(self):
|
||||
if not self.item:
|
||||
item = frappe.get_doc(dict(
|
||||
doctype = 'Item',
|
||||
item_code = self.name,
|
||||
item_group = 'Products',
|
||||
is_stock_item = 0,
|
||||
stock_uom = 'Unit'
|
||||
))
|
||||
item = frappe.get_doc(
|
||||
dict(
|
||||
doctype="Item", item_code=self.name, item_group="Products", is_stock_item=0, stock_uom="Unit"
|
||||
)
|
||||
)
|
||||
item.insert()
|
||||
self.item = item.name
|
||||
|
||||
@@ -4,44 +4,44 @@
|
||||
import unittest
|
||||
|
||||
test_records = [
|
||||
dict(doctype='Item', item_code='Breakfast',
|
||||
item_group='Products', is_stock_item=0),
|
||||
dict(doctype='Item', item_code='Lunch',
|
||||
item_group='Products', is_stock_item=0),
|
||||
dict(doctype='Item', item_code='Dinner',
|
||||
item_group='Products', is_stock_item=0),
|
||||
dict(doctype='Item', item_code='WiFi',
|
||||
item_group='Products', is_stock_item=0),
|
||||
dict(doctype='Hotel Room Type', name="Delux Room",
|
||||
dict(doctype="Item", item_code="Breakfast", item_group="Products", is_stock_item=0),
|
||||
dict(doctype="Item", item_code="Lunch", item_group="Products", is_stock_item=0),
|
||||
dict(doctype="Item", item_code="Dinner", item_group="Products", is_stock_item=0),
|
||||
dict(doctype="Item", item_code="WiFi", item_group="Products", is_stock_item=0),
|
||||
dict(
|
||||
doctype="Hotel Room Type",
|
||||
name="Delux Room",
|
||||
capacity=4,
|
||||
extra_bed_capacity=2,
|
||||
amenities = [
|
||||
dict(item='WiFi', billable=0)
|
||||
]),
|
||||
dict(doctype='Hotel Room Type', name="Basic Room",
|
||||
amenities=[dict(item="WiFi", billable=0)],
|
||||
),
|
||||
dict(
|
||||
doctype="Hotel Room Type",
|
||||
name="Basic Room",
|
||||
capacity=4,
|
||||
extra_bed_capacity=2,
|
||||
amenities = [
|
||||
dict(item='Breakfast', billable=0)
|
||||
]),
|
||||
dict(doctype="Hotel Room Package", name="Basic Room with Breakfast",
|
||||
amenities=[dict(item="Breakfast", billable=0)],
|
||||
),
|
||||
dict(
|
||||
doctype="Hotel Room Package",
|
||||
name="Basic Room with Breakfast",
|
||||
hotel_room_type="Basic Room",
|
||||
amenities = [
|
||||
dict(item="Breakfast", billable=0)
|
||||
]),
|
||||
dict(doctype="Hotel Room Package", name="Basic Room with Lunch",
|
||||
amenities=[dict(item="Breakfast", billable=0)],
|
||||
),
|
||||
dict(
|
||||
doctype="Hotel Room Package",
|
||||
name="Basic Room with Lunch",
|
||||
hotel_room_type="Basic Room",
|
||||
amenities = [
|
||||
dict(item="Breakfast", billable=0),
|
||||
dict(item="Lunch", billable=0)
|
||||
]),
|
||||
dict(doctype="Hotel Room Package", name="Basic Room with Dinner",
|
||||
amenities=[dict(item="Breakfast", billable=0), dict(item="Lunch", billable=0)],
|
||||
),
|
||||
dict(
|
||||
doctype="Hotel Room Package",
|
||||
name="Basic Room with Dinner",
|
||||
hotel_room_type="Basic Room",
|
||||
amenities = [
|
||||
dict(item="Breakfast", billable=0),
|
||||
dict(item="Dinner", billable=0)
|
||||
])
|
||||
amenities=[dict(item="Breakfast", billable=0), dict(item="Dinner", billable=0)],
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
class TestHotelRoomPackage(unittest.TestCase):
|
||||
pass
|
||||
|
||||
@@ -5,15 +5,20 @@ import unittest
|
||||
|
||||
test_dependencies = ["Hotel Room Package"]
|
||||
test_records = [
|
||||
dict(doctype="Hotel Room Pricing", enabled=1,
|
||||
dict(
|
||||
doctype="Hotel Room Pricing",
|
||||
enabled=1,
|
||||
name="Winter 2017",
|
||||
from_date="2017-01-01", to_date="2017-01-10",
|
||||
items = [
|
||||
from_date="2017-01-01",
|
||||
to_date="2017-01-10",
|
||||
items=[
|
||||
dict(item="Basic Room with Breakfast", rate=10000),
|
||||
dict(item="Basic Room with Lunch", rate=11000),
|
||||
dict(item="Basic Room with Dinner", rate=12000)
|
||||
])
|
||||
dict(item="Basic Room with Dinner", rate=12000),
|
||||
],
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
class TestHotelRoomPricing(unittest.TestCase):
|
||||
pass
|
||||
|
||||
@@ -10,8 +10,13 @@ from frappe.model.document import Document
|
||||
from frappe.utils import add_days, date_diff, flt
|
||||
|
||||
|
||||
class HotelRoomUnavailableError(frappe.ValidationError): pass
|
||||
class HotelRoomPricingNotSetError(frappe.ValidationError): pass
|
||||
class HotelRoomUnavailableError(frappe.ValidationError):
|
||||
pass
|
||||
|
||||
|
||||
class HotelRoomPricingNotSetError(frappe.ValidationError):
|
||||
pass
|
||||
|
||||
|
||||
class HotelRoomReservation(Document):
|
||||
def validate(self):
|
||||
@@ -28,27 +33,39 @@ class HotelRoomReservation(Document):
|
||||
if not d.item in self.rooms_booked:
|
||||
self.rooms_booked[d.item] = 0
|
||||
|
||||
room_type = frappe.db.get_value("Hotel Room Package",
|
||||
d.item, 'hotel_room_type')
|
||||
rooms_booked = get_rooms_booked(room_type, day, exclude_reservation=self.name) \
|
||||
+ d.qty + self.rooms_booked.get(d.item)
|
||||
room_type = frappe.db.get_value("Hotel Room Package", d.item, "hotel_room_type")
|
||||
rooms_booked = (
|
||||
get_rooms_booked(room_type, day, exclude_reservation=self.name)
|
||||
+ d.qty
|
||||
+ self.rooms_booked.get(d.item)
|
||||
)
|
||||
total_rooms = self.get_total_rooms(d.item)
|
||||
if total_rooms < rooms_booked:
|
||||
frappe.throw(_("Hotel Rooms of type {0} are unavailable on {1}").format(d.item,
|
||||
frappe.format(day, dict(fieldtype="Date"))), exc=HotelRoomUnavailableError)
|
||||
frappe.throw(
|
||||
_("Hotel Rooms of type {0} are unavailable on {1}").format(
|
||||
d.item, frappe.format(day, dict(fieldtype="Date"))
|
||||
),
|
||||
exc=HotelRoomUnavailableError,
|
||||
)
|
||||
|
||||
self.rooms_booked[d.item] += rooms_booked
|
||||
|
||||
def get_total_rooms(self, item):
|
||||
if not item in self.total_rooms:
|
||||
self.total_rooms[item] = frappe.db.sql("""
|
||||
self.total_rooms[item] = (
|
||||
frappe.db.sql(
|
||||
"""
|
||||
select count(*)
|
||||
from
|
||||
`tabHotel Room Package` package
|
||||
inner join
|
||||
`tabHotel Room` room on package.hotel_room_type = room.hotel_room_type
|
||||
where
|
||||
package.item = %s""", item)[0][0] or 0
|
||||
package.item = %s""",
|
||||
item,
|
||||
)[0][0]
|
||||
or 0
|
||||
)
|
||||
|
||||
return self.total_rooms[item]
|
||||
|
||||
@@ -60,7 +77,8 @@ class HotelRoomReservation(Document):
|
||||
day = add_days(self.from_date, i)
|
||||
if not d.item:
|
||||
continue
|
||||
day_rate = frappe.db.sql("""
|
||||
day_rate = frappe.db.sql(
|
||||
"""
|
||||
select
|
||||
item.rate
|
||||
from
|
||||
@@ -70,18 +88,22 @@ class HotelRoomReservation(Document):
|
||||
item.parent = pricing.name
|
||||
and item.item = %s
|
||||
and %s between pricing.from_date
|
||||
and pricing.to_date""", (d.item, day))
|
||||
and pricing.to_date""",
|
||||
(d.item, day),
|
||||
)
|
||||
|
||||
if day_rate:
|
||||
net_rate += day_rate[0][0]
|
||||
else:
|
||||
frappe.throw(
|
||||
_("Please set Hotel Room Rate on {}").format(
|
||||
frappe.format(day, dict(fieldtype="Date"))), exc=HotelRoomPricingNotSetError)
|
||||
_("Please set Hotel Room Rate on {}").format(frappe.format(day, dict(fieldtype="Date"))),
|
||||
exc=HotelRoomPricingNotSetError,
|
||||
)
|
||||
d.rate = net_rate
|
||||
d.amount = net_rate * flt(d.qty)
|
||||
self.net_total += d.amount
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_room_rate(hotel_room_reservation):
|
||||
"""Calculate rate for each day as it may belong to different Hotel Room Pricing Item"""
|
||||
@@ -89,12 +111,15 @@ def get_room_rate(hotel_room_reservation):
|
||||
doc.set_rates()
|
||||
return doc.as_dict()
|
||||
|
||||
def get_rooms_booked(room_type, day, exclude_reservation=None):
|
||||
exclude_condition = ''
|
||||
if exclude_reservation:
|
||||
exclude_condition = 'and reservation.name != {0}'.format(frappe.db.escape(exclude_reservation))
|
||||
|
||||
return frappe.db.sql("""
|
||||
def get_rooms_booked(room_type, day, exclude_reservation=None):
|
||||
exclude_condition = ""
|
||||
if exclude_reservation:
|
||||
exclude_condition = "and reservation.name != {0}".format(frappe.db.escape(exclude_reservation))
|
||||
|
||||
return (
|
||||
frappe.db.sql(
|
||||
"""
|
||||
select sum(item.qty)
|
||||
from
|
||||
`tabHotel Room Package` room_package,
|
||||
@@ -107,5 +132,10 @@ def get_rooms_booked(room_type, day, exclude_reservation=None):
|
||||
and reservation.docstatus = 1
|
||||
{exclude_condition}
|
||||
and %s between reservation.from_date
|
||||
and reservation.to_date""".format(exclude_condition=exclude_condition),
|
||||
(room_type, day))[0][0] or 0
|
||||
and reservation.to_date""".format(
|
||||
exclude_condition=exclude_condition
|
||||
),
|
||||
(room_type, day),
|
||||
)[0][0]
|
||||
or 0
|
||||
)
|
||||
|
||||
@@ -12,6 +12,7 @@ from erpnext.hotels.doctype.hotel_room_reservation.hotel_room_reservation import
|
||||
|
||||
test_dependencies = ["Hotel Room Package", "Hotel Room Pricing", "Hotel Room"]
|
||||
|
||||
|
||||
class TestHotelRoomReservation(unittest.TestCase):
|
||||
def setUp(self):
|
||||
frappe.db.sql("delete from `tabHotel Room Reservation`")
|
||||
@@ -19,22 +20,14 @@ class TestHotelRoomReservation(unittest.TestCase):
|
||||
|
||||
def test_reservation(self):
|
||||
reservation = make_reservation(
|
||||
from_date="2017-01-01",
|
||||
to_date="2017-01-03",
|
||||
items=[
|
||||
dict(item="Basic Room with Dinner", qty=2)
|
||||
]
|
||||
from_date="2017-01-01", to_date="2017-01-03", items=[dict(item="Basic Room with Dinner", qty=2)]
|
||||
)
|
||||
reservation.insert()
|
||||
self.assertEqual(reservation.net_total, 48000)
|
||||
|
||||
def test_price_not_set(self):
|
||||
reservation = make_reservation(
|
||||
from_date="2016-01-01",
|
||||
to_date="2016-01-03",
|
||||
items=[
|
||||
dict(item="Basic Room with Dinner", qty=2)
|
||||
]
|
||||
from_date="2016-01-01", to_date="2016-01-03", items=[dict(item="Basic Room with Dinner", qty=2)]
|
||||
)
|
||||
self.assertRaises(HotelRoomPricingNotSetError, reservation.insert)
|
||||
|
||||
@@ -44,7 +37,7 @@ class TestHotelRoomReservation(unittest.TestCase):
|
||||
to_date="2017-01-03",
|
||||
items=[
|
||||
dict(item="Basic Room with Dinner", qty=2),
|
||||
]
|
||||
],
|
||||
)
|
||||
reservation.insert()
|
||||
|
||||
@@ -53,10 +46,11 @@ class TestHotelRoomReservation(unittest.TestCase):
|
||||
to_date="2017-01-03",
|
||||
items=[
|
||||
dict(item="Basic Room with Dinner", qty=20),
|
||||
]
|
||||
],
|
||||
)
|
||||
self.assertRaises(HotelRoomUnavailableError, reservation.insert)
|
||||
|
||||
|
||||
def make_reservation(**kwargs):
|
||||
kwargs["doctype"] = "Hotel Room Reservation"
|
||||
if not "guest_name" in kwargs:
|
||||
|
||||
@@ -14,16 +14,18 @@ def execute(filters=None):
|
||||
data = get_data(filters)
|
||||
return columns, data
|
||||
|
||||
|
||||
def get_columns(filters):
|
||||
columns = [
|
||||
dict(label=_("Room Type"), fieldname="room_type"),
|
||||
dict(label=_("Rooms Booked"), fieldtype="Int")
|
||||
dict(label=_("Rooms Booked"), fieldtype="Int"),
|
||||
]
|
||||
return columns
|
||||
|
||||
|
||||
def get_data(filters):
|
||||
out = []
|
||||
for room_type in frappe.get_all('Hotel Room Type'):
|
||||
for room_type in frappe.get_all("Hotel Room Type"):
|
||||
total_booked = 0
|
||||
for i in range(date_diff(filters.to_date, filters.from_date)):
|
||||
day = add_days(filters.from_date, i)
|
||||
|
||||
Reference in New Issue
Block a user