[DEL] Pricelist Cache Model

This commit is contained in:
Alexandre Díaz
2019-01-15 04:15:15 +01:00
parent 69efca6a85
commit 50525260e3
9 changed files with 6 additions and 151 deletions

View File

@@ -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',

View File

@@ -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

View File

@@ -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)))

View File

@@ -1,21 +1,9 @@
# Copyright 2018 Alexandre Díaz <dev@redneboa.es>
# 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()

View File

@@ -1,6 +1,6 @@
# Copyright 2018 Alexandre Díaz <dev@redneboa.es>
# 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

View File

@@ -1,34 +0,0 @@
# Copyright 2018 Alexandre Díaz <dev@redneboa.es>
# 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,
})

View File

@@ -1,17 +0,0 @@
# Copyright 2018 Alexandre Díaz <dev@redneboa.es>
# 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')

View File

@@ -17,13 +17,6 @@
<field name="domain">[('checkout','=', datetime.datetime.now().strftime('%Y-%m-%d'))]</field>
</record>
<record model="ir.actions.act_window" id="hotel_room_pricelist_cached_action_form_tree">
<field name="name">Room Pricelist Cached</field>
<field name="res_model">room.pricelist.cached</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<record model="ir.actions.act_window" id="hotel_calendar_action_form_tree">
<field name="name">Hotel Calendar</field>
<field name="res_model">hotel.calendar</field>

View File

@@ -1,34 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Form view of hotel room -->
<record model="ir.ui.view" id="hotel_room_pricelist_cached_view_form">
<field name="name">hotel.room.pricelist.cached.form</field>
<field name="model">room.pricelist.cached</field>
<field name="arch" type="xml">
<form string="Room Pricelist Cached">
<sheet>
<group>
<field name="room_id" />
<field name="date" />
<field name="price" />
</group>
</sheet>
</form>
</field>
</record>
<!-- Tree view of hotel room -->
<record model="ir.ui.view" id="hotel_room_pricelist_cached_view_tree">
<field name="name">hotel.room.pricelist.cached.tree</field>
<field name="model">room.pricelist.cached</field>
<field name="arch" type="xml">
<tree string="Room Pricelist Cached">
<field name="room_id" />
<field name="date" />
<field name="price" />
</tree>
</field>
</record>
</odoo>