diff --git a/hotel_calendar/__manifest__.py b/hotel_calendar/__manifest__.py index 0f123751b..b85d29a60 100644 --- a/hotel_calendar/__manifest__.py +++ b/hotel_calendar/__manifest__.py @@ -25,7 +25,6 @@ 'views/inherited_res_users_views.xml', 'views/inherited_hotel_room_type_views.xml', 'views/inherited_hotel_room_views.xml', - 'views/room_pricelist_cached_views.xml', 'views/hotel_reservation_views.xml', 'views/hotel_calendar_management_views.xml', 'views/hotel_calendar_views.xml', diff --git a/hotel_calendar/models/__init__.py b/hotel_calendar/models/__init__.py index 7aa6dfff6..e8ac8c555 100644 --- a/hotel_calendar/models/__init__.py +++ b/hotel_calendar/models/__init__.py @@ -2,17 +2,15 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import hotel_calendar from . import bus_hotel_calendar -from . import room_pricelist_cached from . import hotel_calendar_management from . import inherited_hotel_reservation -from . import inherited_product_pricelist_item from . import inherited_res_users from . import inherited_hotel_room from . import inherited_hotel_room_type from . import inherited_hotel_room_type_restriction_item from . import inherited_hotel_room_type_availability from . import inherited_product_pricelist +from . import inherited_product_pricelist_item from . import inherited_hotel_folio -from . import ir_default from . import ir_actions_act_window_view from . import ir_ui_view diff --git a/hotel_calendar/models/inherited_hotel_reservation.py b/hotel_calendar/models/inherited_hotel_reservation.py index 3968a9993..b32bfcdde 100644 --- a/hotel_calendar/models/inherited_hotel_reservation.py +++ b/hotel_calendar/models/inherited_hotel_reservation.py @@ -235,14 +235,13 @@ class HotelReservation(models.Model): WHERE td.date < %s ) SELECT - TO_CHAR(gtd.date, 'DD/MM/YYYY') AS date, gtd.date AS o_date, - gtd.id AS room_type_id, pt.name, rpc.price, pt.list_price + TO_CHAR(gtd.date, 'DD/MM/YYYY') as date, gtd.id as room_type_id, + pt.name, ppi.fixed_price as price, pt.list_price FROM gen_table_days AS gtd - LEFT JOIN room_pricelist_cached AS rpc - ON rpc.date = gtd.date AND rpc.room_id = gtd.id LEFT JOIN hotel_room_type AS hrt ON hrt.id = gtd.id LEFT JOIN product_product AS pp ON pp.id = hrt.product_id LEFT JOIN product_template AS pt ON pt.id = pp.product_tmpl_id + LEFT JOIN product_pricelist_item AS ppi ON ppi.date_start = gtd.date AND ppi.date_end = gtd.date AND ppi.product_tmpl_id = pt.id WHERE gtd.id IN %s ORDER BY gtd.id ASC, gtd.date ASC ''', (dfrom_str, dto_str, tuple(room_types_ids.ids))) diff --git a/hotel_calendar/models/inherited_hotel_room_type.py b/hotel_calendar/models/inherited_hotel_room_type.py index eb254cc50..e72d30496 100644 --- a/hotel_calendar/models/inherited_hotel_room_type.py +++ b/hotel_calendar/models/inherited_hotel_room_type.py @@ -1,21 +1,9 @@ # Copyright 2018 Alexandre Díaz # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields, api +from odoo import models, fields class HotelRoomType(models.Model): _inherit = 'hotel.room.type' hcal_sequence = fields.Integer('Calendar Sequence', default=0) - - @api.multi - def unlink(self): - room_type_pr_cached_obj = self.env['room.pricelist.cached'] - for record in self: - pr_chached = room_type_pr_cached_obj.search([ - ('room_id', '=', record.id) - ]) - # Because 'pricelist.cached' is an isolated model, - # doesn't trigger 'ondelete'. Need call 'unlink' instead. - pr_chached.unlink() - return super(HotelRoomType, self).unlink() diff --git a/hotel_calendar/models/inherited_product_pricelist_item.py b/hotel_calendar/models/inherited_product_pricelist_item.py index 0c025e27e..ad93492dc 100644 --- a/hotel_calendar/models/inherited_product_pricelist_item.py +++ b/hotel_calendar/models/inherited_product_pricelist_item.py @@ -1,6 +1,6 @@ # Copyright 2018 Alexandre Díaz # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields, api +from odoo import models, api class ProductPricelistItem(models.Model): @@ -33,20 +33,6 @@ class ProductPricelistItem(models.Model): 'price': prod_price, 'id': self.id, }) - - room_pr_cached_obj = self.env['room.pricelist.cached'] - room_pr_cached_id = room_pr_cached_obj.search([ - ('room_id', '=', room_type.id), - ('date', '=', date_start), - ], limit=1) - if room_pr_cached_id: - room_pr_cached_id.write({'price': prod_price}) - else: - room_pr_cached_obj.create({ - 'room_id': room_type.id, - 'date': date_start, - 'price': prod_price, - }) return res @api.multi @@ -57,7 +43,6 @@ class ProductPricelistItem(models.Model): pricelist_default_id = int(pricelist_default_id) ret_vals = super(ProductPricelistItem, self).write(vals) - room_pr_cached_obj = self.env['room.pricelist.cached'] bus_calendar_obj = self.env['bus.hotel.calendar'] room_type_obj = self.env['hotel.room.type'] if vals.get('fixed_price'): @@ -87,19 +72,6 @@ class ProductPricelistItem(models.Model): 'price': prod_price, 'id': record.id, }) - - room_pr_cached_id = room_pr_cached_obj.search([ - ('room_id', '=', room_type.id), - ('date', '=', date_start), - ], limit=1) - if room_pr_cached_id: - room_pr_cached_id.write({'price': prod_price}) - else: - room_pr_cached_obj.create({ - 'room_id': room_type.id, - 'date': date_start, - 'price': prod_price, - }) return ret_vals @api.multi @@ -125,7 +97,6 @@ class ProductPricelistItem(models.Model): # Do Normal Stuff res = super(ProductPricelistItem, self).unlink() # Do extra operations - room_pr_cached_obj = self.env['room.pricelist.cached'] bus_calendar_obj = self.env['bus.hotel.calendar'] for vals in unlink_vals: pricelist_id = vals['pricelist_id'] @@ -144,12 +115,4 @@ class ProductPricelistItem(models.Model): 'price': prod.price, 'id': vals['id'], }) - - # Remove records from cache model - room_pr_cached_id = room_pr_cached_obj.search([ - ('room_id', '=', room_type.id), - ('date', '=', date_start), - ], limit=1) - if room_pr_cached_id: - room_pr_cached_id.unlink() return res diff --git a/hotel_calendar/models/ir_default.py b/hotel_calendar/models/ir_default.py deleted file mode 100644 index baf735d36..000000000 --- a/hotel_calendar/models/ir_default.py +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright 2018 Alexandre Díaz -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields, api -from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT - - -class IrDefault(models.Model): - _inherit = 'ir.default' - - @api.model - def set(self, model_name, field_name, value, user_id=False, company_id=False, condition=False): - super(IrDefault, self).set(model_name, field_name, value, user_id, company_id, condition) - if model_name == 'res.config.settings' and field_name == 'default_pricelist_id': - pricelist_id = int(value) - self.env['room.pricelist.cached'].search([]).unlink() - - pricelist_items = self.env['product.pricelist.item'].search([ - ('pricelist_id', '=', pricelist_id) - ]) - room_type_obj = self.env['hotel.room.type'] - room_pr_cached_obj = self.env['room.pricelist.cached'] - for pitem in pricelist_items: - date_start = pitem.date_start - product_tmpl_id = pitem.product_tmpl_id.id - fixed_price = pitem.fixed_price - room_type = room_type_obj.search([ - ('product_id.product_tmpl_id', '=', product_tmpl_id), - ], limit=1) - if room_type: - room_pr_cached_obj.create({ - 'room_id': room_type.id, - 'date': date_start, - 'price': fixed_price, - }) diff --git a/hotel_calendar/models/room_pricelist_cached.py b/hotel_calendar/models/room_pricelist_cached.py deleted file mode 100644 index 3514150b3..000000000 --- a/hotel_calendar/models/room_pricelist_cached.py +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2018 Alexandre Díaz -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields, api -from odoo.exceptions import ValidationError - - -class RoomPricelistCached(models.Model): - ''' - Cached Pricelist. Used only for Calendar Values - ''' - - _name = 'room.pricelist.cached' - - room_id = fields.Many2one('hotel.room.type', 'Virtual Room', - required=True, track_visibility='always') - price = fields.Float('Price', default=0.0) - date = fields.Date('Date', required=True, track_visibility='always') diff --git a/hotel_calendar/views/actions.xml b/hotel_calendar/views/actions.xml index 2dd031c3b..6648b557c 100644 --- a/hotel_calendar/views/actions.xml +++ b/hotel_calendar/views/actions.xml @@ -17,13 +17,6 @@ [('checkout','=', datetime.datetime.now().strftime('%Y-%m-%d'))] - - Room Pricelist Cached - room.pricelist.cached - form - tree,form - - Hotel Calendar hotel.calendar diff --git a/hotel_calendar/views/room_pricelist_cached_views.xml b/hotel_calendar/views/room_pricelist_cached_views.xml deleted file mode 100644 index 9ff9d3348..000000000 --- a/hotel_calendar/views/room_pricelist_cached_views.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - hotel.room.pricelist.cached.form - room.pricelist.cached - -
- - - - - - - -
-
-
- - - - hotel.room.pricelist.cached.tree - room.pricelist.cached - - - - - - - - - -