From abf2bae3af229d8aaec6bc87843401cbbd710102 Mon Sep 17 00:00:00 2001 From: Dario Lodeiros Date: Sun, 17 Mar 2019 18:53:41 +0100 Subject: [PATCH] [ADD] Price in service lines --- hotel/models/hotel_folio.py | 1 + hotel/models/hotel_reservation.py | 26 +++++++++++++++++++++--- hotel/models/hotel_reservation_line.py | 1 - hotel/models/hotel_service_line.py | 20 ++++++++++++++++++ hotel/views/hotel_service_line_views.xml | 9 ++++++-- hotel/wizard/wizard_reservation.py | 3 ++- 6 files changed, 53 insertions(+), 7 deletions(-) diff --git a/hotel/models/hotel_folio.py b/hotel/models/hotel_folio.py index 975854c4b..0e8661ed3 100644 --- a/hotel/models/hotel_folio.py +++ b/hotel/models/hotel_folio.py @@ -142,6 +142,7 @@ class HotelFolio(models.Model): channel_type = fields.Selection([('door', 'Door'), ('mail', 'Mail'), ('phone', 'Phone'), + ('call', 'Call Center'), ('web', 'Web')], 'Sales Channel', default='door') user_id = fields.Many2one('res.users', string='Salesperson', index=True, track_visibility='onchange', default=lambda self: self.env.user) diff --git a/hotel/models/hotel_reservation.py b/hotel/models/hotel_reservation.py index b1b35792d..87f49edef 100644 --- a/hotel/models/hotel_reservation.py +++ b/hotel/models/hotel_reservation.py @@ -78,6 +78,11 @@ class HotelReservation(models.Model): else: return default_departure_hour + @api.multi + def set_call_center_user(self): + user = self.env['res.users'].browse(self.env.uid) + return user.has_group('hotel.group_hotel_call') + @api.model def _default_diff_invoicing(self): """ @@ -270,6 +275,7 @@ class HotelReservation(models.Model): related='folio_id.internal_comment') preconfirm = fields.Boolean('Auto confirm to Save', default=True) to_send = fields.Boolean('To Send', default=True) + call_center = fields.Boolean(default='set_call_center_user') has_confirmed_reservations_to_send = fields.Boolean( related='folio_id.has_confirmed_reservations_to_send', readonly=True) @@ -352,6 +358,12 @@ class HotelReservation(models.Model): if 'service_ids' in vals and vals['service_ids'][0][2]: for service in vals['service_ids']: service[2]['folio_id'] = folio.id + user = self.env['res.users'].browse(self.env.uid) + if user.has_group('hotel.group_hotel_call'): + vals.update({ + 'to_assign': True, + 'channel_type': 'call' + }) vals.update({ 'last_updated_res': fields.Datetime.now(), }) @@ -427,10 +439,15 @@ class HotelReservation(models.Model): persons=service.ser_room_line.adults, old_line_days=service.service_line_ids )) - if ('checkin' in vals and record.checkin != vals['checkin']) or \ - ('checkout' in vals and record.checkout != vals['checkout']) or \ - ('state' in vals and record.state != vals['state']): + if ('checkin' in vals and record.checkin != vals['checkin']) or\ + ('checkout' in vals and record.checkout != vals['checkout']) or\ + ('state' in vals and record.state != vals['state']): record.update({'to_send': True}) + user = self.env['res.users'].browse(self.env.uid) + if user.has_group('hotel.group_hotel_call'): + vals.update({ + 'to_assign': True, + }) res = super(HotelReservation, self).write(vals) return res @@ -760,8 +777,11 @@ class HotelReservation(models.Model): ''' _logger.info('confirm') hotel_reserv_obj = self.env['hotel.reservation'] + user = self.env['res.users'].browse(self.env.uid) for record in self: vals = {} + if user.has_group('hotel.group_hotel_call'): + vals.update({'channel_type': 'call'}) if record.checkin_partner_ids: vals.update({'state': 'booking'}) else: diff --git a/hotel/models/hotel_reservation_line.py b/hotel/models/hotel_reservation_line.py index 56e370f3d..11432fe80 100644 --- a/hotel/models/hotel_reservation_line.py +++ b/hotel/models/hotel_reservation_line.py @@ -4,7 +4,6 @@ from odoo import models, fields, api, _ from odoo.addons import decimal_precision as dp from odoo.exceptions import ValidationError -from datetime import date class HotelReservationLine(models.Model): _name = "hotel.reservation.line" diff --git a/hotel/models/hotel_service_line.py b/hotel/models/hotel_service_line.py index 9b6585f1e..e7e986b84 100644 --- a/hotel/models/hotel_service_line.py +++ b/hotel/models/hotel_service_line.py @@ -14,6 +14,26 @@ class HotelServiceLine(models.Model): date = fields.Date('Date') day_qty = fields.Integer('Units') product_id = fields.Many2one(related='service_id.product_id', store=True) + price_total = fields.Float('Price Total', + compute='_compute_price_total', + store=True) + price_unit = fields.Float('Unit Price', + related="service_id.price_unit", + readonly=True, + store=True) + discount = fields.Float('Discount', + related="service_id.discount", + readonly=True, + store=True) + tax_ids = fields.Many2many('account.tax', + string='Taxes', + related="service_id.tax_ids", + readonly="True") + + @api.depends('day_qty', 'service_id.price_total') + def _compute_price_total(self): + for record in self: + record.price_total = (record.service_id.price_total * record.day_qty) / record.service_id.product_qty @api.constrains('day_qty') def no_free_resources(self): diff --git a/hotel/views/hotel_service_line_views.xml b/hotel/views/hotel_service_line_views.xml index a5d7a7db7..052990189 100644 --- a/hotel/views/hotel_service_line_views.xml +++ b/hotel/views/hotel_service_line_views.xml @@ -13,6 +13,7 @@ + @@ -37,9 +38,13 @@ - + + + + + @@ -96,7 +101,7 @@ res_model="hotel.service.line" view_mode="tree,form" view_id = "hotel.hotel_service_line_report_view_tree" /> - +