This commit is contained in:
parent
1e572d2be5
commit
40ae3c6d45
@ -144,9 +144,12 @@ class ExelyModifiedData(models.Model):
|
|||||||
hash_object = hashlib.sha256(json_data.encode())
|
hash_object = hashlib.sha256(json_data.encode())
|
||||||
hash_hex = hash_object.hexdigest()
|
hash_hex = hash_object.hexdigest()
|
||||||
|
|
||||||
found_raw_record = self.env[model].search([
|
find_records = self.env[model].search([('bid', '=', bid)])
|
||||||
('bid', '=', bid),
|
|
||||||
])
|
if len(find_records) > 1:
|
||||||
|
found_raw_record = find_records.sorted(key=lambda x: x.id, reverse=True)[0]
|
||||||
|
else:
|
||||||
|
found_raw_record = find_records
|
||||||
|
|
||||||
if found_raw_record:
|
if found_raw_record:
|
||||||
if found_raw_record.json_hash_code != hash_hex:
|
if found_raw_record.json_hash_code != hash_hex:
|
||||||
@ -159,9 +162,10 @@ class ExelyModifiedData(models.Model):
|
|||||||
'json_hash_code': hash_hex,
|
'json_hash_code': hash_hex,
|
||||||
'bid': bid,
|
'bid': bid,
|
||||||
})
|
})
|
||||||
found_raw_record.parent_id = new_created_record.id
|
for record in find_records:
|
||||||
|
record.parent_id = new_created_record.id
|
||||||
else:
|
else:
|
||||||
found_raw_record = self.env[model].create({
|
self.env[model].create({
|
||||||
'json_data': json_data,
|
'json_data': json_data,
|
||||||
'json_hash_code': hash_hex,
|
'json_hash_code': hash_hex,
|
||||||
'bid': bid
|
'bid': bid
|
||||||
@ -372,8 +376,14 @@ class ExelyModifiedData(models.Model):
|
|||||||
for room in rooms:
|
for room in rooms:
|
||||||
self.create_or_update_raw_data(room, 'exely.raw.rooms', room['id'])
|
self.create_or_update_raw_data(room, 'exely.raw.rooms', room['id'])
|
||||||
|
|
||||||
|
found_record = self.env['exely.modified.bookings'].search([])
|
||||||
|
if found_record:
|
||||||
|
latest_record = self.env['exely.modified.bookings'].search([], order='mod_period_end desc', limit=1)
|
||||||
|
max_mod_period_end = latest_record.mod_period_end
|
||||||
|
max_modified_id = latest_record.id
|
||||||
|
|
||||||
start_date = datetime(2024, 1, 1)
|
max_id_to_process = max_modified_id if found_record else 0
|
||||||
|
start_date = max_mod_period_end if found_record else datetime(2024, 1, 1)
|
||||||
end_date = datetime.now()
|
end_date = datetime.now()
|
||||||
|
|
||||||
date_ranges = self.generate_date_ranges(start_date, end_date, 29, "%Y-%m-%dT%H:%M")
|
date_ranges = self.generate_date_ranges(start_date, end_date, 29, "%Y-%m-%dT%H:%M")
|
||||||
@ -381,7 +391,7 @@ class ExelyModifiedData(models.Model):
|
|||||||
to_create = []
|
to_create = []
|
||||||
for status in STATES:
|
for status in STATES:
|
||||||
for start, end in date_ranges:
|
for start, end in date_ranges:
|
||||||
print(f"{start} to {end}")
|
print(f"{start} to {end} - {status}")
|
||||||
|
|
||||||
data = self.get_exely_data_api(f"https://connect.hopenapi.com/api/exelypms/v1/bookings?modifiedFrom={start}&modifiedTo={end}&state={status}", headers)
|
data = self.get_exely_data_api(f"https://connect.hopenapi.com/api/exelypms/v1/bookings?modifiedFrom={start}&modifiedTo={end}&state={status}", headers)
|
||||||
if data:
|
if data:
|
||||||
@ -418,15 +428,16 @@ class ExelyModifiedData(models.Model):
|
|||||||
guest = self.get_exely_data_api(f"https://connect.hopenapi.com/api/exelypms/v1/guests/{bid}", headers)
|
guest = self.get_exely_data_api(f"https://connect.hopenapi.com/api/exelypms/v1/guests/{bid}", headers)
|
||||||
|
|
||||||
self.create_or_update_raw_data(guest, 'exely.raw.guests', bid)
|
self.create_or_update_raw_data(guest, 'exely.raw.guests', bid)
|
||||||
|
self.process_exely_data(max_id_to_process)
|
||||||
|
|
||||||
def process_exely_data(self):
|
def process_exely_data(self, max_modified_id):
|
||||||
found_booking_record = self.env['hms.bookings'].search([], order="write_date desc", limit=1)
|
# found_booking_record = self.env['hms.bookings'].search([], order="write_date desc", limit=1)
|
||||||
if found_booking_record:
|
# if found_booking_record:
|
||||||
max_date = found_booking_record.write_date
|
# max_date = found_booking_record.write_date
|
||||||
else:
|
# else:
|
||||||
max_date = datetime.strptime('1970-01-01', "%Y-%m-%d").date()
|
# max_date = datetime.strptime('1970-01-01', "%Y-%m-%d").date()
|
||||||
|
|
||||||
to_process_modified_bookings = self.env['exely.raw.bookings'].search([('write_date', '>', max_date), ('parent_id', '=', False)])
|
to_process_modified_bookings = self.env['exely.raw.bookings'].search([('id', '>', max_modified_id), ('parent_id', '=', False)])
|
||||||
|
|
||||||
to_create = []
|
to_create = []
|
||||||
for modified in to_process_modified_bookings:
|
for modified in to_process_modified_bookings:
|
||||||
@ -513,14 +524,12 @@ class ExelyModifiedData(models.Model):
|
|||||||
|
|
||||||
roomstay['roomId'] = room_id
|
roomstay['roomId'] = room_id
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
guests = roomstay.pop('guestsIds', None)
|
guests = roomstay.pop('guestsIds', None)
|
||||||
|
|
||||||
if guests:
|
if guests:
|
||||||
guest_ids = []
|
guest_ids = []
|
||||||
for guest in guests:
|
for guest in guests:
|
||||||
guest_data = json.loads(self.env['exely.raw.guests'].search([('bid', '=', guest)]).json_data)
|
guest_data = json.loads(self.env['exely.raw.guests'].search([('bid', '=', guest), ('parent_id', '=', False)]).json_data)
|
||||||
guest_data['bid'] = guest_data.pop('id')
|
guest_data['bid'] = guest_data.pop('id')
|
||||||
|
|
||||||
if guest_data:
|
if guest_data:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user