[WIP] refactoring default_ pricelist and restriction

This commit is contained in:
Pablo
2019-09-09 15:55:12 +02:00
parent 2fc5a5ad05
commit f68528b929
12 changed files with 24 additions and 56 deletions

View File

@@ -9,8 +9,8 @@
<record id="main_hotel_property" model="hotel.property"> <record id="main_hotel_property" model="hotel.property">
<field name="name">My Hotel</field> <field name="name">My Hotel</field>
<field name="company_id" ref="base.main_company"/> <field name="company_id" ref="base.main_company"/>
<field name="pricelist_id" ref="product.list0"/> <field name="default_pricelist_id" ref="product.list0"/>
<field name="restriction_id" ref="main_hotel_room_type_restriction"/> <field name="default_restriction_id" ref="main_hotel_room_type_restriction"/>
</record> </record>
<record model="res.users" id="base.user_root"> <record model="res.users" id="base.user_root">

View File

@@ -463,7 +463,7 @@ class HotelFolio(models.Model):
addr = self.partner_id.address_get(['invoice']) addr = self.partner_id.address_get(['invoice'])
pricelist = self.partner_id.property_product_pricelist and \ pricelist = self.partner_id.property_product_pricelist and \
self.partner_id.property_product_pricelist.id or \ self.partner_id.property_product_pricelist.id or \
self.env.user.hotel_id.pricelist_id.id self.env.user.hotel_id.default_pricelist_id.id
values = { values = {
'pricelist_id': pricelist, 'pricelist_id': pricelist,
'payment_term_id': self.partner_id.property_payment_term_id and self.partner_id.property_payment_term_id.id or False, 'payment_term_id': self.partner_id.property_payment_term_id and self.partner_id.property_payment_term_id.id or False,

View File

@@ -23,13 +23,13 @@ class HotelProperty(models.Model):
room_ids = fields.One2many('hotel.room', 'hotel_id', 'Rooms') room_ids = fields.One2many('hotel.room', 'hotel_id', 'Rooms')
# TODO: refactoring res.config.settings', 'default_pricelist_id' by the current hotel.property.pricelist_id # TODO: refactoring res.config.settings', 'default_pricelist_id' by the current hotel.property.pricelist_id
pricelist_id = fields.Many2one('product.pricelist', 'Product Pricelist', default_pricelist_id = fields.Many2one('product.pricelist', 'Product Pricelist',
help='The default pricelist used in this hotel.', help='The default pricelist used in this hotel.',
required=True) required=True)
# TODO: refactoring res.config.settings', 'default_restriction_id by the current hotel.property.restriction_id # TODO: refactoring res.config.settings', 'default_restriction_id by the current hotel.property.restriction_id
restriction_id = fields.Many2one('hotel.room.type.restriction', 'Restriction Plan', default_restriction_id = fields.Many2one('hotel.room.type.restriction', 'Restriction Plan',
help='The default restriction plan used in this hotel.', help='The default restriction plan used in this hotel.',
required=True) required=True)
# TODO: refactoring 'res.config.settings', 'default_arrival_hour' by the current hotel.property.arrival_hour # TODO: refactoring 'res.config.settings', 'default_arrival_hour' by the current hotel.property.arrival_hour
arrival_hour = fields.Char('Arrival Hour (GMT)', arrival_hour = fields.Char('Arrival Hour (GMT)',

View File

@@ -670,7 +670,7 @@ class HotelReservation(models.Model):
addr = self.partner_id.address_get(['invoice']) addr = self.partner_id.address_get(['invoice'])
pricelist = self.partner_id.property_product_pricelist and \ pricelist = self.partner_id.property_product_pricelist and \
self.partner_id.property_product_pricelist.id or \ self.partner_id.property_product_pricelist.id or \
self.env.user.hotel_id.pricelist_id.id self.env.user.hotel_id.default_pricelist_id.id
values = { values = {
'pricelist_id': pricelist, 'pricelist_id': pricelist,
'partner_invoice_id': addr['invoice'], 'partner_invoice_id': addr['invoice'],

View File

@@ -156,16 +156,10 @@ class HotelRoomType(models.Model):
raise ValidationError(_('Date From and days are mandatory')) raise ValidationError(_('Date From and days are mandatory'))
partner_id = kwargs.get('partner_id', False) partner_id = kwargs.get('partner_id', False)
partner = self.env['res.partner'].browse(partner_id) partner = self.env['res.partner'].browse(partner_id)
pricelist_id = partner.property_product_pricelist.id if partner else \
self.env['ir.default'].sudo().get(
'res.config.settings',
'default_pricelist_id')
pricelist_id = kwargs.get('pricelist_id', pricelist_id = kwargs.get('pricelist_id',
partner.property_product_pricelist.id and partner.property_product_pricelist.id and
partner.property_product_pricelist.id or partner.property_product_pricelist.id or
self.env['ir.default'].sudo().get( self.env.user.hotel_id.default_pricelist_id.id)
'res.config.settings',
'default_pricelist_id'))
vals.update({ vals.update({
'partner_id': partner_id if partner_id else False, 'partner_id': partner_id if partner_id else False,
'discount': discount, 'discount': discount,

View File

@@ -6,33 +6,10 @@ from odoo import models, fields, api
class HotelRoomTypeRestriction(models.Model): class HotelRoomTypeRestriction(models.Model):
_name = 'hotel.room.type.restriction' _name = 'hotel.room.type.restriction'
@api.model
def _get_default_hotel(self):
return self.env.user.hotel_id
name = fields.Char('Restriction Plan Name', required=True) name = fields.Char('Restriction Plan Name', required=True)
item_ids = fields.One2many('hotel.room.type.restriction.item', item_ids = fields.One2many('hotel.room.type.restriction.item',
'restriction_id', string='Restriction Items', 'restriction_id', string='Restriction Items',
copy=True) copy=True)
active = fields.Boolean('Active', default=True, active = fields.Boolean('Active', default=True,
help='If unchecked, it will allow you to hide the ' help='If unchecked, it will allow you to hide the '
'restriction plan without removing it.') 'restriction plan without removing it.')
# TODO: Review this relationship.
# 1. How to create a new hotel if hotel_property.restriction_id is required?
# 2. If you delete the hotel_id from the hotel is also deleted
hotel_ids = fields.One2many('hotel.property',
'restriction_id', string='Hotel',
default=_get_default_hotel, required=True)
@api.multi
@api.depends('name')
def name_get(self):
# TODO: refactoring res.config.settings', 'default_restriction_id by the current hotel.property.restriction_id
restriction_id = self.env.user.hotel_id.restriction_id.id
names = []
for record in self:
if record.id == restriction_id:
names.append((record.id, '%s (Default)' % record.name))
else:
names.append((record.id, record.name))
return names

View File

@@ -21,8 +21,8 @@
</page> </page>
<page string="Settings" name="hotel_settings"> <page string="Settings" name="hotel_settings">
<group colspan="4" col="4" string="Price and Restriction Plans"> <group colspan="4" col="4" string="Price and Restriction Plans">
<field name="pricelist_id" required="True" /> <field name="default_pricelist_id" required="True" />
<field name="restriction_id" required="True" /> <field name="default_restriction_id" required="True" />
</group> </group>
<group string="Timezone"> <group string="Timezone">
<field name="tz" widget="timezone_mismatch"/> <field name="tz" widget="timezone_mismatch"/>

View File

@@ -21,9 +21,6 @@
<field name="name" /> <field name="name" />
</h1> </h1>
</div> </div>
<group>
<field name="hotel_ids" invisible="0"/>
</group>
<div> <div>
<separator string="Pricelist Items"/> <separator string="Pricelist Items"/>
<field name="item_ids" nolabel="1"> <field name="item_ids" nolabel="1">

View File

@@ -51,7 +51,7 @@ class FolioWizard(models.TransientModel):
@api.model @api.model
def _get_default_pricelist(self): def _get_default_pricelist(self):
return self.env.user.hotel_id.pricelist_id.id return self.env.user.hotel_id.default_pricelist_id.id
partner_id = fields.Many2one('res.partner', required=True, string="Customer") partner_id = fields.Many2one('res.partner', required=True, string="Customer")
email = fields.Char('E-mail') email = fields.Char('E-mail')
@@ -106,7 +106,7 @@ class FolioWizard(models.TransientModel):
vals = {} vals = {}
pricelist = self.partner_id.property_product_pricelist and \ pricelist = self.partner_id.property_product_pricelist and \
self.partner_id.property_product_pricelist.id or \ self.partner_id.property_product_pricelist.id or \
self.env.user.hotel_id.pricelist_id.id self.env.user.hotel_id.default_pricelist_id.id
vals.update({ vals.update({
'pricelist_id': pricelist, 'pricelist_id': pricelist,
'email': self.partner_id.email, 'email': self.partner_id.email,

View File

@@ -218,10 +218,10 @@ class HotelCalendarManagement(models.TransientModel):
vals = {} vals = {}
# TODO: refactoring res.config.settings', 'default_pricelist_id' by the current hotel.property.pricelist_id # TODO: refactoring res.config.settings', 'default_pricelist_id' by the current hotel.property.pricelist_id
if not pricelist_id: if not pricelist_id:
pricelist_id = self.env.user.hotel_id.pricelist_id.id pricelist_id = self.env.user.hotel_id.default_pricelist_id.id
# TODO: refactoring res.config.settings', 'default_restriction_id by the current hotel.property.restriction_id # TODO: refactoring res.config.settings', 'default_restriction_id by the current hotel.property.restriction_id
if not restriction_id: if not restriction_id:
restriction_id = self.env.user.hotel_id.restriction_id.id restriction_id = self.env.user.hotel_id.default_restriction_id.id
# TODO: ensure pricelist_id and restriction_id belong to the current hotel # TODO: ensure pricelist_id and restriction_id belong to the current hotel
vals.update({'pricelist_id': pricelist_id}) vals.update({'pricelist_id': pricelist_id})

View File

@@ -132,7 +132,7 @@ class HotelReservation(models.Model):
def _hcalendar_room_data(self, rooms): def _hcalendar_room_data(self, rooms):
_logger.warning('_found [%s] rooms for hotel [%s]', len(rooms), self.env.user.hotel_id.id) _logger.warning('_found [%s] rooms for hotel [%s]', len(rooms), self.env.user.hotel_id.id)
# TODO: refactoring res.config.settings', 'default_pricelist_id' by the current hotel.property.pricelist_id # TODO: refactoring res.config.settings', 'default_pricelist_id' by the current hotel.property.pricelist_id
pricelist_id = self.env.user.hotel_id.pricelist_id.id pricelist_id = self.env.user.hotel_id.default_pricelist_id.id
json_rooms = [ json_rooms = [
{ {
'id': room.id, 'id': room.id,
@@ -239,7 +239,7 @@ class HotelReservation(models.Model):
@api.model @api.model
def get_hcalendar_pricelist_data(self, dfrom_dt, dto_dt): def get_hcalendar_pricelist_data(self, dfrom_dt, dto_dt):
# TODO: refactoring res.config.settings', 'default_pricelist_id' by the current hotel.property.pricelist_id # TODO: refactoring res.config.settings', 'default_pricelist_id' by the current hotel.property.pricelist_id
pricelist_id = self.env.user.hotel_id.pricelist_id.id pricelist_id = self.env.user.hotel_id.default_pricelist_id.id
hotel_id = self.env.user.hotel_id.id hotel_id = self.env.user.hotel_id.id
room_types_ids = self.env['hotel.room.type'].search([ room_types_ids = self.env['hotel.room.type'].search([
('hotel_id', '=', hotel_id) ('hotel_id', '=', hotel_id)
@@ -294,10 +294,10 @@ class HotelReservation(models.Model):
@api.model @api.model
def get_hcalendar_restrictions_data(self, dfrom_dt, dto_dt): def get_hcalendar_restrictions_data(self, dfrom_dt, dto_dt):
""" Returns the room type restrictions between dfrom_dt and dto_dt """ Returns the room type restrictions between dfrom_dt and dto_dt
for the room types of the current_hotel and the its default restriction plan for the room types of the current_hotel within the default restriction plan
""" """
hotel_id = self.env.user.hotel_id.id hotel_id = self.env.user.hotel_id.id
restriction_id = self.env.user.hotel_id.restriction_id.id restriction_id = self.env.user.hotel_id.default_restriction_id.id
json_rooms_rests = {} json_rooms_rests = {}
room_typed_ids = self.env['hotel.room.type'].search([ room_typed_ids = self.env['hotel.room.type'].search([

View File

@@ -12,7 +12,7 @@ class HotelRoomTypeResrtrictionItem(models.Model):
def create(self, vals): def create(self, vals):
res = super(HotelRoomTypeResrtrictionItem, self).create(vals) res = super(HotelRoomTypeResrtrictionItem, self).create(vals)
# TODO: refactoring res.config.settings', 'default_restriction_id by the current hotel.property.restriction_id # TODO: refactoring res.config.settings', 'default_restriction_id by the current hotel.property.restriction_id
if res.restriction_id.id == self.env.user.hotel_id.restriction_id.id: if res.restriction_id.id == self.env.user.hotel_id.default_restriction_id.id:
self.env['bus.hotel.calendar'].send_restriction_notification({ self.env['bus.hotel.calendar'].send_restriction_notification({
'restriction_id': res.restriction_id.id, 'restriction_id': res.restriction_id.id,
'date': res.date, 'date': res.date,
@@ -51,7 +51,7 @@ class HotelRoomTypeResrtrictionItem(models.Model):
@api.multi @api.multi
def unlink(self): def unlink(self):
# TODO: refactoring res.config.settings', 'default_restriction_id by the current hotel.property.restriction_id # TODO: refactoring res.config.settings', 'default_restriction_id by the current hotel.property.restriction_id
default_restriction_id = self.env.user.hotel_id.restriction_id.id default_restriction_id = self.env.user.hotel_id.default_restriction_id.id
# Construct dictionary with relevant info of removed records # Construct dictionary with relevant info of removed records
unlink_vals = [] unlink_vals = []
for record in self: for record in self: