mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
Change parity by default
This commit is contained in:
@@ -267,10 +267,10 @@ class HotelCalendarManagement(models.TransientModel):
|
||||
vals = {}
|
||||
if not pricelist_id:
|
||||
pricelist_id = self.env['ir.default'].sudo().get(
|
||||
'res.config.settings', 'parity_pricelist_id')
|
||||
'res.config.settings', 'default_pricelist_id')
|
||||
if not restriction_id:
|
||||
restriction_id = self.env['ir.default'].sudo().get(
|
||||
'res.config.settings', 'parity_restrictions_id')
|
||||
'res.config.settings', 'default_restrictions_id')
|
||||
|
||||
pricelist_id = int(pricelist_id)
|
||||
vals.update({'pricelist_id': pricelist_id})
|
||||
|
||||
@@ -59,7 +59,7 @@ class HotelReservation(models.Model):
|
||||
@api.model
|
||||
def _hcalendar_room_data(self, rooms):
|
||||
pricelist_id = self.env['ir.default'].sudo().get(
|
||||
'res.config.settings', 'parity_pricelist_id')
|
||||
'res.config.settings', 'default_pricelist_id')
|
||||
if pricelist_id:
|
||||
pricelist_id = int(pricelist_id)
|
||||
json_rooms = []
|
||||
@@ -117,7 +117,7 @@ class HotelReservation(models.Model):
|
||||
@api.model
|
||||
def get_hcalendar_pricelist_data(self, dfrom, dto):
|
||||
pricelist_id = self.env['ir.default'].sudo().get(
|
||||
'res.config.settings', 'parity_pricelist_id')
|
||||
'res.config.settings', 'default_pricelist_id')
|
||||
if pricelist_id:
|
||||
pricelist_id = int(pricelist_id)
|
||||
date_start = fields.Date.from_string(dfrom) - timedelta(days=1)
|
||||
@@ -157,7 +157,7 @@ class HotelReservation(models.Model):
|
||||
@api.model
|
||||
def get_hcalendar_restrictions_data(self, dfrom, dto):
|
||||
restriction_id = self.env['ir.default'].sudo().get(
|
||||
'res.config.settings', 'parity_restrictions_id')
|
||||
'res.config.settings', 'default_restrictions_id')
|
||||
if restriction_id:
|
||||
restriction_id = int(restriction_id)
|
||||
date_start = fields.Date.from_string(dfrom) - timedelta(days=1)
|
||||
|
||||
@@ -11,12 +11,12 @@ class HotelRoomTypeResrtrictionItem(models.Model):
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
res = super(HotelRoomTypeResrtrictionItem, self).create(vals)
|
||||
restrictions_parity_id = self.env['ir.default'].sudo().get(
|
||||
'res.config.settings', 'parity_restrictions_id')
|
||||
if restrictions_parity_id:
|
||||
restrictions_parity_id = int(restrictions_parity_id)
|
||||
restrictions_default_id = self.env['ir.default'].sudo().get(
|
||||
'res.config.settings', 'default_restrictions_id')
|
||||
if restrictions_default_id:
|
||||
restrictions_default_id = int(restrictions_default_id)
|
||||
restriction_id = res.restriction_id.id
|
||||
if restriction_id == restrictions_parity_id and \
|
||||
if restriction_id == restrictions_default_id and \
|
||||
self.applied_on == '0_room_type':
|
||||
self.env['bus.hotel.calendar'].send_restriction_notification({
|
||||
'restriction_id': self.restriction_id.id,
|
||||
@@ -35,15 +35,15 @@ class HotelRoomTypeResrtrictionItem(models.Model):
|
||||
|
||||
@api.multi
|
||||
def write(self, vals):
|
||||
restrictions_parity_id = self.env['ir.default'].sudo().get(
|
||||
'res.config.settings', 'parity_restrictions_id')
|
||||
if restrictions_parity_id:
|
||||
restrictions_parity_id = int(restrictions_parity_id)
|
||||
restrictions_default_id = self.env['ir.default'].sudo().get(
|
||||
'res.config.settings', 'default_restrictions_id')
|
||||
if restrictions_default_id:
|
||||
restrictions_default_id = int(restrictions_default_id)
|
||||
ret_vals = super(HotelRoomTypeResrtrictionItem, self).write(vals)
|
||||
|
||||
bus_hotel_calendar_obj = self.env['bus.hotel.calendar']
|
||||
for record in self:
|
||||
if record.restriction_id.id != restrictions_parity_id or \
|
||||
if record.restriction_id.id != restrictions_default_id or \
|
||||
record.applied_on != '0_room_type':
|
||||
continue
|
||||
bus_hotel_calendar_obj.send_restriction_notification({
|
||||
@@ -63,14 +63,14 @@ class HotelRoomTypeResrtrictionItem(models.Model):
|
||||
|
||||
@api.multi
|
||||
def unlink(self):
|
||||
restrictions_parity_id = self.env['ir.default'].sudo().get(
|
||||
'res.config.settings', 'parity_restrictions_id')
|
||||
if restrictions_parity_id:
|
||||
restrictions_parity_id = int(restrictions_parity_id)
|
||||
restrictions_default_id = self.env['ir.default'].sudo().get(
|
||||
'res.config.settings', 'default_restrictions_id')
|
||||
if restrictions_default_id:
|
||||
restrictions_default_id = int(restrictions_default_id)
|
||||
# Construct dictionary with relevant info of removed records
|
||||
unlink_vals = []
|
||||
for record in self:
|
||||
if record.restriction_id.id != restrictions_parity_id or \
|
||||
if record.restriction_id.id != restrictions_default_id or \
|
||||
record.applied_on != '0_room_type':
|
||||
continue
|
||||
unlink_vals.append({
|
||||
|
||||
@@ -10,7 +10,7 @@ class IrDefault(models.Model):
|
||||
@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 == 'parity_pricelist_id':
|
||||
if model_name == 'res.config.settings' and field_name == 'default_pricelist_id':
|
||||
pricelist_id = int(value)
|
||||
self.env['room.pricelist.cached'].search([]).unlink()
|
||||
|
||||
|
||||
@@ -9,17 +9,17 @@ class ProductPricelistItem(models.Model):
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
res = super(ProductPricelistItem, self).create(vals)
|
||||
pricelist_parity_id = self.env['ir.default'].sudo().get(
|
||||
'res.config.settings', 'parity_pricelist_id')
|
||||
if pricelist_parity_id:
|
||||
pricelist_parity_id = int(pricelist_parity_id)
|
||||
pricelist_default_id = self.env['ir.default'].sudo().get(
|
||||
'res.config.settings', 'default_pricelist_id')
|
||||
if pricelist_default_id:
|
||||
pricelist_default_id = int(pricelist_default_id)
|
||||
pricelist_id = res.pricelist_id.id
|
||||
product_tmpl_id = res.product_tmpl_id.id
|
||||
date_start = res.date_start
|
||||
room_type = self.env['hotel.room.type'].search([
|
||||
('product_id.product_tmpl_id', '=', product_tmpl_id)
|
||||
], limit=1)
|
||||
if pricelist_id == pricelist_parity_id and room_type:
|
||||
if pricelist_id == pricelist_default_id and room_type:
|
||||
prod = room_type.product_id.with_context(
|
||||
quantity=1,
|
||||
date=date_start,
|
||||
@@ -51,10 +51,10 @@ class ProductPricelistItem(models.Model):
|
||||
|
||||
@api.multi
|
||||
def write(self, vals):
|
||||
pricelist_parity_id = self.env['ir.default'].sudo().get(
|
||||
'res.config.settings', 'parity_pricelist_id')
|
||||
if pricelist_parity_id:
|
||||
pricelist_parity_id = int(pricelist_parity_id)
|
||||
pricelist_default_id = self.env['ir.default'].sudo().get(
|
||||
'res.config.settings', 'default_pricelist_id')
|
||||
if pricelist_default_id:
|
||||
pricelist_default_id = int(pricelist_default_id)
|
||||
ret_vals = super(ProductPricelistItem, self).write(vals)
|
||||
|
||||
room_pr_cached_obj = self.env['room.pricelist.cached']
|
||||
@@ -64,7 +64,7 @@ class ProductPricelistItem(models.Model):
|
||||
for record in self:
|
||||
pricelist_id = vals.get('pricelist_id') or \
|
||||
record.pricelist_id.id
|
||||
if pricelist_id != pricelist_parity_id:
|
||||
if pricelist_id != pricelist_default_id:
|
||||
continue
|
||||
date_start = vals.get('date_start') or record.date_start
|
||||
product_tmpl_id = vals.get('product_tmpl_id') or \
|
||||
@@ -104,14 +104,14 @@ class ProductPricelistItem(models.Model):
|
||||
|
||||
@api.multi
|
||||
def unlink(self):
|
||||
pricelist_parity_id = self.env['ir.default'].sudo().get(
|
||||
'res.config.settings', 'parity_pricelist_id')
|
||||
if pricelist_parity_id:
|
||||
pricelist_parity_id = int(pricelist_parity_id)
|
||||
pricelist_default_id = self.env['ir.default'].sudo().get(
|
||||
'res.config.settings', 'default_pricelist_id')
|
||||
if pricelist_default_id:
|
||||
pricelist_default_id = int(pricelist_default_id)
|
||||
# Construct dictionary with relevant info of removed records
|
||||
unlink_vals = []
|
||||
for record in self:
|
||||
if record.pricelist_id.id != pricelist_parity_id:
|
||||
if record.pricelist_id.id != pricelist_default_id:
|
||||
continue
|
||||
room_type = self.env['hotel.room.type'].search([
|
||||
('product_id.product_tmpl_id', '=', record.product_tmpl_id.id)
|
||||
|
||||
@@ -31,8 +31,8 @@ class TestHotelCalendar(TestHotel):
|
||||
|
||||
# Minimal Hotel Calendar Configuration
|
||||
cls.tz_hotel = 'Europe/Madrid'
|
||||
cls.parity_pricelist_id = cls.pricelist_1.id
|
||||
cls.parity_restrictions_id = cls.restriction_1.id
|
||||
cls.default_pricelist_id = cls.pricelist_1.id
|
||||
cls.default_restrictions_id = cls.restriction_1.id
|
||||
cls.env['ir.default'].sudo().set_default('res.config.settings',
|
||||
'default_arrival_hour',
|
||||
'14:00')
|
||||
|
||||
@@ -45,8 +45,8 @@ class TestManagementCalendar(TestHotelCalendar):
|
||||
hcal_data = hotel_cal_mngt_obj.get_hcalendar_all_data(
|
||||
now_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
adv_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
self.parity_pricelist_id,
|
||||
self.parity_restrictions_id,
|
||||
self.default_pricelist_id,
|
||||
self.default_restrictions_id,
|
||||
True)
|
||||
for room_type in room_types:
|
||||
for k_pr, v_pr in hcal_data['prices'].iteritems():
|
||||
@@ -67,7 +67,7 @@ class TestManagementCalendar(TestHotelCalendar):
|
||||
self.hotel_room_type_special.product_id.product_tmpl_id.id
|
||||
)
|
||||
pr_ids = prices_obj.search([
|
||||
('pricelist_id', '=', self.parity_pricelist_id),
|
||||
('pricelist_id', '=', self.default_pricelist_id),
|
||||
('product_tmpl_id', 'in', prod_tmpl_ids),
|
||||
])
|
||||
pr_ids.sudo(self.user_hotel_manager).unlink()
|
||||
@@ -75,8 +75,8 @@ class TestManagementCalendar(TestHotelCalendar):
|
||||
hcal_data = hotel_cal_mngt_obj.get_hcalendar_all_data(
|
||||
now_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
adv_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
self.parity_pricelist_id,
|
||||
self.parity_restrictions_id,
|
||||
self.default_pricelist_id,
|
||||
self.default_restrictions_id,
|
||||
True)
|
||||
self.assertFalse(any(hcal_data['prices']), "Hotel Calendar Management \
|
||||
Prices doesn't match after remove!")
|
||||
@@ -92,8 +92,8 @@ class TestManagementCalendar(TestHotelCalendar):
|
||||
hcal_data = hotel_cal_mngt_obj.get_hcalendar_all_data(
|
||||
now_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
adv_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
self.parity_pricelist_id,
|
||||
self.parity_restrictions_id,
|
||||
self.default_pricelist_id,
|
||||
self.default_restrictions_id,
|
||||
True)
|
||||
for room_type in room_types:
|
||||
for k_pr, v_pr in hcal_data['restrictions'].iteritems():
|
||||
@@ -113,7 +113,7 @@ class TestManagementCalendar(TestHotelCalendar):
|
||||
self.user_hotel_manager)
|
||||
rest_ids = rest_it_obj.search([
|
||||
('applied_on', '=', '0_room_type'),
|
||||
('restriction_id', '=', self.parity_restrictions_id),
|
||||
('restriction_id', '=', self.default_restrictions_id),
|
||||
('room_type_id', 'in', (self.hotel_room_type_budget.id,
|
||||
self.hotel_room_type_special.id)),
|
||||
])
|
||||
@@ -122,8 +122,8 @@ class TestManagementCalendar(TestHotelCalendar):
|
||||
hcal_data = hotel_cal_mngt_obj.get_hcalendar_all_data(
|
||||
now_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
adv_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
self.parity_pricelist_id,
|
||||
self.parity_restrictions_id,
|
||||
self.default_pricelist_id,
|
||||
self.default_restrictions_id,
|
||||
True)
|
||||
self.assertFalse(
|
||||
any(hcal_data['restrictions']),
|
||||
@@ -143,8 +143,8 @@ class TestManagementCalendar(TestHotelCalendar):
|
||||
hcal_data = hotel_cal_mngt_obj.get_hcalendar_all_data(
|
||||
now_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
adv_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
self.parity_pricelist_id,
|
||||
self.parity_restrictions_id,
|
||||
self.default_pricelist_id,
|
||||
self.default_restrictions_id,
|
||||
True)
|
||||
for room_type in room_types:
|
||||
for k_pr, v_pr in hcal_data['availability'].iteritems():
|
||||
@@ -168,8 +168,8 @@ class TestManagementCalendar(TestHotelCalendar):
|
||||
hcal_data = hotel_cal_mngt_obj.get_hcalendar_all_data(
|
||||
now_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
adv_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
self.parity_pricelist_id,
|
||||
self.parity_restrictions_id,
|
||||
self.default_pricelist_id,
|
||||
self.default_restrictions_id,
|
||||
True)
|
||||
for room_type in room_types:
|
||||
for k_pr, v_pr in hcal_data['availability'].iteritems():
|
||||
@@ -191,8 +191,8 @@ class TestManagementCalendar(TestHotelCalendar):
|
||||
hcal_data = hotel_cal_mngt_obj.get_hcalendar_all_data(
|
||||
now_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
adv_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
self.parity_pricelist_id,
|
||||
self.parity_restrictions_id,
|
||||
self.default_pricelist_id,
|
||||
self.default_restrictions_id,
|
||||
True)
|
||||
for room_type in room_types:
|
||||
for k_pr, v_pr in hcal_data['availability'].iteritems():
|
||||
@@ -260,8 +260,8 @@ class TestManagementCalendar(TestHotelCalendar):
|
||||
|
||||
# Save new values
|
||||
hotel_cal_mngt_obj.save_changes(
|
||||
self.parity_pricelist_id,
|
||||
self.parity_restrictions_id,
|
||||
self.default_pricelist_id,
|
||||
self.default_restrictions_id,
|
||||
cprices,
|
||||
crestrictions,
|
||||
cavails)
|
||||
@@ -270,8 +270,8 @@ class TestManagementCalendar(TestHotelCalendar):
|
||||
hcal_data = hotel_cal_mngt_obj.get_hcalendar_all_data(
|
||||
now_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
adv_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
self.parity_pricelist_id,
|
||||
self.parity_restrictions_id,
|
||||
self.default_pricelist_id,
|
||||
self.default_restrictions_id,
|
||||
True)
|
||||
|
||||
for room_type in room_types:
|
||||
@@ -347,8 +347,8 @@ class TestManagementCalendar(TestHotelCalendar):
|
||||
hcal_data = hotel_cal_mngt_obj.get_hcalendar_all_data(
|
||||
now_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
adv_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
self.parity_pricelist_id,
|
||||
self.parity_restrictions_id,
|
||||
self.default_pricelist_id,
|
||||
self.default_restrictions_id,
|
||||
True)
|
||||
|
||||
avail_end_utc_dt = reserv_end_utc_dt - timedelta(days=1)
|
||||
@@ -376,22 +376,22 @@ class TestManagementCalendar(TestHotelCalendar):
|
||||
hcal_data = hotel_cal_mngt_obj.get_hcalendar_all_data(
|
||||
False,
|
||||
adv_utc_dt.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
|
||||
self.parity_pricelist_id,
|
||||
self.parity_restrictions_id,
|
||||
self.default_pricelist_id,
|
||||
self.default_restrictions_id,
|
||||
True)
|
||||
with self.assertRaises(ValidationError):
|
||||
hcal_data = hotel_cal_mngt_obj.get_hcalendar_all_data(
|
||||
now_utc_dt.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
|
||||
False,
|
||||
self.parity_pricelist_id,
|
||||
self.parity_restrictions_id,
|
||||
self.default_pricelist_id,
|
||||
self.default_restrictions_id,
|
||||
True)
|
||||
with self.assertRaises(ValidationError):
|
||||
hcal_data = hotel_cal_mngt_obj.get_hcalendar_all_data(
|
||||
False,
|
||||
False,
|
||||
self.parity_pricelist_id,
|
||||
self.parity_restrictions_id,
|
||||
self.default_pricelist_id,
|
||||
self.default_restrictions_id,
|
||||
True)
|
||||
hcal_data = hotel_cal_mngt_obj.get_hcalendar_all_data(
|
||||
now_utc_dt.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
@@ -400,7 +400,7 @@ class TestManagementCalendar(TestHotelCalendar):
|
||||
False,
|
||||
True)
|
||||
self.assertTrue(any(hcal_data), "Hotel Calendar invalid default \
|
||||
management parity models!")
|
||||
management default models!")
|
||||
|
||||
def test_calendar_settings(self):
|
||||
hotel_cal_mngt_obj = self.env['hotel.calendar.management'].sudo(
|
||||
|
||||
@@ -34,7 +34,7 @@ class TestProductPricelist(TestHotelCalendar):
|
||||
|
||||
pritem_obj = self.env['product.pricelist.item']
|
||||
plitem = pritem_obj.search([
|
||||
('pricelist_id', '=', self.parity_pricelist_id),
|
||||
('pricelist_id', '=', self.default_pricelist_id),
|
||||
('product_tmpl_id', '=', room_type_tmpl_id.id),
|
||||
('date_start', '=', now_utc_str),
|
||||
('date_end', '=', now_utc_str),
|
||||
@@ -49,7 +49,7 @@ class TestProductPricelist(TestHotelCalendar):
|
||||
999.9)
|
||||
|
||||
plitem = pritem_obj.search([
|
||||
('pricelist_id', '=', self.parity_pricelist_id),
|
||||
('pricelist_id', '=', self.default_pricelist_id),
|
||||
('product_tmpl_id', '=', room_type_tmpl_id.id),
|
||||
('date_start', '=', now_utc_str),
|
||||
('date_end', '=', now_utc_str),
|
||||
|
||||
@@ -78,7 +78,7 @@ class TestReservationsCalendar(TestHotelCalendar):
|
||||
pricelist_item_obj = self.env['product.pricelist.item'].sudo(
|
||||
self.user_hotel_manager)
|
||||
pr_ids = pricelist_item_obj.search([
|
||||
('pricelist_id', '=', self.parity_pricelist_id),
|
||||
('pricelist_id', '=', self.default_pricelist_id),
|
||||
('product_tmpl_id', 'in', (
|
||||
self.hotel_room_type_budget.product_id.product_tmpl_id.id,
|
||||
self.hotel_room_type_special.product_id.product_tmpl_id.id)),
|
||||
|
||||
Reference in New Issue
Block a user