From cc480e9c3288d6254e5c1fb76dedd6e031c3b898 Mon Sep 17 00:00:00 2001 From: Dario Lodeiros Date: Thu, 7 Feb 2019 14:06:39 +0100 Subject: [PATCH] [ADD] Compute tax excluded --- hotel/models/hotel_reservation.py | 10 +++++++--- hotel/models/hotel_reservation_line.py | 4 +++- .../views/inherited_hotel_reservation_views.xml | 2 +- .../models/hotel_reservation/importer.py | 16 ++++++++++------ 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/hotel/models/hotel_reservation.py b/hotel/models/hotel_reservation.py index a5e63a641..f7a868c3d 100644 --- a/hotel/models/hotel_reservation.py +++ b/hotel/models/hotel_reservation.py @@ -112,7 +112,7 @@ class HotelReservation(models.Model): line.invoice_status = 'invoiced' else: line.invoice_status = 'no' - + @api.model def name_search(self, name='', args=None, operator='ilike', limit=100): @@ -173,7 +173,7 @@ class HotelReservation(models.Model): track_visibility='onchange') reservation_type = fields.Selection(related='folio_id.reservation_type', default=lambda *a: 'normal') - invoice_count = fields.Integer(related='folio_id.invoice_count') + invoice_count = fields.Integer(related='folio_id.invoice_count') board_service_room_id = fields.Many2one('hotel.board.service.room.type', string='Board Service') cancelled_reason = fields.Selection([ @@ -305,10 +305,12 @@ class HotelReservation(models.Model): price_subtotal = fields.Monetary(string='Subtotal', readonly=True, store=True, + digits=dp.get_precision('Product Price'), compute='_compute_amount_reservation') price_total = fields.Monetary(string='Total', readonly=True, store=True, + digits=dp.get_precision('Product Price'), compute='_compute_amount_reservation') price_tax = fields.Float(string='Taxes', readonly=True, @@ -317,10 +319,12 @@ class HotelReservation(models.Model): price_services = fields.Monetary(string='Services Total', readonly=True, store=True, + digits=dp.get_precision('Product Price'). compute='_compute_amount_room_services') price_room_services_set = fields.Monetary(string='Room Services Total', readonly=True, store=True, + digits=dp.get_precision('Product Price'), compute='_compute_amount_set') discount = fields.Float(string='Discount (€)', digits=dp.get_precision('Discount'), @@ -347,7 +351,7 @@ class HotelReservation(models.Model): 'channel_type': vals.get('channel_type')}) if 'service_ids' in vals and vals['service_ids'][0][2]: for service in vals['service_ids']: - service[2]['folio_id'] = folio.id + service[2]['folio_id'] = folio.id vals.update({ 'last_updated_res': fields.Datetime.now(), }) diff --git a/hotel/models/hotel_reservation_line.py b/hotel/models/hotel_reservation_line.py index 7ee0fbf22..56e370f3d 100644 --- a/hotel/models/hotel_reservation_line.py +++ b/hotel/models/hotel_reservation_line.py @@ -23,7 +23,9 @@ class HotelReservationLine(models.Model): ondelete='cascade', required=True, copy=False) date = fields.Date('Date') - price = fields.Float('Price') + price = fields.Float( + string='Price', + digits=dp.get_precision('Product Price')) discount = fields.Float( string='Discount (%)', digits=dp.get_precision('Discount'), default=0.0) diff --git a/hotel_channel_connector/views/inherited_hotel_reservation_views.xml b/hotel_channel_connector/views/inherited_hotel_reservation_views.xml index 87ef10340..de7500e14 100644 --- a/hotel_channel_connector/views/inherited_hotel_reservation_views.xml +++ b/hotel_channel_connector/views/inherited_hotel_reservation_views.xml @@ -40,7 +40,7 @@ - {'readonly': [('able_to_modify_channel','=',False)]} + {'readonly': [('is_from_ota','=',True),('able_to_modify_channel','=',False)]} {'readonly': [('is_from_ota','=',True),('able_to_modify_channel','=',False)]} diff --git a/hotel_channel_connector_wubook/models/hotel_reservation/importer.py b/hotel_channel_connector_wubook/models/hotel_reservation/importer.py index f05b1bf5f..489909498 100644 --- a/hotel_channel_connector_wubook/models/hotel_reservation/importer.py +++ b/hotel_channel_connector_wubook/models/hotel_reservation/importer.py @@ -97,8 +97,12 @@ class HotelReservationImporter(Component): DEFAULT_WUBOOK_DATE_FORMAT ).replace(tzinfo=tz.gettz('UTC')) if dates_checkin[0] >= wndate <= (dates_checkout[0] - timedelta(days=1)): - # HOT-FIX: Hard-Coded Tax 10% - room_day_price = round(brday['price'] * 1.1, 2) if not tax_inclusive else brday['price'] + amount_day_tax = 0 + if not tax_inclusive: + price_subtotal = book['amount'] - broom['ancillary']['taxes'] + day_tax_weigh = brday['price'] * 100 / price_subtotal + amount_day_tax = broom['ancillary']['taxes'] * day_tax_weigh / 100 + room_day_price = brday['price'] + amount_day_tax reservation_lines.append((0, False, { 'date': wndate.strftime(DEFAULT_SERVER_DATE_FORMAT), 'price': room_day_price, @@ -114,6 +118,7 @@ class HotelReservationImporter(Component): 'external_id': rcode, 'ota_id': ota_id and ota_id.id, 'ota_reservation_id': crcode, + 'channel_status': str(book['status']), 'channel_raw_data': json.dumps(book), 'channel_modified': book['was_modified'], } @@ -122,7 +127,7 @@ class HotelReservationImporter(Component): 'checkout': checkout_str, 'adults': persons, 'children': book['children'], - 'reservation_lines': reservation_lines, + 'reservation_line_ids': reservation_lines, 'price_unit': tprice, 'to_assign': True, 'to_read': True, @@ -130,9 +135,8 @@ class HotelReservationImporter(Component): 'room_type_id': room_type_bind.odoo_id.id, 'splitted': split_booking, 'name': room_type_bind and room_type_bind.name, - 'channel_bind_ids': [(0, False, binding_vals)] + 'channel_bind_ids': [(0, False, binding_vals)], } - return vals @api.model @@ -447,7 +451,7 @@ class HotelReservationImporter(Component): rlines = sorted_rlines = folio_id.room_lines for rline in rlines: for rline_bind in rline.channel_bind_ids: - self.binder(rline_bind.external_id, rline_bind) + self.binder.bind(rline_bind.external_id, rline_bind) processed_rids.append(rcode) return (processed_rids, any(failed_reservations),