From 77b82e553815024f0b08f71d4751910d10856941 Mon Sep 17 00:00:00 2001 From: mgite Date: Thu, 10 Oct 2024 01:42:10 +0400 Subject: [PATCH] Add models and views --- .env | 2 +- bross.py | 50 +++++ bross_hms/__manifest__.py | 38 ++-- bross_hms/cron/crons.xml | 17 ++ bross_hms/demo/demo.xml | 30 --- bross_hms/models/__init__.py | 2 +- bross_hms/models/exely_data.py | 296 +++++++++++++++++++++++++ bross_hms/models/models.py | 19 -- bross_hms/security/ir.model.access.csv | 11 +- bross_hms/views/amenities.xml | 27 +++ bross_hms/views/bookings.xml | 65 ++++++ bross_hms/views/customers.xml | 78 +++++++ bross_hms/views/emails.xml | 27 +++ bross_hms/views/guests.xml | 27 +++ bross_hms/views/main_menus.xml | 7 + bross_hms/views/modified_bookings.xml | 32 +++ bross_hms/views/phones.xml | 27 +++ bross_hms/views/roomstays.xml | 34 +++ bross_hms/views/templates.xml | 24 -- bross_hms/views/views.xml | 60 ----- 20 files changed, 716 insertions(+), 157 deletions(-) create mode 100644 bross.py create mode 100644 bross_hms/cron/crons.xml delete mode 100644 bross_hms/demo/demo.xml create mode 100644 bross_hms/models/exely_data.py delete mode 100644 bross_hms/models/models.py create mode 100644 bross_hms/views/amenities.xml create mode 100644 bross_hms/views/bookings.xml create mode 100644 bross_hms/views/customers.xml create mode 100644 bross_hms/views/emails.xml create mode 100644 bross_hms/views/guests.xml create mode 100644 bross_hms/views/main_menus.xml create mode 100644 bross_hms/views/modified_bookings.xml create mode 100644 bross_hms/views/phones.xml create mode 100644 bross_hms/views/roomstays.xml delete mode 100644 bross_hms/views/templates.xml delete mode 100644 bross_hms/views/views.xml diff --git a/.env b/.env index 2a8f97d..34f7835 100644 --- a/.env +++ b/.env @@ -15,5 +15,5 @@ PASSWORD="odoo" ADDONS="--addons-path=/opt/odoo/addons/,/opt/odoo/customaddons/$CUSTOMADDONS_DIR" ARGS="" # ARGS="-d bross" -ARGS="-d cybro_hms" +ARGS="-d cybro_hms -u bross_hms" # DEBUG="-m debugpy --listen 0.0.0.0:5678 --wait-for-client" diff --git a/bross.py b/bross.py new file mode 100644 index 0000000..bf694ac --- /dev/null +++ b/bross.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python + +import requests +import sys + +headers = { + 'X-API-KEY': 'b84f2c33-d9dc-439a-84ff-3deed4b18e10', + 'Content-Type': 'application/json', +} +#url = "https://connect.hopenapi.com/api/exelypms/v1/analytics/services" +#url = "https://connect.hopenapi.com/api/exelypms/v1/analytics/payments" + +#payload = {'startDate': '20240909', 'endDate': '20240910', 'dateKind': 0, 'language': 'en'} +#response = requests.get(url, data=payload, headers=headers) + +# response = requests.get("https://connect.hopenapi.com/api/exelypms/v1/analytics/services?startDate=20241008&endDate=20241008&dateKind=4", headers=headers) +# response = requests.get("https://connect.hopenapi.com/api/exelypms/v1/bookings/20240301-503875-1211582391", headers=headers) +# response = requests.get("https://connect.hopenapi.com/api/exelypms/v1/bookings/20241217-503875-1220773707", headers=headers) +# response = requests.get("https://connect.hopenapi.com/api/exelypms/v1/bookings/20240909-503875-1219004943", headers=headers) + +response = requests.get("https://connect.hopenapi.com/api/exelypms/v1/bookings?modifiedFrom=2024-01-01T00:00&modifiedTo=2024-01-30T23:59&state=Active", headers=headers) +# response = requests.get("https://connect.hopenapi.com/api/exelypms/v1/bookings?modifiedFrom=2024-01-01T00:00&modifiedTo=2024-30-01T23:59&state=Cancelled", headers=headers) + +# response = requests.get("https://connect.hopenapi.com/api/exelypms/v1/rooms", headers=headers) + +if response.status_code == 200: + data = response.json() + print(data) + + sys.exit() + for i in data['data']['services']: + pass + #print(i) + for i in data['data']['customers']: + pass + #print(i) + for i in data['data']['agents']: + pass + #print(i) + for i in data['data']['reservations']: + #pass + print(i) + #if i['guestId'] == '9007199257013459_9007199256429978': + # print(i) + for i in data['data']['roomTypes']: + pass + #print(i) +else: + print(response.json()) + print(f"Failed to retrieve data. Status code: {response.status_code}") diff --git a/bross_hms/__manifest__.py b/bross_hms/__manifest__.py index b709463..d101006 100644 --- a/bross_hms/__manifest__.py +++ b/bross_hms/__manifest__.py @@ -1,30 +1,26 @@ # -*- coding: utf-8 -*- { 'name': "bross_hms", - - 'summary': "Short (1 phrase/line) summary of the module's purpose", - - 'description': """ -Long description of module's purpose - """, - - 'author': "My Company", - 'website': "https://www.yourcompany.com", - - # Categories can be used to filter modules in modules listing - # Check https://github.com/odoo/odoo/blob/15.0/odoo/addons/base/data/ir_module_category_data.xml - # for the full list + 'summary': "HMS", + 'description': """Hotel Management System""", + 'author': "Mate Managadze", + 'website': "https://www.brossegarden.com", 'category': 'Uncategorized', - 'version': '0.1', - - # any module necessary for this one to work correctly + 'version': '17.0.1.0.0', + 'license': 'OPL-1', 'depends': ['base'], - - # always loaded 'data': [ - # 'security/ir.model.access.csv', - 'views/views.xml', - 'views/templates.xml', + 'security/ir.model.access.csv', + 'cron/crons.xml', + 'views/main_menus.xml', + 'views/emails.xml', + 'views/phones.xml', + 'views/customers.xml', + 'views/guests.xml', + 'views/amenities.xml', + 'views/roomstays.xml', + 'views/modified_bookings.xml', + 'views/bookings.xml', ], # only loaded in demonstration mode 'demo': [ diff --git a/bross_hms/cron/crons.xml b/bross_hms/cron/crons.xml new file mode 100644 index 0000000..26ffbd8 --- /dev/null +++ b/bross_hms/cron/crons.xml @@ -0,0 +1,17 @@ + + + + + Get Exely Data + + code + model.get_exely_data() + + 1 + -1 + + + 100 + + + \ No newline at end of file diff --git a/bross_hms/demo/demo.xml b/bross_hms/demo/demo.xml deleted file mode 100644 index 9b20ea8..0000000 --- a/bross_hms/demo/demo.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - diff --git a/bross_hms/models/__init__.py b/bross_hms/models/__init__.py index cde864b..59dac22 100644 --- a/bross_hms/models/__init__.py +++ b/bross_hms/models/__init__.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- -from . import models +from . import exely_data diff --git a/bross_hms/models/exely_data.py b/bross_hms/models/exely_data.py new file mode 100644 index 0000000..6bb3aac --- /dev/null +++ b/bross_hms/models/exely_data.py @@ -0,0 +1,296 @@ +# -*- coding: utf-8 -*- + +import requests +import logging +from odoo import models, fields, api, _ +from datetime import datetime, timedelta + + +_logger = logging.getLogger(__name__) + +HEADERS = { + 'X-API-KEY': 'b84f2c33-d9dc-439a-84ff-3deed4b18e10', + 'Content-Type': 'application/json', +} + +STATES = ['Active', 'Cancelled'] + + +class ExelyModifiedData(models.Model): + _name = 'exely.modified.bookings' + _description = 'Exely Modified Bookings' + _rec_name = 'booking_number' + + mod_period_start = fields.Datetime(string="Start Date") + mod_period_end = fields.Datetime(string="End Date") + booking_number = fields.Char(string="Booking Number") + status = fields.Char(string="Status") + + + + +class ExelyEmail(models.Model): + _name = 'exely.email' + _description = 'Exely Email' + _rec_name = 'email' + + email = fields.Char(string="Email") + + +class ExelyPhones(models.Model): + _name = 'exely.phones' + _description = 'Exely Phones' + _rec_name = 'phone' + + phone = fields.Char(string="Phone") + + +class ExelyCustomer(models.Model): + _name = 'exely.customer' + _description = 'Exely Customer' + _rec_name = 'bid' + + bid = fields.Char(string="Customer ID", index=True) + lastName = fields.Char(string="Last Name") + firstName = fields.Char(string="First Name") + middleName = fields.Char(string="Middle Name") + birthDate = fields.Char(string="Birth Date") + citizenshipCode = fields.Char(string="Citizenship Code") + status = fields.Json(string="Status") + emails = fields.Many2many(comodel_name="exely.email", string="Emails") + phones = fields.Many2many(comodel_name="exely.phones", string="Phones") + gender = fields.Char(string="Gender") + + + + +class ExelyGuests(models.Model): + _name = 'exely.guests' + _description = 'Exely Guests' + _rec_name = 'bid' + + bid = fields.Char(string="Guest ID", index=True) + + +class ExelyAmenities(models.Model): + _name = 'exely.amenities' + _description = 'Exely Amenities' + _rec_name = 'name' + + name = fields.Char(string="Name") + + +class ExelyRoomStays(models.Model): + _name = 'exely.roomstays' + _description = 'Exely RoomStays' + _rec_name = 'bid' + + bid = fields.Char(string="Room ID", index=True) + bookingId = fields.Char(string="Booking ID", index=True) + roomId = fields.Char(string="Room ID") + roomTypeId = fields.Char(string="Room Type ID") + guestsIds = fields.Many2many(comodel_name="exely.guests", string="Guests Ids") + checkInDateTime = fields.Char(string="Check In Date Time") + checkOutDateTime = fields.Char(string="Check Out Date Time") + actualCheckInDateTime = fields.Char(string="Actual Check In Date Time") + actualCheckOutDateTime = fields.Char(string="Actual Check Out Date Time") + status = fields.Char(string="Status") + bookingStatus = fields.Char(string="Booking Status") + guestCountInfo = fields.Json(string="Guest Count Info") + totalPrice = fields.Json(string="Total Price") + amenities = fields.Many2many(comodel_name="exely.amenities", string="Amenities") + + bookings_id = fields.Many2one(comodel_name="exely.bookings", string="Room Stay Id") + + + + +class ExcelyBookings(models.Model): + _name = 'exely.bookings' + _description = 'Exely Bookings' + _rec_name = 'bid' + + bid = fields.Char(string="Booking ID", index=True) + number = fields.Char(string="Booking Number", index=True) + customerLanguage = fields.Char(string="Customer Language") + visitPurpose = fields.Json(string="Visit Purpose") + customerComment = fields.Char(string="Customer Comment") + lastModified = fields.Char(string="Last Modified") + currencyId = fields.Char(string="Currency ID") + customer = fields.Many2one(comodel_name="exely.customer", string="Customer") + roomStays = fields.One2many(comodel_name="exely.roomstays", inverse_name="bookings_id", string="RoomStays") + customerCompany = fields.Json(string="Customer Company") + source = fields.Json(string="RoomStays") + sourceChannelName = fields.Char(string="Source Channel Name") + + def json_data_store_visit(self): + self.visitPurpose = { + 'id': self.id, + 'key': self.number, + 'value': self.number, + } + + + def generate_date_ranges(self, start_date, end_date): + date_ranges = [] + current_date = start_date + + while current_date < end_date: + period_start = current_date + period_end = min(current_date + timedelta(days=29), end_date) + + if period_end.date() < end_date.date(): + period_end = period_end.replace(hour=23, minute=59) + else: + period_end = end_date + + date_ranges.append(( + period_start.strftime("%Y-%m-%dT%H:%M"), + period_end.strftime("%Y-%m-%dT%H:%M") + )) + + current_date = period_end + timedelta(days=1) + return date_ranges + + def get_exely_data(self): + start_date = datetime(2024, 1, 1) + end_date = datetime.now() + + date_ranges = self.generate_date_ranges(start_date, end_date) + + to_create = [] + for status in STATES: + for start, end in date_ranges: + print(f"{start} to {end}") + + url = f"https://connect.hopenapi.com/api/exelypms/v1/bookings?modifiedFrom={start}&modifiedTo={end}&state={status}" + # try: + response = requests.get(url, headers=HEADERS) + if response.status_code == 200: + data = response.json() + for booking_number in data['bookingNumbers']: + start_write = datetime.strptime(start, "%Y-%m-%dT%H:%M") - timedelta(hours=4) + end_write = datetime.strptime(end, "%Y-%m-%dT%H:%M") - timedelta(hours=4) + found_modified_booking = self.env['exely.modified.bookings'].search([ + ('mod_period_start', '=', start_write), + ('mod_period_end', '=', end_write), + ('booking_number', '=', booking_number), + ('status', '=', status)] + ) + if not found_modified_booking: + self.env['exely.modified.bookings'].create({ + 'mod_period_start': start_write, + 'mod_period_end': end_write, + 'booking_number': booking_number, + 'status': status + }) + + url = f"https://connect.hopenapi.com/api/exelypms/v1/bookings/{booking_number}" + response = requests.get(url, headers=HEADERS) + if response.status_code == 200: + data = response.json() + + data['bid'] = data.pop('id') + + customer = data.pop('customer', None) + + if customer: + customer['bid'] = customer.pop('id') + emails = customer.get('emails', None) + phones = customer.get('phones', None) + + if emails: + email_ids = [] + for email in emails: + found_email = self.env['exely.email'].search([('email', '=', email)]) + if found_email: + email_id = found_email.id + else: + email_id = self.env['exely.email'].create({'email': email}).id + email_ids.append(email_id) + + if email_ids: + customer['emails'] = [(6, 0, email_ids)] + + if phones: + phone_ids = [] + for phone in phones: + found_phone = self.env['exely.phones'].search([('phone', '=', phone)]) + if found_phone: + phone_id = found_phone.id + else: + phone_id = self.env['exely.phones'].create({'phone': phone}).id + phone_ids.append(phone_id) + + if phone_ids: + customer['phones'] = [(6, 0, phone_ids)] + + found_customer = self.env['exely.customer'].search([('bid', '=', customer['bid'])]) + if found_customer: + customer_id = found_customer.id + else: + customer_id = self.env['exely.customer'].create(customer).id + data['customer'] = customer_id + + roomstays = data.pop('roomStays', None) + if roomstays: + roomstays_ids = [] + for roomstay in roomstays: + roomstay['bid'] = roomstay.pop('id') + + guests = roomstay.pop('guestsIds', None) + + if guests: + guest_ids = [] + for guest in guests: + found_guest = self.env['exely.guests'].search([('bid', '=', guest)]) + if found_guest: + guest_id = found_guest.id + else: + guest_id = self.env['exely.guests'].create({'bid': guest}).id + guest_ids.append(guest_id) + + if guest_ids: + roomstay['guestsIds'] = [(6, 0, guest_ids)] + + amenities = roomstay.pop('amenities', None) + + if not amenities: + amenity_ids = [] + for amenity in amenities: + found_amenity = self.env['exely.amenities'].search([('name', '=', amenity)]) + if found_amenity: + amenity_id = found_amenity.id + else: + amenity_id = self.env['exely.amenities'].create({'name': amenity}).id + amenity_ids.append(amenity_id) + + if amenity_ids: + roomstay['amenities'] = [(6, 0, amenity_ids)] + + found_roomstay = self.env['exely.roomstays'].search([('bid', '=', roomstay['bid'])]) + if found_roomstay: + roomstay_id = found_roomstay.id + else: + roomstay_id = self.env['exely.roomstays'].create(roomstay).id + roomstays_ids.append(roomstay_id) + + if roomstays_ids: + data['roomStays'] = [(6, 0, roomstays_ids)] + + print(data) + to_create.append(data) + else: + _logger.warning(f"Failed to retrieve data. Status code: {response.status_code}") + # except Exception as e: + # _logger.warning(f"Error processing data: {e}") + + if to_create: + for i in to_create: + try: + self.env['exely.bookings'].create(i) + except Exception as e: + _logger.warning(f"##############################: {i}") + break + # if to_create: + # self.env['exely.bookings'].create(to_create) diff --git a/bross_hms/models/models.py b/bross_hms/models/models.py deleted file mode 100644 index 295072b..0000000 --- a/bross_hms/models/models.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- - -from odoo import models, fields, api - - -class bross_hms(models.Model): - _name = 'bross_hms.bross_hms' - _description = 'bross_hms.bross_hms' - - name = fields.Char() - value = fields.Integer() - value2 = fields.Float(compute="_value_pc", store=True) - description = fields.Text() - - @api.depends('value') - def _value_pc(self): - for record in self: - record.value2 = float(record.value) / 100 - diff --git a/bross_hms/security/ir.model.access.csv b/bross_hms/security/ir.model.access.csv index fe21e56..674f79d 100644 --- a/bross_hms/security/ir.model.access.csv +++ b/bross_hms/security/ir.model.access.csv @@ -1,2 +1,11 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_bross_hms_bross_hms,bross_hms.bross_hms,model_bross_hms_bross_hms,base.group_user,1,1,1,1 + +bross_hms.access_exely_modified_bookings,access_exely_modified_bookings,bross_hms.model_exely_modified_bookings,base.group_user,1,1,1,1 +bross_hms.access_exely_bookings,access_exely_bookings,bross_hms.model_exely_bookings,base.group_user,1,1,1,1 + +bross_hms.access_exely_email,access_exely_email,bross_hms.model_exely_email,base.group_user,1,1,1,1 +bross_hms.access_exely_phones,access_exely_phones,bross_hms.model_exely_phones,base.group_user,1,1,1,1 +bross_hms.access_exely_customer,access_exely_customer,bross_hms.model_exely_customer,base.group_user,1,1,1,1 +bross_hms.access_exely_guests,access_exely_guests,bross_hms.model_exely_guests,base.group_user,1,1,1,1 +bross_hms.access_exely_amenities,access_exely_amenities,bross_hms.model_exely_amenities,base.group_user,1,1,1,1 +bross_hms.access_exely_roomstays,access_exely_roomstays,bross_hms.model_exely_roomstays,base.group_user,1,1,1,1 \ No newline at end of file diff --git a/bross_hms/views/amenities.xml b/bross_hms/views/amenities.xml new file mode 100644 index 0000000..9c69d89 --- /dev/null +++ b/bross_hms/views/amenities.xml @@ -0,0 +1,27 @@ + + + + + exely.amenities.tree + exely.amenities + + + + + + + + + Exely Amenities + exely.amenities + tree + +

+ Create your first amenity record. +

+
+
+ + +
+
diff --git a/bross_hms/views/bookings.xml b/bross_hms/views/bookings.xml new file mode 100644 index 0000000..f316e1d --- /dev/null +++ b/bross_hms/views/bookings.xml @@ -0,0 +1,65 @@ + + + + + exely.bookings.tree + exely.bookings + + + + + + + + + + + + + + exely.bookings.form + exely.bookings + +
+
+ +
+ + +

+
+ + + + + + + + + + + + + + + + +
+
+
+
+ + + Exely Bookings + exely.bookings + tree,form + +

+ Create your first booking record. +

+
+
+ + +
+
diff --git a/bross_hms/views/customers.xml b/bross_hms/views/customers.xml new file mode 100644 index 0000000..46b4c4a --- /dev/null +++ b/bross_hms/views/customers.xml @@ -0,0 +1,78 @@ + + + + + exely.customer.tree + exely.customer + + + + + + + + + + + + + + + exely.customer.form + exely.customer + +
+
+ +
+ + +

+
+ + + + + + + + + + + + + + + + + +
+
+
+
+ + + + + Exely Customers + exely.customer + tree,form,pivot,graph + +

+ Create your first customer record. +

+
+
+ + +
+
diff --git a/bross_hms/views/emails.xml b/bross_hms/views/emails.xml new file mode 100644 index 0000000..f18b600 --- /dev/null +++ b/bross_hms/views/emails.xml @@ -0,0 +1,27 @@ + + + + + exely.email.tree + exely.email + + + + + + + + + Exely Emails + exely.email + tree + +

+ Create your first email record. +

+
+
+ + +
+
diff --git a/bross_hms/views/guests.xml b/bross_hms/views/guests.xml new file mode 100644 index 0000000..bda1b81 --- /dev/null +++ b/bross_hms/views/guests.xml @@ -0,0 +1,27 @@ + + + + + exely.guests.tree + exely.guests + + + + + + + + + Exely Guests + exely.guests + tree + +

+ Create your first guest record. +

+
+
+ + +
+
diff --git a/bross_hms/views/main_menus.xml b/bross_hms/views/main_menus.xml new file mode 100644 index 0000000..a2c7df7 --- /dev/null +++ b/bross_hms/views/main_menus.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/bross_hms/views/modified_bookings.xml b/bross_hms/views/modified_bookings.xml new file mode 100644 index 0000000..5676719 --- /dev/null +++ b/bross_hms/views/modified_bookings.xml @@ -0,0 +1,32 @@ + + + + + exely.modified.bookings.tree + exely.modified.bookings + + + + + + + + + + + + + + exely.modified.data + exely.modified.bookings + tree + +

+ Create your first modified bookings record. +

+
+
+ + +
+
diff --git a/bross_hms/views/phones.xml b/bross_hms/views/phones.xml new file mode 100644 index 0000000..30ae448 --- /dev/null +++ b/bross_hms/views/phones.xml @@ -0,0 +1,27 @@ + + + + + exely.phones.tree + exely.phones + + + + + + + + + Exely Phones + exely.phones + tree + +

+ Create your first phone record. +

+
+
+ + +
+
diff --git a/bross_hms/views/roomstays.xml b/bross_hms/views/roomstays.xml new file mode 100644 index 0000000..0a3596b --- /dev/null +++ b/bross_hms/views/roomstays.xml @@ -0,0 +1,34 @@ + + + + + exely.roomstays.tree + exely.roomstays + + + + + + + + + + + + + + + + Exely Room Stays + exely.roomstays + tree + +

+ Create your first room stay record. +

+
+
+ + +
+
diff --git a/bross_hms/views/templates.xml b/bross_hms/views/templates.xml deleted file mode 100644 index 2f37b71..0000000 --- a/bross_hms/views/templates.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - diff --git a/bross_hms/views/views.xml b/bross_hms/views/views.xml deleted file mode 100644 index 57e9998..0000000 --- a/bross_hms/views/views.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - -