mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[WIP] Change board_service by board_service_room in reservation, refact code board_services model
This commit is contained in:
@@ -13,3 +13,6 @@ class HotelBoardService(models.Model):
|
|||||||
column1='board_id',
|
column1='board_id',
|
||||||
column2='service_id')
|
column2='service_id')
|
||||||
sequence = fields.Integer('Sequence')
|
sequence = fields.Integer('Sequence')
|
||||||
|
hotel_board_service_room_type_ids = fields.One2many(
|
||||||
|
'hotel.board.service.room.type', 'hotel_board_service_id')
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,17 @@ class HotelBoardServiceRoomType(models.Model):
|
|||||||
_log_access = False
|
_log_access = False
|
||||||
_description = 'Board Service included in Room'
|
_description = 'Board Service included in Room'
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def name_get(self):
|
||||||
|
result = []
|
||||||
|
for res in self:
|
||||||
|
if res.pricelist_id:
|
||||||
|
name = u'%s (%s)' % (res.hotel_board_service_id.name, res.pricelist_id.name)
|
||||||
|
else:
|
||||||
|
name = u'%s (%s)' % (res.hotel_board_service_id.name, _('Generic'))
|
||||||
|
result.append((res.id, name))
|
||||||
|
return result
|
||||||
|
|
||||||
hotel_board_service_id = fields.Many2one(
|
hotel_board_service_id = fields.Many2one(
|
||||||
'hotel.board.service', 'Board Service', index=True, ondelete='cascade', required=True)
|
'hotel.board.service', 'Board Service', index=True, ondelete='cascade', required=True)
|
||||||
hotel_room_type_id = fields.Many2one(
|
hotel_room_type_id = fields.Many2one(
|
||||||
@@ -74,7 +85,7 @@ class HotelBoardServiceRoomType(models.Model):
|
|||||||
today = fields.Date.today()
|
today = fields.Date.today()
|
||||||
for product in board_service.service_ids:
|
for product in board_service.service_ids:
|
||||||
cmds.append((0, False, {
|
cmds.append((0, False, {
|
||||||
'service_id': product.id,
|
'product_id': product.id,
|
||||||
'amount': product.list_price #TODO: default amomunt?¿
|
'amount': product.list_price #TODO: default amomunt?¿
|
||||||
}))
|
}))
|
||||||
return {'board_service_line_ids': cmds}
|
return {'board_service_line_ids': cmds}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class HotelBoardServiceRoomTypeLine(models.Model):
|
|||||||
|
|
||||||
hotel_board_service_room_type_id = fields.Many2one(
|
hotel_board_service_room_type_id = fields.Many2one(
|
||||||
'hotel.board.service.room.type', 'Board Service Room', ondelete='cascade', required=True)
|
'hotel.board.service.room.type', 'Board Service Room', ondelete='cascade', required=True)
|
||||||
service_id = fields.Many2one(
|
product_id = fields.Many2one(
|
||||||
'product.product', 'Product', required=True, readonly=True)
|
'product.product', 'Product', required=True, readonly=True)
|
||||||
amount = fields.Float('Amount', digits=dp.get_precision('Product Price'), default=0.0)
|
amount = fields.Float('Amount', digits=dp.get_precision('Product Price'), default=0.0)
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from lxml import etree
|
||||||
from odoo.exceptions import UserError, ValidationError
|
from odoo.exceptions import UserError, ValidationError
|
||||||
from odoo.tools import (
|
from odoo.tools import (
|
||||||
misc,
|
misc,
|
||||||
@@ -133,7 +134,8 @@ class HotelReservation(models.Model):
|
|||||||
track_visibility='onchange')
|
track_visibility='onchange')
|
||||||
reservation_type = fields.Selection(related='folio_id.reservation_type',
|
reservation_type = fields.Selection(related='folio_id.reservation_type',
|
||||||
default=lambda *a: 'normal')
|
default=lambda *a: 'normal')
|
||||||
board_service_id = fields.Many2one('hotel.board.service', string='Board Service')
|
board_service_room_id = fields.Many2one('hotel.board.service.room.type',
|
||||||
|
string='Board Service')
|
||||||
cancelled_reason = fields.Selection([
|
cancelled_reason = fields.Selection([
|
||||||
('late', 'Late'),
|
('late', 'Late'),
|
||||||
('intime', 'In time'),
|
('intime', 'In time'),
|
||||||
@@ -290,12 +292,12 @@ class HotelReservation(models.Model):
|
|||||||
vals.update({
|
vals.update({
|
||||||
'last_updated_res': fields.Datetime.now(),
|
'last_updated_res': fields.Datetime.now(),
|
||||||
})
|
})
|
||||||
if 'board_service_id' in vals:
|
if 'board_service_room_id' in vals:
|
||||||
board_services = []
|
board_services = []
|
||||||
board = self.env['hotel.board.service'].browse(vals['board_service_id'])
|
board = self.env['hotel.board.service.room.type'].browse(vals['board_service_room_id'])
|
||||||
for product in board.service_ids:
|
for line in board.board_service_line_ids:
|
||||||
board_services.append((0, False, {
|
board_services.append((0, False, {
|
||||||
'product_id': product.id,
|
'product_id': line.product_id.id,
|
||||||
'is_board_service': True,
|
'is_board_service': True,
|
||||||
'folio_id': vals.get('folio_id'),
|
'folio_id': vals.get('folio_id'),
|
||||||
}))
|
}))
|
||||||
@@ -330,10 +332,10 @@ class HotelReservation(models.Model):
|
|||||||
if self.compute_board_services(vals):
|
if self.compute_board_services(vals):
|
||||||
record.service_ids.filtered(lambda r: r.is_board_service == True).unlink()
|
record.service_ids.filtered(lambda r: r.is_board_service == True).unlink()
|
||||||
board_services = []
|
board_services = []
|
||||||
board = self.env['hotel.board.service'].browse(vals['board_service_id'])
|
board = self.env['hotel.board.service.room.type'].browse(vals['board_service_room_id'])
|
||||||
for product in board.service_ids:
|
for product in board.service_ids:
|
||||||
board_services.append((0, False, {
|
board_services.append((0, False, {
|
||||||
'product_id': product.id,
|
'product_id': line.product_id.id,
|
||||||
'is_board_service': True,
|
'is_board_service': True,
|
||||||
'folio_id': record.folio_id.id or vals.get('folio_id')
|
'folio_id': record.folio_id.id or vals.get('folio_id')
|
||||||
}))
|
}))
|
||||||
@@ -369,10 +371,10 @@ class HotelReservation(models.Model):
|
|||||||
@api.multi
|
@api.multi
|
||||||
def compute_board_services(self, vals):
|
def compute_board_services(self, vals):
|
||||||
"""
|
"""
|
||||||
We must compute service_ids when we hace a board_service_id without
|
We must compute service_ids when we have a board_service_id without
|
||||||
service_ids associated to reservation
|
service_ids associated to reservation
|
||||||
"""
|
"""
|
||||||
if 'board_service_id' in vals:
|
if 'board_service_room_id' in vals:
|
||||||
if 'service_ids' in vals:
|
if 'service_ids' in vals:
|
||||||
for service in vals['service_ids']:
|
for service in vals['service_ids']:
|
||||||
if 'is_board_service' in service[2] and \
|
if 'is_board_service' in service[2] and \
|
||||||
@@ -402,7 +404,7 @@ class HotelReservation(models.Model):
|
|||||||
""" Deduce missing required fields from the onchange """
|
""" Deduce missing required fields from the onchange """
|
||||||
res = {}
|
res = {}
|
||||||
onchange_fields = ['room_id', 'reservation_type',
|
onchange_fields = ['room_id', 'reservation_type',
|
||||||
'currency_id', 'name', 'board_service_id']
|
'currency_id', 'name', 'board_service_room_id']
|
||||||
if values.get('room_type_id'):
|
if values.get('room_type_id'):
|
||||||
line = self.new(values)
|
line = self.new(values)
|
||||||
if any(f not in values for f in onchange_fields):
|
if any(f not in values for f in onchange_fields):
|
||||||
@@ -610,11 +612,13 @@ class HotelReservation(models.Model):
|
|||||||
]
|
]
|
||||||
return {'domain': {'room_id': domain_rooms}}
|
return {'domain': {'room_id': domain_rooms}}
|
||||||
|
|
||||||
@api.onchange('board_service_id')
|
@api.onchange('board_service_room_id')
|
||||||
def onchange_board_service(self):
|
def onchange_board_service(self):
|
||||||
if self.board_service_id:
|
if self.board_service_room_id:
|
||||||
|
import wdb; wdb.set_trace()
|
||||||
board_services = []
|
board_services = []
|
||||||
for product in self.board_service_id.service_ids:
|
for line in self.board_service_room_id.board_service_line_ids:
|
||||||
|
product = line.product_id
|
||||||
if product.per_day:
|
if product.per_day:
|
||||||
vals = {
|
vals = {
|
||||||
'product_id': product.id,
|
'product_id': product.id,
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ class HotelService(models.Model):
|
|||||||
def _compute_tax_ids(self):
|
def _compute_tax_ids(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
# If company_id is set, always filter taxes by the company
|
# If company_id is set, always filter taxes by the company
|
||||||
folio = self.folio_id or self.env.context.get('default_folio_id')
|
folio = record.folio_id or self.env.context.get('default_folio_id')
|
||||||
record.tax_id = record.product_id.taxes_id.filtered(lambda r: not record.company_id or r.company_id == folio.company_id)
|
record.tax_id = record.product_id.taxes_id.filtered(lambda r: not record.company_id or r.company_id == folio.company_id)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@@ -184,12 +184,12 @@ class HotelService(models.Model):
|
|||||||
if record.per_day and record.ser_room_line:
|
if record.per_day and record.ser_room_line:
|
||||||
product = record.product_id
|
product = record.product_id
|
||||||
reservation = record.ser_room_line
|
reservation = record.ser_room_line
|
||||||
vals.update(self.prepare_service_lines(
|
vals.update(record.prepare_service_lines(
|
||||||
dfrom=reservation.checkin,
|
dfrom=reservation.checkin,
|
||||||
days=reservation.nights,
|
days=reservation.nights,
|
||||||
per_person=product.per_person,
|
per_person=product.per_person,
|
||||||
persons=reservation.adults,
|
persons=reservation.adults,
|
||||||
old_line_days=self.service_line_ids))
|
old_line_days=record.service_line_ids))
|
||||||
if record.product_id.daily_limit > 0:
|
if record.product_id.daily_limit > 0:
|
||||||
for day in record.service_line_ids:
|
for day in record.service_line_ids:
|
||||||
day.no_free_resources()
|
day.no_free_resources()
|
||||||
@@ -205,33 +205,25 @@ class HotelService(models.Model):
|
|||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
folio = self.folio_id or self.env.context.get('default_folio_id')
|
folio = self.folio_id or self.env.context.get('default_folio_id')
|
||||||
reservation = self.ser_room_line or self.env.context.get('ser_room_line')
|
reservation = self.ser_room_line or self.env.context.get('ser_room_line')
|
||||||
if self.is_board_service:
|
partner = folio.partner_id if folio else reservation.partner_id
|
||||||
board_room_type = self.env['hotel.board.service.room.type'].search([
|
pricelist = folio.pricelist_id if folio else reservation.pricelist_id
|
||||||
('hotel_board_service_id', '=', reservation.board_service_id.id),
|
if reservation and self.is_board_service:
|
||||||
('hotel_room_type_id', '=', reservation.room_type_id.id),
|
board_room_type = reservation.board_service_room_id
|
||||||
('pricelist_id', '=', folio.pricelist_id.id)
|
if board_room_type.price_type == 'fixed':
|
||||||
])
|
|
||||||
if not board_room_type:
|
|
||||||
board_room_type = self.env['hotel.board.service.room.type'].search([
|
|
||||||
('hotel_board_service_id', '=', reservation.board_service_id.id),
|
|
||||||
('hotel_room_type_id', '=', reservation.room_type_id.id)
|
|
||||||
])
|
|
||||||
if board_room_type.price_type = 'fixed':
|
|
||||||
return self.env['hotel.board.service.room.type.line'].search([
|
return self.env['hotel.board.service.room.type.line'].search([
|
||||||
('hotel_board_service_room_type_id', '=', board_room_type.id),
|
('hotel_board_service_room_type_id', '=', board_room_type.id),
|
||||||
('service_id','=',self.product_id.id)]).amount
|
('product_id','=',self.product_id.id)]).amount
|
||||||
else:
|
else:
|
||||||
return (reservation.price_total * self.env['hotel.board.service.room.type.line'].search([
|
return (reservation.price_total * self.env['hotel.board.service.room.type.line'].search([
|
||||||
('hotel_board_service_room_type_id', '=', board_room_type.id),
|
('hotel_board_service_room_type_id', '=', board_room_type.id),
|
||||||
('service_id','=',self.product_id.id)]).amount) / 100
|
('product_id','=',self.product_id.id)]).amount) / 100
|
||||||
else:
|
else:
|
||||||
folio = self.folio_id or self.env.context.get('default_folio_id')
|
|
||||||
product = self.product_id.with_context(
|
product = self.product_id.with_context(
|
||||||
lang=folio.partner_id.lang,
|
lang=partner.lang,
|
||||||
partner=folio.partner_id.id,
|
partner=partner.id,
|
||||||
quantity=self.product_qty,
|
quantity=self.product_qty,
|
||||||
date=folio.date_order,
|
date=folio.date_order or fields.Date.today(),
|
||||||
pricelist=folio.pricelist_id.id,
|
pricelist=pricelist.id,
|
||||||
uom=self.product_id.uom_id.id,
|
uom=self.product_id.uom_id.id,
|
||||||
fiscal_position=False
|
fiscal_position=False
|
||||||
)
|
)
|
||||||
@@ -272,9 +264,11 @@ class HotelService(models.Model):
|
|||||||
"""
|
"""
|
||||||
for record in self:
|
for record in self:
|
||||||
folio = record.folio_id or self.env.context.get('default_folio_id')
|
folio = record.folio_id or self.env.context.get('default_folio_id')
|
||||||
|
reservation = record.ser_room_line or self.env.context.get('ser_room_line')
|
||||||
|
currency = folio.currency_id if folio else reservation.currency_id
|
||||||
product = record.product_id
|
product = record.product_id
|
||||||
price = record.price_unit * (1 - (record.discount or 0.0) * 0.01)
|
price = record.price_unit * (1 - (record.discount or 0.0) * 0.01)
|
||||||
taxes = record.tax_ids.compute_all(price, folio.currency_id, record.product_qty, product=product)
|
taxes = record.tax_ids.compute_all(price, currency, record.product_qty, product=product)
|
||||||
record.update({
|
record.update({
|
||||||
'price_tax': sum(t.get('amount', 0.0) for t in taxes.get('taxes', [])),
|
'price_tax': sum(t.get('amount', 0.0) for t in taxes.get('taxes', [])),
|
||||||
'price_total': taxes['total_included'],
|
'price_total': taxes['total_included'],
|
||||||
|
|||||||
@@ -17,3 +17,4 @@ access_hotel_reservation,access_hotel_reservation,model_hotel_reservation,base.g
|
|||||||
access_hotel_folio,access_hotel_folio,model_hotel_folio,base.group_user,1,0,0,0
|
access_hotel_folio,access_hotel_folio,model_hotel_folio,base.group_user,1,0,0,0
|
||||||
access_hotel_room_type,access_hotel_room_type,model_hotel_room_type,base.group_user,1,0,0,0
|
access_hotel_room_type,access_hotel_room_type,model_hotel_room_type,base.group_user,1,0,0,0
|
||||||
access_hotel_board_service_room_type,access_hotel_board_service_room_type,model_hotel_board_service_room_type,base.group_user,1,0,0,0
|
access_hotel_board_service_room_type,access_hotel_board_service_room_type,model_hotel_board_service_room_type,base.group_user,1,0,0,0
|
||||||
|
access_hotel_board_service_room_type_line,access_hotel_board_service_room_type_line,model_hotel_board_service_room_type_line,base.group_user,1,0,0,0
|
||||||
|
|||||||
|
@@ -11,7 +11,7 @@
|
|||||||
<field name="board_service_line_ids">
|
<field name="board_service_line_ids">
|
||||||
<tree editable="bottom">
|
<tree editable="bottom">
|
||||||
<field name="hotel_board_service_room_type_id" invisible="1"/>
|
<field name="hotel_board_service_room_type_id" invisible="1"/>
|
||||||
<field name="service_id"/>
|
<field name="product_id"/>
|
||||||
<field name="amount" />
|
<field name="amount" />
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
|
|||||||
@@ -298,7 +298,9 @@
|
|||||||
<field name="arrival_hour"/>
|
<field name="arrival_hour"/>
|
||||||
<field name="departure_hour"/>
|
<field name="departure_hour"/>
|
||||||
<field name="nights" invisible="1"/>
|
<field name="nights" invisible="1"/>
|
||||||
<field name="board_service_id" />
|
<field name="board_service_room_id" domain="[
|
||||||
|
('hotel_room_type_id', '=', room_type_id),
|
||||||
|
('pricelist_id', 'in', [pricelist_id, False])]" />
|
||||||
<field name="name"/>
|
<field name="name"/>
|
||||||
<field name="adults"/>
|
<field name="adults"/>
|
||||||
<field name="children"/>
|
<field name="children"/>
|
||||||
|
|||||||
@@ -191,7 +191,10 @@
|
|||||||
<field name="arrival_hour"/>
|
<field name="arrival_hour"/>
|
||||||
<field name="departure_hour"/>
|
<field name="departure_hour"/>
|
||||||
<field name="nights" invisible="1"/>
|
<field name="nights" invisible="1"/>
|
||||||
<field name="board_service_id" />
|
<!-- TODO: How to filter to avoid show False (generic) pricelist board when exist a specific pricelist board¿? -->
|
||||||
|
<field name="board_service_room_id" domain="[
|
||||||
|
('hotel_room_type_id', '=', room_type_id),
|
||||||
|
('pricelist_id', 'in', [pricelist_id, False])]" />
|
||||||
<field name="name"/>
|
<field name="name"/>
|
||||||
<field name="adults"/>
|
<field name="adults"/>
|
||||||
<field name="children"/>
|
<field name="children"/>
|
||||||
@@ -237,7 +240,7 @@
|
|||||||
</group>
|
</group>
|
||||||
<notebook>
|
<notebook>
|
||||||
<page name="days" string="Service and Days">
|
<page name="days" string="Service and Days">
|
||||||
<group string="Reservation Services" name="reservation_services" attrs="{'invisible': [('folio_id','=',False)]}">
|
<group string="Reservation Services" name="reservation_services">
|
||||||
<field name="service_ids"
|
<field name="service_ids"
|
||||||
context="{'default_ser_room_line': active_id, 'default_folio_id': folio_id}"
|
context="{'default_ser_room_line': active_id, 'default_folio_id': folio_id}"
|
||||||
nolabel="1">
|
nolabel="1">
|
||||||
|
|||||||
Reference in New Issue
Block a user