[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">
<field name="name">My Hotel</field>
<field name="company_id" ref="base.main_company"/>
<field name="pricelist_id" ref="product.list0"/>
<field name="restriction_id" ref="main_hotel_room_type_restriction"/>
<field name="default_pricelist_id" ref="product.list0"/>
<field name="default_restriction_id" ref="main_hotel_room_type_restriction"/>
</record>
<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'])
pricelist = self.partner_id.property_product_pricelist and \
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 = {
'pricelist_id': pricelist,
'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')
# TODO: refactoring res.config.settings', 'default_pricelist_id' by the current hotel.property.pricelist_id
pricelist_id = fields.Many2one('product.pricelist', 'Product Pricelist',
help='The default pricelist used in this hotel.',
required=True)
default_pricelist_id = fields.Many2one('product.pricelist', 'Product Pricelist',
help='The default pricelist used in this hotel.',
required=True)
# 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',
help='The default restriction plan used in this hotel.',
required=True)
default_restriction_id = fields.Many2one('hotel.room.type.restriction', 'Restriction Plan',
help='The default restriction plan used in this hotel.',
required=True)
# TODO: refactoring 'res.config.settings', 'default_arrival_hour' by the current hotel.property.arrival_hour
arrival_hour = fields.Char('Arrival Hour (GMT)',

View File

@@ -670,7 +670,7 @@ class HotelReservation(models.Model):
addr = self.partner_id.address_get(['invoice'])
pricelist = self.partner_id.property_product_pricelist and \
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 = {
'pricelist_id': pricelist,
'partner_invoice_id': addr['invoice'],

View File

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

View File

@@ -6,33 +6,10 @@ from odoo import models, fields, api
class HotelRoomTypeRestriction(models.Model):
_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)
item_ids = fields.One2many('hotel.room.type.restriction.item',
'restriction_id', string='Restriction Items',
copy=True)
active = fields.Boolean('Active', default=True,
help='If unchecked, it will allow you to hide the '
'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
'restriction plan without removing it.')

View File

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

View File

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

View File

@@ -51,7 +51,7 @@ class FolioWizard(models.TransientModel):
@api.model
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")
email = fields.Char('E-mail')
@@ -106,7 +106,7 @@ class FolioWizard(models.TransientModel):
vals = {}
pricelist = self.partner_id.property_product_pricelist and \
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({
'pricelist_id': pricelist,
'email': self.partner_id.email,