diff --git a/call_center_report/wizard/call_center_report.py b/call_center_report/wizard/call_center_report.py index d3da53d1d..964fb85d5 100644 --- a/call_center_report/wizard/call_center_report.py +++ b/call_center_report/wizard/call_center_report.py @@ -276,6 +276,7 @@ class CallCenterReportWizard(models.TransientModel): worksheet.write('I1', _('In-Hora'), xls_cell_format_header) worksheet.write('J1', _('Checkout'), xls_cell_format_header) worksheet.write('K1', _('Creado por'), xls_cell_format_header) + worksheet.write('K1', _('Cancelado en'), xls_cell_format_header) worksheet.write('L1', _('Precio Final'), xls_cell_format_header) worksheet.write('M1', _('Precio Original'), xls_cell_format_header) @@ -311,6 +312,8 @@ class CallCenterReportWizard(models.TransientModel): worksheet.write(k_res+offset, 9, checkout_date.strftime(date_format), xls_cell_format_date) worksheet.write(k_res+offset, 10, v_res.create_uid.name) + worksheet.write(k_res+offset, 9, v_res.last_updated_res, + xls_cell_format_date) worksheet.write(k_res+offset, 11, v_res.price_total, xls_cell_format_money) worksheet.write(k_res+offset, 12, v_res.price_total - v_res.discount, diff --git a/hotel/models/hotel_reservation.py b/hotel/models/hotel_reservation.py index 27385364a..2b0bc2572 100644 --- a/hotel/models/hotel_reservation.py +++ b/hotel/models/hotel_reservation.py @@ -159,11 +159,12 @@ class HotelReservation(models.Model): @api.depends('folio_id', 'checkin', 'checkout') def _compute_localizator(self): for record in self: - localizator = re.sub("[^0-9]", "", record.folio_id.name) - checkout = int(re.sub("[^0-9]", "", record.checkout)) - checkin = int(re.sub("[^0-9]", "", record.checkin)) - localizator += str((checkin + checkout) % 99) - record.localizator = localizator + if record.folio_id: + localizator = re.sub("[^0-9]", "", record.folio_id.name) + checkout = int(re.sub("[^0-9]", "", record.checkout)) + checkin = int(re.sub("[^0-9]", "", record.checkin)) + localizator += str((checkin + checkout) % 99) + record.localizator = localizator localizator = fields.Char('Localizator', compute='_compute_localizator', store=True) diff --git a/hotel_roommatik/__manifest__.py b/hotel_roommatik/__manifest__.py index de79f8b56..9fdefcf9f 100755 --- a/hotel_roommatik/__manifest__.py +++ b/hotel_roommatik/__manifest__.py @@ -18,7 +18,8 @@ 'hotel', 'partner_contact_gender', 'partner_second_lastname', - 'partner_contact_birthdate' + 'partner_contact_birthdate', + 'base_iso3166' ], 'data': [ 'views/inherit_hotel_reservation.xml', diff --git a/hotel_roommatik/models/__init__.py b/hotel_roommatik/models/__init__.py index 9b5209f6d..34a81fa30 100755 --- a/hotel_roommatik/models/__init__.py +++ b/hotel_roommatik/models/__init__.py @@ -4,3 +4,4 @@ from . import inherited_res_partner from . import inherited_hotel_room_type from . import roommatik from . import inherited_hotel_reservation +from . import inherited_accuont_payment diff --git a/hotel_roommatik/models/inherited_account_payment.py b/hotel_roommatik/models/inherited_account_payment.py new file mode 100644 index 000000000..81c62e241 --- /dev/null +++ b/hotel_roommatik/models/inherited_account_payment.py @@ -0,0 +1,42 @@ +# Copyright 2017 Dario Lodeiros +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo.exceptions import except_orm +from odoo import models, fields, api, _ + +class AccountPayment(models.Model): + _inherit = 'account.payment' + + @api.model + def _rm_add_payment(self, code, payment): + reservation = self.env['hotel.reservation'].search([ + '|', ('localizator', '=', code), + ('folio_id.name', '=', code)]) + if reservation: + for cashpay in payment['PaymentTransaction']['CashPayments']: + vals = { + 'journal_id': 7, # TODO:config setting + 'partner_id': reservation.partner_invoice_id.id, + 'amount': cashpay['Amount'], + 'payment_date': cashpay['DateTime'], + 'communication': reservation.name, + 'folio_id': reservation.folio_id.id, + 'payment_type': 'inbound', + 'payment_method_id': 1, + 'partner_type': 'customer', + 'state': 'draft', + } + for cashpay in payment['PaymentTransaction']['CreditCardPayments']: + vals = { + 'journal_id': 15, # TODO:config setting + 'partner_id': reservation.partner_invoice_id.id, + 'amount': cashpay['Amount'], + 'payment_date': cashpay['DateTime'], + 'communication': reservation.name, + 'folio_id': reservation.folio_id.id, + 'payment_type': 'inbound', + 'payment_method_id': 1, + 'partner_type': 'customer', + 'state': 'draft', + } + self.update(vals) + self.with_context({'ignore_notification_post': True}).post() diff --git a/hotel_roommatik/models/inherited_hotel_checkin_partner.py b/hotel_roommatik/models/inherited_hotel_checkin_partner.py index 809b20e8a..99b07e1f0 100644 --- a/hotel_roommatik/models/inherited_hotel_checkin_partner.py +++ b/hotel_roommatik/models/inherited_hotel_checkin_partner.py @@ -14,10 +14,8 @@ class HotelFolio(models.Model): def rm_checkin_partner(self, stay): _logger = logging.getLogger(__name__) # CHECK-IN - reservation_rm = self.env['hotel.reservation'].search([('id', '=', - stay['Code'])]) + reservation_rm = self.env['hotel.reservation'].browse(stay['ReservationCode']) # Need checkin? - total_chekins = reservation_rm.checkin_partner_pending_count if total_chekins > 0 and len(stay["Customers"]) <= total_chekins: _logger.info('ROOMMATIK checkin %s customer in %s Reservation.', @@ -35,35 +33,23 @@ class HotelFolio(models.Model): 'exit_date': datetime.strptime(stay["Departure"], "%d%m%Y").date(), 'partner_id': room_partner["Customer"]["Id"], - 'email': room_partner["Customer"]["Contact"]["Email"], - 'mobile': room_partner["Customer"]["Contact"]["Mobile"], - 'document_type': room_partner["Customer"][ - "IdentityDocument"]["Type"], - 'document_number': room_partner["Customer"][ - "IdentityDocument"]["Number"], - 'document_expedition_date': datetime.strptime(room_partner[ - "Customer"]["IdentityDocument"]["ExpiryDate"], "%d%m%Y").date(), - 'gender': room_partner["Customer"]["Sex"], - 'birthdate_date': datetime.strptime(room_partner[ - "Customer"]["Birthday"], "%d%m%Y").date(), - 'code_ine_id': room_partner["Customer"][ - "Address"]["Province"], - 'state': 'booking', } try: record = self.env['hotel.checkin.partner'].create( checkin_partner_val) - _logger.info('ROOMMATIK check-in Document: %s in \ + _logger.info('ROOMMATIK check-in partner: %s in \ (%s Reservation) ID:%s.', - checkin_partner_val['document_number'], + checkin_partner_val['partner_id'], checkin_partner_val['reservation_id'], record.id) + record.action_on_board() stay['Id'] = record.id + stay['Room'] = reservation_rm.room_id.id json_response = stay except: json_response = {'Estate': 'Error not create Checkin'} _logger.error('ROOMMATIK writing %s in reservation: %s).', - checkin_partner_val['document_number'], + checkin_partner_val['partner_id'], checkin_partner_val['reservation_id']) return json_response @@ -78,24 +64,28 @@ class HotelFolio(models.Model): @api.model def rm_get_stay(self, code): # BUSQUEDA POR LOCALIZADOR - reserva = self.search([('id', '=', code)]) - if any(reserva): - stay = {'Code': reserva.reservation_id.localizator} - stay['Id'] = reserva.folio_id.id + checkin_partner = self.search([('id', '=', code)]) + default_arrival_hour = self.env['ir.default'].sudo().get( + 'res.config.settings', 'default_arrival_hour') + default_departure_hour = self.env['ir.default'].sudo().get( + 'res.config.settings', 'default_departure_hour') + if any(checkin_partner): + arrival = "%s %s" % (checkin_partner.enter_date, + default_arrival_hour) + departure = "%s %s" % (checkin_partner.exit_date, + default_departure_hour) + stay = {'Code': checkin_partner.id} + stay['Id'] = checkin_partner.id stay['Room'] = {} - stay['Room']['Id'] = reserva.reservation_id.room_id.id - stay['Room']['Name'] = reserva.reservation_id.room_id.name + stay['Room']['Id'] = checkin_partner.reservation_id.room_id.id + stay['Room']['Name'] = checkin_partner.reservation_id.room_id.name stay['RoomType'] = {} - stay['RoomType']['Id'] = reserva.reservation_id.room_type_id.id - stay['RoomType']['Name'] = reserva.reservation_id.room_type_id.name - stay['RoomType']['GuestNumber'] = "xxxxxxx" - stay['Arrival'] = (reserva.reservation_id.real_checkin + - 'T' + reserva.reservation_id.arrival_hour + ':00') - stay['Departure'] = (reserva.reservation_id.real_checkout + - 'T' + - reserva.reservation_id.departure_hour + ':00') + stay['RoomType']['Id'] = checkin_partner.reservation_id.room_type_id.id + stay['RoomType']['Name'] = checkin_partner.reservation_id.room_type_id.name + stay['Arrival'] = arrival + stay['Departure'] = departure stay['Customers'] = [] - for idx, cpi in enumerate(reserva.reservation_id.checkin_partner_ids): + for idx, cpi in enumerate(checkin_partner.reservation_id.checkin_partner_ids): stay['Customers'].append({'Customer': {}}) stay['Customers'][idx]['Customer'] = self.env[ 'res.partner'].rm_get_a_customer(cpi.partner_id.id) @@ -103,13 +93,12 @@ class HotelFolio(models.Model): stay['TimeInterval']['Id'] = {} stay['TimeInterval']['Name'] = {} stay['TimeInterval']['Minutes'] = {} - stay['Adults'] = reserva.reservation_id.adults + stay['Adults'] = checkin_partner.reservation_id.adults stay['ReservationCode'] = {} - stay['Total'] = reserva.reservation_id.price_total - stay['Paid'] = (stay['Total'] - - reserva.reservation_id.folio_pending_amount) - stay['Outstanding'] = {} - stay['Taxable'] = reserva.reservation_id.price_tax + stay['Total'] = checkin_partner.reservation_id.price_total + stay['Paid'] = checkin_partner.reservation_id.folio_id.invoices_paid + stay['Outstanding'] = checkin_partner.reservation_id.folio_id.pending_amount + stay['Taxable'] = checkin_partner.reservation_id.price_tax else: stay = {'Code': ""} diff --git a/hotel_roommatik/models/inherited_hotel_reservation.py b/hotel_roommatik/models/inherited_hotel_reservation.py index 8d603db48..8c5e4a553 100644 --- a/hotel_roommatik/models/inherited_hotel_reservation.py +++ b/hotel_roommatik/models/inherited_hotel_reservation.py @@ -10,16 +10,33 @@ from dateutil import tz import json import logging _logger = logging.getLogger(__name__) -import random - class HotelReservation(models.Model): _inherit = 'hotel.reservation' + @api.model + def _computed_deposit_roommatik(self, rm_localizator): + reservations = self.env['hotel.reservation'].search([ + ('localizator', '=', rm_localizator)]) + folio = reservations[0].folio_id + # We dont have the payments by room, that's why we have to computed + # the proportional deposit part if the folio has more rooms that the + # reservations code (this happens when in the same folio are + # reservations with different checkins/outs convinations) + if len(folio.room_lines) > len(reservations) and folio.invoices_paid > 0: + + total_reservations = sum(reservations.mapped('price_total')) + paid_in_folio = folio.invoices_paid + total_in_folio = folio.amount_total + deposit = total_reservations * paid_in_folio / total_in_folio + return deposit + return folio.invoices_paid + + @api.model def rm_get_reservation(self, code): - # BÚSQUEDA DE RESERVA POR LOCALIZADOR + # Search by localizator reservations = self._get_reservations_roommatik(code) reservations = reservations.filtered( lambda x: x.state in ('draft', 'confirm')) @@ -38,7 +55,7 @@ class HotelReservation(models.Model): 'Id': reservations[0].localizator, 'Arrival': checkin, 'Departure': checkout, - 'Deposit': reservations[0].folio_id.invoices_paid, + 'Deposit': self._computed_deposit_roommatik(code) } } for i, line in enumerate(reservations): diff --git a/hotel_roommatik/models/inherited_res_partner.py b/hotel_roommatik/models/inherited_res_partner.py index c967bce87..6dd95e0b3 100755 --- a/hotel_roommatik/models/inherited_res_partner.py +++ b/hotel_roommatik/models/inherited_res_partner.py @@ -53,10 +53,10 @@ class ResPartner(models.Model): if customer['Sex'] not in {'male', 'female'}: customer['Sex'] = '' # Check state_id - city_srch = self.env['res.country.state'].search([ + state = self.env['res.country.state'].search([ ('name', 'ilike', customer['Address']['Province'])]) country = self.env['res.country'].search([ - ('name', 'ilike', customer['Address']['Province'])]) + ('code_alpha3', '=', customer['Address']['Country'])]) # Create Street2s street_2 = customer['Address']['House'] street_2 += ' ' + customer['Address']['Flat'] @@ -72,17 +72,17 @@ class ResPartner(models.Model): 'city': customer['Address']['City'], 'street': customer['Address']['Street'], 'street2': street_2, - 'state_id': city_srch.id, + 'state_id': state.id if state else False, + 'country': country.id if country else False, 'phone': customer['Contact']['Telephone'], 'mobile': customer['Contact']['Mobile'], 'email': customer['Contact']['Email'], 'document_number': customer['IdentityDocument']['Number'], 'document_type': customer['IdentityDocument']['Type'], 'document_expedition_date': datetime.strptime(customer[ - 'IdentityDocument']['ExpeditionDate'], - "%d%m%Y").date(), + 'IdentityDocument']['ExpeditionDate'], "%d%m%Y").date(), } - return {k: v for k, v in metadata.items() if v is not ""} + return {k: v for k, v in metadata.items() if v != ""} def rm_get_a_customer(self, customer): # Prepare a Customer for RoomMatik @@ -94,26 +94,27 @@ class ResPartner(models.Model): response['LastName2'] = partner.lastname2 response['Birthday'] = partner.birthdate_date response['Sex'] = partner.gender - response['Address'] = {'Nationality': {}, - 'Country': partner.country_id.name, - 'ZipCode': partner.zip, - 'City': partner.city, - 'Street': partner.street, - 'House': partner.street2, - # 'Flat': "xxxxxxx", - # 'Number': "xxxxxxx", - 'Province': partner.state_id.name, - } + response['Address'] = { + # 'Nationality': 'xxxxx' + 'Country': partner.country_id.code_alpha3, + 'ZipCode': partner.zip, + 'City': partner.city, + 'Street': partner.street, + 'House': partner.street2, + # 'Flat': "xxxxxxx", + # 'Number': "xxxxxxx", + 'Province': partner.state_id.name, + } response['IdentityDocument'] = { - 'Number': partner.document_number, - 'Type': partner.document_type, - 'ExpiryDate': "", - 'ExpeditionDate': partner.document_expedition_date, - } + 'Number': partner.document_number, + 'Type': partner.document_type, + 'ExpiryDate': "", + 'ExpeditionDate': partner.document_expedition_date, + } response['Contact'] = { - 'Telephone': partner.phone, - # 'Fax': 'xxxxxxx', - 'Mobile': partner.mobile, - 'Email': partner.email, - } + 'Telephone': partner.phone, + # 'Fax': 'xxxxxxx', + 'Mobile': partner.mobile, + 'Email': partner.email, + } return response diff --git a/hotel_roommatik/models/roommatik.py b/hotel_roommatik/models/roommatik.py index b6e6b898b..4ac417913 100755 --- a/hotel_roommatik/models/roommatik.py +++ b/hotel_roommatik/models/roommatik.py @@ -76,6 +76,21 @@ class RoomMatik(models.Model): apidata = self.env['hotel.room.type'] return apidata.rm_get_prices(start_date, number_intervals, room_type, guest_number) + @api.model + def _rm_add_payment(self, code, payment): + apidata = self.env['account.payment'] + reservation = self.env['hotel.reservation'].search([ + '|', ('localizator', '=', code), + ('folio_id.name', '=', code)]) + if reservation: + for cashpay in payment['PaymentTransaction']['CashPayments']: + + for cashpay in payment['PaymentTransaction']['CreditCardPayments:']: + + + + + return apidata.rm_checkin_partner(stay) # Debug Stop ------------------- # import wdb; wdb.set_trace() # Debug Stop -------------------