Merge pull request #68 from hootel/pr_onboard_service

WorkFlow BoardServices
This commit is contained in:
Darío Lodeiros
2018-12-04 14:05:51 +01:00
committed by GitHub
8 changed files with 215 additions and 65 deletions

View File

@@ -2,6 +2,16 @@
<odoo>
<data noupdate="0">
<!-- hotel.users -->
<record id="base.user_root" model="res.users">
<field name="groups_id" eval="[(4,ref('hotel.group_hotel_manager'))]"/>
</record>
<record id="base.user_demo" model="res.users">
<field name="groups_id" eval="[(4,ref('hotel.group_hotel_user'))]"/>
</record>
<!-- hotel.floor -->
<record id="hotel_floor_0" model="hotel.floor">
@@ -57,8 +67,6 @@
<field name="room_amenity_type_id" ref="hotel_amenity_type_2"/>
</record>
<!-- hotel.board.service -->
<!-- hotel.room.type.class -->
<record id="hotel_room_type_class_0" model="hotel.room.type.class">
@@ -171,7 +179,6 @@
<field name="list_price">5.0</field>
<field name="type">service</field>
<field name="purchase_ok">False</field>
<field name="is_hotel_service">True</field>
<field name="per_day">True</field>
<field name="per_person">True</field>
</record>
@@ -181,7 +188,6 @@
<field name="list_price">15.0</field>
<field name="type">service</field>
<field name="purchase_ok">False</field>
<field name="is_hotel_service">True</field>
<field name="per_day">False</field>
<field name="per_person">True</field>
<field name="daily_limit">1</field>
@@ -192,11 +198,61 @@
<field name="list_price">10.0</field>
<field name="type">service</field>
<field name="purchase_ok">False</field>
<field name="is_hotel_service">True</field>
<field name="per_day">False</field>
<field name="per_person">False</field>
</record>
<record id="hotel_service_4" model="product.product">
<field name="name">Menú A</field>
<field name="list_price">15.0</field>
<field name="type">service</field>
<field name="purchase_ok">False</field>
<field name="per_day">True</field>
<field name="per_person">True</field>
</record>
<record id="hotel_service_5" model="product.product">
<field name="name">Menú B</field>
<field name="list_price">20.0</field>
<field name="type">service</field>
<field name="purchase_ok">False</field>
<field name="per_day">True</field>
<field name="per_person">True</field>
</record>
<record id="hotel_service_6" model="product.product">
<field name="name">Menú C</field>
<field name="list_price">25.0</field>
<field name="type">service</field>
<field name="purchase_ok">False</field>
<field name="per_day">True</field>
<field name="per_person">True</field>
</record>
<!-- hotel.board.service -->
<record id="hotel_board_service_0" model="hotel.board.service">
<field name="name">BreakFast</field>
<field name="service_ids"
eval="[(4, ref('hotel_service_0'))]"/>
<field name="sequence">0</field>
</record>
<record id="hotel_board_service_1" model="hotel.board.service">
<field name="name">Half Board</field>
<field name="service_ids"
eval="[(4, ref('hotel_service_0')), (4, ref('hotel_service_4'))]"/>
<field name="sequence">10</field>
</record>
<record id="hotel_board_service_2" model="hotel.board.service">
<field name="name">FullBoard</field>
<field name="service_ids"
eval="[(4, ref('hotel_service_0')), (4, ref('hotel_service_4')),
(4, ref('hotel_service_5'))]"/>
<field name="sequence">10</field>
</record>
<!-- hotel.folio -->
<!-- reservation of 1 economic room for 1 person -->
@@ -209,6 +265,7 @@
'checkout': (DateTime.today() + timedelta(days=2)).strftime('%Y-%m-%d'),
'adults': 2,
'state': 'confirm',
'board_service_id': ref('hotel_board_service_1'),
})]"/>
</record>
<!-- reservation of 1 triple room for 3 people on behalf on the company -->
@@ -220,6 +277,7 @@
'checkin': (DateTime.today() + timedelta(days=2)).strftime('%Y-%m-%d'),
'checkout': (DateTime.today() + timedelta(days=4)).strftime('%Y-%m-%d'),
'adults': 3,
'board_service_id': ref('hotel_board_service_2'),
})]"/>
</record>
<!-- reservation of 3 single rooms for 3 people with 1 cancelled -->
@@ -256,6 +314,7 @@
'checkout': (DateTime.today() + timedelta(days=4)).strftime('%Y-%m-%d'),
'adults': 1,
'state': 'confirm',
'board_service_id': ref('hotel_board_service_1'),
})]"/>
</record>

View File

@@ -8,8 +8,8 @@ class HotelBoardService(models.Model):
_description = "Board Services"
name = fields.Char('Board Name', size=64, required=True, index=True)
service_ids = fields.Many2many(comodel_name='product.template',
relation='hotel_board_services_room',
service_ids = fields.Many2many(comodel_name='product.product',
relation='hotel_board_services_reservation',
column1='board_id',
column2='service_id')
sequence = fields.Integer('Sequence')

View File

@@ -74,7 +74,7 @@ class HotelFolio(models.Model):
states={'done': [('readonly', True)]},
help="Hotel room reservation detail.",)
service_line_ids = fields.One2many('hotel.service', 'folio_id',
service_ids = fields.One2many('hotel.service', 'folio_id',
readonly=False,
states={'done': [('readonly', True)]},
help="Hotel services detail provide to "

View File

@@ -102,7 +102,7 @@ class HotelReservation(models.Model):
for record in self:
if record.folio_id:
record.shared_folio = len(record.folio_id.room_lines) > 1 or \
any(record.folio_id.service_line_ids.filtered(
any(record.folio_id.service_ids.filtered(
lambda x: x.ser_room_line.id != record.id))
@api.depends('checkin', 'checkout')
@@ -133,6 +133,7 @@ class HotelReservation(models.Model):
track_visibility='onchange')
reservation_type = fields.Selection(related='folio_id.reservation_type',
default=lambda *a: 'normal')
board_service_id = fields.Many2one('hotel.board.service', string='Board Service')
cancelled_reason = fields.Selection([
('late', 'Late'),
('intime', 'In time'),
@@ -173,7 +174,7 @@ class HotelReservation(models.Model):
store=True)
reserve_color_text = fields.Char(compute='_compute_color', string='Color',
store=True)
service_line_ids = fields.One2many('hotel.service', 'ser_room_line')
service_ids = fields.One2many('hotel.service', 'ser_room_line')
pricelist_id = fields.Many2one('product.pricelist',
related='folio_id.pricelist_id',
@@ -289,6 +290,15 @@ class HotelReservation(models.Model):
#~ 'reserve_color': colors[0],
#~ 'reserve_color_text': colors[1],
})
if 'board_service_id' in vals:
board_services = []
board = self.env['hotel.board.service'].browse(vals['board_service_id'])
for product in board.service_ids:
board_services.append((0, False, {
'product_id': product.id,
'is_board_service': True,
}))
vals.update({'service_ids': board_services})
if self.compute_price_out_vals(vals):
days_diff = (
fields.Date.from_string(vals['checkout']) - fields.Date.from_string(vals['checkin'])
@@ -316,22 +326,36 @@ class HotelReservation(models.Model):
fields.Date.from_string(checkout) - \
fields.Date.from_string(checkin)
).days
if self.compute_board_services(vals):
record.service_ids.filtered(lambda r: r.is_board_service == True).unlink()
board_services = []
board = self.env['hotel.board.service'].browse(vals['board_service_id'])
for product in board.service_ids:
board_services.append((0, False, {
'product_id': product.id,
'is_board_service': True,
}))
# NEED REVIEW: Why I need add manually the old IDs if board service is (0,0,(-)) ¿?¿?¿
record.update({'service_ids': [(6, 0, record.service_ids.ids)] + board_services})
update_services = record.service_ids.filtered(
lambda r: r.is_board_service == True
)
for service in update_services:
service.onchange_product_calc_qty()
if record.compute_price_out_vals(vals):
record.update(record.prepare_reservation_lines(
checkin,
days_diff,
vals=vals)) #REVISAR el unlink
if record.compute_qty_service_day(vals):
for service in record.service_line_ids:
for service in record.service_ids:
if service.product_id.per_day:
params = {
'per_person': service.product_id.per_person,
'persons': vals['adults'] if 'adults' in vals else record.adults
}
service.update(service.prepare_service_lines(
checkin,
days_diff,
params
dfrom=checkin,
days=days_diff,
per_person=product.per_person,
persons=reservation.adults,
old_line_days=service.service_line_ids
))
if ('checkin' in vals and record.checkin != vals['checkin']) or \
('checkout' in vals and record.checkout != vals['checkout']) or \
@@ -340,6 +364,21 @@ class HotelReservation(models.Model):
res = super(HotelReservation, self).write(vals)
return res
@api.multi
def compute_board_services(self, vals):
"""
We must compute service_ids when we hace a board_service_id without
service_ids associated to reservation
"""
if 'board_service_id' in vals:
if 'service_ids' in vals:
for service in vals['service_ids']:
if 'is_board_service' in service[2] and \
service[2]['is_board_service'] == True:
return False
return True
return False
@api.multi
def compute_qty_service_day(self, vals):
"""
@@ -348,7 +387,7 @@ class HotelReservation(models.Model):
self.ensure_one()
if not vals:
vals = {}
if 'service_line_ids' in vals:
if 'service_ids' in vals:
return False
if ('checkin' in vals and self.checkin != vals['checkin']) or \
('checkout' in vals and self.checkout != vals['checkout']) or \
@@ -360,12 +399,14 @@ class HotelReservation(models.Model):
def _prepare_add_missing_fields(self, values):
""" Deduce missing required fields from the onchange """
res = {}
onchange_fields = ['room_id', 'reservation_type', 'currency_id', 'name']
onchange_fields = ['room_id', 'reservation_type',
'currency_id', 'name', 'board_service_id']
if values.get('room_type_id'):
line = self.new(values)
if any(f not in values for f in onchange_fields):
line.onchange_room_id()
line.onchange_compute_reservation_description()
line.onchange_board_service()
if 'pricelist_id' not in values:
line.onchange_partner_id()
for field in onchange_fields:
@@ -407,7 +448,7 @@ class HotelReservation(models.Model):
def open_folio(self):
action = self.env.ref('hotel.open_hotel_folio1_form_tree_all').read()[0]
if self.folio_id:
action['views'] = [(self.env.ref('hotel.view_hotel_folio1_form').id, 'form')]
action['views'] = [(self.env.ref('hotel.hotel_folio_view_form').id, 'form')]
action['res_id'] = self.folio_id.id
else:
action = {'type': 'ir.actions.act_window_close'}
@@ -416,7 +457,7 @@ class HotelReservation(models.Model):
@api.multi
def open_reservation_form(self):
action = self.env.ref('hotel.open_hotel_reservation_form_tree_all').read()[0]
action['views'] = [(self.env.ref('hotel.view_hotel_reservation_form').id, 'form')]
action['views'] = [(self.env.ref('hotel.hotel_reservation_view_form').id, 'form')]
action['res_id'] = self.id
return action
@@ -536,7 +577,7 @@ class HotelReservation(models.Model):
@api.onchange('checkin', 'checkout')
def onchange_update_service_per_day(self):
services = self.service_line_ids.filtered(lambda r: r.per_day == True)
services = self.service_ids.filtered(lambda r: r.per_day == True)
for service in services:
service.onchange_product_calc_qty()
@@ -563,6 +604,27 @@ class HotelReservation(models.Model):
]
return {'domain': {'room_id': domain_rooms}}
@api.onchange('board_service_id')
def onchange_board_service(self):
if self.board_service_id:
board_services = []
for product in self.board_service_id.service_ids:
if product.per_day:
vals = {
'product_id': product.id,
'is_board_service': True,
}
vals.update(self.env['hotel.service'].prepare_service_lines(
dfrom=self.checkin,
days=self.nights,
per_person=product.per_person,
persons=self.adults,
old_line_days=False))
board_services.append((0, False, vals))
other_services = self.service_ids.filtered(lambda r: r.is_board_service == False)
self.update({'service_ids': [(6, 0, other_services.ids)] + board_services})
"""
COMPUTE RESERVE COLOR ----------------------------------------------
"""

View File

@@ -1,7 +1,7 @@
# Copyright 2017 Alexandre Díaz
# Copyright 2017 Dario Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields, api
from odoo import models, fields, api, _
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
from datetime import timedelta
from odoo.exceptions import ValidationError
@@ -10,6 +10,28 @@ class HotelService(models.Model):
_name = 'hotel.service'
_description = 'Hotel Services and its charges'
@api.model
def name_search(self, name='', args=None, operator='ilike', limit=100):
if args is None:
args = []
if not(name == '' and operator == 'ilike'):
args += [
'|',
('ser_room_line.name', operator, name),
('name', operator, name)
]
return super(HotelService, self).name_search(
name='', args=args, operator='ilike', limit=limit)
@api.multi
def name_get(self):
result = []
for res in self:
name = u'%s (%s)' % (res.name, res.ser_room_line.name)
result.append((res.id, name))
return result
@api.model
def _default_ser_room_line(self):
if self.env.context.get('room_lines'):
@@ -27,6 +49,7 @@ class HotelService(models.Model):
service_line_ids = fields.One2many('hotel.service.line', 'service_id')
product_qty = fields.Integer('Quantity')
days_qty = fields.Integer(compute="_compute_days_qty", store=True)
is_board_service = fields.Boolean()
pricelist_id = fields.Many2one(related='folio_id.pricelist_id')
channel_type = fields.Selection([
('door', 'Door'),
@@ -53,16 +76,15 @@ class HotelService(models.Model):
@api.model
def create(self, vals):
if self.compute_lines_out_vals(vals):
reservation = self.env['hotel.reservation'].browse(vals['reservation_id'])
reservation = self.env['hotel.reservation'].browse(vals['ser_room_line'])
product = self.env['product.product'].browse(vals['product_id'])
params = {
'per_person': product.per_person,
'persons': reservation.adults
}
vals.update(self.prepare_service_lines(
reservation.checkin,
reservation.days,
params
dfrom=reservation.checkin,
days=reservation.nights,
per_person=product.per_person,
persons=reservation.adults,
old_day_lines=False,
))
record = super(HotelService, self).create(vals)
return record
@@ -80,16 +102,14 @@ class HotelService(models.Model):
else:
for record in self:
reservations = self.env['hotel.reservation']
reservation = reservations.browse(vals['reservation_id']) \
if 'reservation_id' in vals else record.reservation_id
params = {
'per_person': product.per_person,
'persons': reservation.adults
}
reservation = reservations.browse(vals['ser_room_line']) \
if 'ser_room_line' in vals else record.ser_room_line
record.update(record.prepare_service_lines(
reservation.checkin,
reservation.days,
params
dfrom=reservation.checkin,
days=reservation.nights,
per_person=product.per_person,
persons=reservation.adults,
old_line_days=self.service_line_ids
))
res = super(HotelService, self).write(vals)
return res
@@ -119,37 +139,36 @@ class HotelService(models.Model):
if record.per_day and record.ser_room_line:
product = record.product_id
reservation = record.ser_room_line
params = {
'per_person': product.per_person,
'persons': reservation.adults
}
record.update(self.prepare_service_lines(
reservation.checkin,
reservation.nights,
params))
@api.multi
def prepare_service_lines(self, dfrom, days, params=False):
dfrom=reservation.checkin,
days=reservation.nights,
per_person=product.per_person,
persons=reservation.adults,
old_line_days=self.service_line_ids))
@api.model
def prepare_service_lines(self, **kwargs):
"""
Respect the old manual changes on lines
Prepare line and respect the old manual changes on lines
"""
self.ensure_one()
cmds = [(5, 0, 0)]
old_lines_days = self.mapped('service_line_ids.date')
old_lines_days = kwargs.get('old_lines_days')
total_qty = 0
day_qty = 1
if params.get('per_person'): #WARNING: Change adults in reservation NOT update qty service!!
day_qty = params.get('persons')
for i in range(0, days):
idate = (fields.Date.from_string(dfrom) + timedelta(days=i)).strftime(
if kwargs.get('per_person'): #WARNING: Change adults in reservation NOT update qty service!!
day_qty = kwargs.get('persons')
old_line_days = self.env['hotel.service.line'].browse(kwargs.get('old_line_days'))
for i in range(0, kwargs.get('days')):
idate = (fields.Date.from_string(kwargs.get('dfrom')) + timedelta(days=i)).strftime(
DEFAULT_SERVER_DATE_FORMAT)
old_line = self.service_line_ids.filtered(lambda r: r.date == idate)
if idate not in old_lines_days:
if not old_lines_days or idate not in old_lines_days.mapped('date'):
cmds.append((0, False, {
'date': idate,
'day_qty': day_qty
}))
total_qty = total_qty + day_qty
else:
old_line = old_line_days.filtered(lambda r: r.date == idate)
cmds.append((4, old_line.id))
total_qty = total_qty + old_line.day_qty
return {'service_line_ids': cmds, 'product_qty': total_qty}

View File

@@ -58,6 +58,8 @@ class AccountInvoice(models.Model):
@api.multi
def action_invoice_open(self):
#TODO: VAT Control
"""
to_open_invoices_without_vat = self.filtered(
lambda inv: inv.state != 'open' and inv.partner_id.vat == False)
if to_open_invoices_without_vat:
@@ -65,5 +67,6 @@ class AccountInvoice(models.Model):
for invoice in to_open_invoices_without_vat:
vat_error += ", " + invoice.partner_id.name
raise ValidationError(vat_error)
"""
return super(AccountInvoice, self).action_invoice_open()

View File

@@ -338,7 +338,7 @@
<page name="days" string="Service and Days">
<group col="9">
<group colspan="6" string="Reservation Services" name="reservation_services" attrs="{'invisible': [('folio_id','=',False)]}">
<field name="service_line_ids"
<field name="service_ids"
context="{'default_ser_room_line': active_id, 'default_folio_id': folio_id}"
nolabel="1" style="padding-right:10px !important;">
<tree string="Services" editable="bottom">
@@ -407,7 +407,7 @@
</form>
</field>
<separator string="Service Lines" colspan="4"/>
<field name="service_line_ids"
<field name="service_ids"
context="{'default_folio_id': active_id}"
nolabel="1">
<tree string="Services" editable="bottom">
@@ -509,7 +509,7 @@
<field name="name"/>
<field name="partner_id"/>
<field name="room_lines"/>
<field name="service_line_ids"/>
<field name="service_ids"/>
<field name="pending_amount"/>
<field name="refund_amount"/>
<field name="invoices_paid"/>

View File

@@ -189,6 +189,7 @@
<group colspan="4" string="Reservation Details" name="reservation_details">
<field name="arrival_hour"/>
<field name="departure_hour"/>
<field name="board_service_id" />
<field name="name"/>
<field name="adults"/>
<field name="children"/>
@@ -238,12 +239,13 @@
<page name="days" string="Service and Days">
<group col="9">
<group colspan="6" string="Reservation Services" name="reservation_services" attrs="{'invisible': [('folio_id','=',False)]}">
<field name="service_line_ids"
<field name="service_ids"
nolabel="1" style="padding-right:10px !important;">
<!-- <field name="service_line_ids"> -->
<!-- <field name="service_ids"> -->
<tree string="Services">
<!-- <field name="sequence" widget="handle"/> -->
<field name="per_day" />
<field name="is_board_service" />
<field name="folio_id" invisible="1"/>
<field name="product_id"
domain="[('sale_ok', '=', True)]"
@@ -252,7 +254,12 @@
<field name="name"/>
<field name="product_qty" attrs="{'readonly': [('per_day','=',True)]}" force_save="1"/>
<field name="days_qty" />
<field name="service_line_ids" />
<field name="service_line_ids" invisible="1">
<tree string="Days" >
<field name="date" />
<field name="day_qty" />
</tree>
</field>
</tree>
<form string="Services">
<!-- <field name="sequence" widget="handle"/> -->