From 8cb90d72649a189e36e45cef003bbff245b6de3f Mon Sep 17 00:00:00 2001 From: Dario Lodeiros Date: Wed, 13 Mar 2019 15:21:10 +0100 Subject: [PATCH] [FIX] unit price computed taxes --- hotel/models/hotel_reservation.py | 4 +- .../views/inherited_account_payment_views.xml | 2 +- hotel/wizard/wizard_reservation.py | 137 ++++++------------ hotel/wizard/wizard_reservation.xml | 20 +-- 4 files changed, 57 insertions(+), 106 deletions(-) diff --git a/hotel/models/hotel_reservation.py b/hotel/models/hotel_reservation.py index 61c969c69..3c82825d2 100644 --- a/hotel/models/hotel_reservation.py +++ b/hotel/models/hotel_reservation.py @@ -891,8 +891,8 @@ class HotelReservation(models.Model): date=idate, pricelist=pricelist_id, uom=product.uom_id.id) - line_price = self.env['account.tax']._fix_tax_included_price_company( - product.price, product.taxes_id, self.tax_ids, self.company_id) + # REVIEW this forces to have configured the taxes included in the price + line_price = product.price if old_line and old_line.id: cmds.append((1, old_line.id, { 'price': line_price diff --git a/hotel/views/inherited_account_payment_views.xml b/hotel/views/inherited_account_payment_views.xml index 6a66142d6..1d469e064 100644 --- a/hotel/views/inherited_account_payment_views.xml +++ b/hotel/views/inherited_account_payment_views.xml @@ -8,7 +8,7 @@ - + diff --git a/hotel/wizard/wizard_reservation.py b/hotel/wizard/wizard_reservation.py index 05fee32e5..b96753e21 100644 --- a/hotel/wizard/wizard_reservation.py +++ b/hotel/wizard/wizard_reservation.py @@ -49,7 +49,17 @@ class FolioWizard(models.TransientModel): if user.has_group('hotel.group_hotel_call'): return 'phone' - partner_id = fields.Many2one('res.partner',string="Customer") + @api.model + def _get_default_pricelist(self): + return self.env['ir.default'].sudo().get( + 'res.config.settings', 'default_pricelist_id') + + partner_id = fields.Many2one('res.partner', required=True, string="Customer") + pricelist_id = fields.Many2one('product.pricelist', + string='Pricelist', + required=True, + default=_get_default_pricelist, + help="Pricelist for current folio.") checkin = fields.Date('Check In', required=True, default=_get_default_checkin) checkout = fields.Date('Check Out', required=True, @@ -68,13 +78,28 @@ class FolioWizard(models.TransientModel): ('mail', 'Mail'), ('phone', 'Phone') ], string='Sales Channel', default=_get_default_channel_type) - room_type_wizard_ids = fields.Many2many('hotel.room.type.wizard', - string="Room Types") + room_type_wizard_ids = fields.One2many('hotel.room.type.wizard', + 'folio_wizard_id', + string="Room Types") call_center = fields.Boolean(default=_get_default_center_user) def assign_rooms(self): self.assign = True + @api.onchange('pricelist_id') + def onchange_pricelist_id(self): + if self.pricelist_id: + self.onchange_checks() + + @api.onchange('partner_id') + def onchange_partner_id(self): + if self.partner_id: + pricelist = self.partner_id.property_product_pricelist and \ + self.partner_id.property_product_pricelist.id or \ + self.env['ir.default'].sudo().get( + 'res.config.settings', 'default_pricelist_id') + self.pricelist_id = pricelist + @api.onchange('autoassign') def create_reservations(self): self.ensure_one() @@ -103,10 +128,7 @@ class FolioWizard(models.TransientModel): checkout_dt = fields.Date.from_string(line.checkout) nights = abs((checkout_dt - checkin_dt).days) for room in room_list: - pricelist_id = self.env['ir.default'].sudo().get( - 'res.config.settings', 'default_pricelist_id') - if pricelist_id: - pricelist_id = int(pricelist_id) + pricelist_id = self.pricelist_id.id res_price = 0 for i in range(0, nights): ndate = checkin_dt + timedelta(days=i) @@ -198,6 +220,7 @@ class FolioWizard(models.TransientModel): services = [(5, False, False)] if self.autoassign: self.create_reservations() + import wdb; wdb.set_trace() for line in self.reservation_wizard_ids: reservations.append((0, False, { 'room_id': line.room_id.id, @@ -297,16 +320,9 @@ class HotelRoomTypeWizards(models.TransientModel): dates.append(ndate_str) if minstay_restrictions: date_min_days = minstay_restrictions.filtered( - lambda r: r.date_start <= ndate_str and \ - r.date_end >= ndate_str).min_stay + lambda r: r.date == ndate_str).min_stay if date_min_days > min_stay: min_stay = date_min_days - if user.has_group('hotel.group_hotel_call'): - if avail_restrictions: - max_avail = avail_restrictions.filtered( - lambda r: r.date == ndate_str).wmax_avail - if max_avail < avail: - avail = min(max_avail, real_max) else: avail = real_max @@ -330,12 +346,7 @@ class HotelRoomTypeWizards(models.TransientModel): if chkin_utc_dt >= chkout_utc_dt: chkout_utc_dt = chkin_utc_dt + timedelta(days=1) nights = abs((chkout_utc_dt - chkin_utc_dt).days) - - pricelist_id = self.env['ir.default'].sudo().get( - 'res.config.settings', 'default_pricelist_id') - if pricelist_id: - pricelist_id = int(pricelist_id) - + pricelist_id = self.folio_wizard_id.pricelist_id.id res_price = 0 for i in range(0, nights): ndate = chkin_utc_dt + timedelta(days=i) @@ -347,8 +358,7 @@ class HotelRoomTypeWizards(models.TransientModel): date=ndate_str, pricelist=pricelist_id, uom=record.room_type_id.product_id.uom_id.id) - res_price += self.env['account.tax']._fix_tax_included_price_company( - product.price, product.taxes_id, product.taxes_id, self.env.user.company_id) + res_price += product.price price = res_price - ((res_price * record.discount) * 0.01) total_price = record.rooms_num * price @@ -427,10 +437,7 @@ class ReservationWizard(models.TransientModel): end_date_utc_dt = fields.Date.from_string(line.checkout) if line.room_type_id: - pricelist_id = self.env['ir.default'].sudo().get( - 'res.config.settings', 'default_pricelist_id') - if pricelist_id: - pricelist_id = int(pricelist_id) + pricelist_id = self.folio_wizard_id.pricelist_id.id nights = abs((end_date_utc_dt - start_date_utc_dt).days) res_price = 0 for i in range(0, nights): @@ -443,8 +450,7 @@ class ReservationWizard(models.TransientModel): date=ndate_str, pricelist=pricelist_id, uom=line.room_type_id.product_id.uom_id.id) - res_price += self.env['account.tax']._fix_tax_included_price_company( - product.price, product.taxes_id, product.taxes_id, self.env.user.company_id) + res_price += product.price res_price = res_price - (res_price * self.discount) * 0.01 line.amount_reservation = res_price line.price = res_price @@ -469,7 +475,6 @@ class ServiceWizard(models.TransientModel): default=0.0) price_total = fields.Float(compute='_compute_amount', string='Subtotal', readonly=True, store=True) - reservation_wizard_ids = fields.Many2many('hotel.reservation.wizard', 'Rooms') product_uom_qty = fields.Float(string='Quantity', digits=dp.get_precision('Product Unit of Measure'), required=True, @@ -478,70 +483,16 @@ class ServiceWizard(models.TransientModel): @api.onchange('product_id', 'reservation_wizard_ids') def onchange_product_id(self): if self.product_id: - vals = {} - qty = 0 - vals['product_uom_qty'] = 1.0 - service_obj = self.env['hotel.service'] - if self.product_id.per_day: - product = self.product_id - for room in self.reservation_wizard_ids: - lines = {} - lines.update(service_obj.prepare_service_lines( - dfrom=room.checkin, - days=room.nights, - per_person=product.per_person, - persons=room.adults)) - qty += lines.get('service_line_ids')[1][2]['day_qty'] - if self.product_id.daily_limit > 0: - limit = self.product_id.daily_limit - for day in self.service_line_ids: - out_qty = sum(self.env['hotel.service.line'].search([ - ('product_id', '=', self.product_id.id), - ('date', '=', self.date), - ('service_id', '!=', self.product_id.id) - ]).mapped('day_qty')) - if limit < out_qty + self.day_qty: - raise ValidationError( - _("%s limit exceeded for %s")% (self.service_id.product_id.name, - self.date)) - vals['product_uom_qty'] = qty - """ - Description and warnings - """ - product = self.product_id.with_context( - lang=self.folio_wizard_id.partner_id.lang, - partner=self.folio_wizard_id.partner_id.id - ) - title = False - message = False - warning = {} - if product.sale_line_warn != 'no-message': - title = _("Warning for %s") % product.name - message = product.sale_line_warn_msg - warning['title'] = title - warning['message'] = message - result = {'warning': warning} - if product.sale_line_warn == 'block': - self.product_id = False - return result - """ - Compute tax and price unit - """ - #REVIEW: self._compute_tax_ids() # TODO change pricelist for partner - pricelist_id = self.env['ir.default'].sudo().get( - 'res.config.settings', 'default_pricelist_id') - product = self.product_id.with_context( - lang=self.folio_wizard_id.partner_id.lang, - partner=self.folio_wizard_id.partner_id.id, - quantity=1, - date=fields.Datetime.now(), - pricelist=pricelist_id, - uom=product.uom_id.id) - vals['price_unit'] = self.env['account.tax']._fix_tax_included_price_company( - product.price, product.taxes_id, product.taxes_id, self.env.user.company_id) - import wdb; wdb.set_trace() - self.update(vals) + pricelist_id = self.folio_wizard_id.pricelist_id.id + prod = self.product_id.with_context( + lang=self.folio_wizard_id.partner_id.lang, + partner=self.folio_wizard_id.partner_id.id, + quantity=1, + date=fields.Datetime.now(), + pricelist=pricelist_id, + uom=self.product_id.uom_id.id) + self.price_unit = prod.price @api.depends('price_unit', 'product_uom_qty', 'discount') def _compute_amount(self): diff --git a/hotel/wizard/wizard_reservation.xml b/hotel/wizard/wizard_reservation.xml index 382ff6c84..e5d6e8064 100644 --- a/hotel/wizard/wizard_reservation.xml +++ b/hotel/wizard/wizard_reservation.xml @@ -11,11 +11,12 @@ + - - + + @@ -27,13 +28,14 @@ decoration-success="max_rooms >= rooms_num and rooms_num > 0"> - - + + + - - - + + + @@ -56,7 +58,7 @@ - + @@ -76,8 +78,6 @@ -