mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[ADD] WorkFlow Product per_day, Service Lines creation and modifications
This commit is contained in:
@@ -103,7 +103,7 @@ class HotelReservation(models.Model):
|
||||
if record.folio_id:
|
||||
record.shared_folio = len(record.folio_id.room_lines) > 1 or \
|
||||
any(record.folio_id.service_line_ids.filtered(
|
||||
lambda x: x.ser_room_line != record.id))
|
||||
lambda x: x.ser_room_line.id != record.id))
|
||||
|
||||
@api.depends('checkin', 'checkout')
|
||||
def _computed_nights(self):
|
||||
@@ -310,25 +310,52 @@ class HotelReservation(models.Model):
|
||||
'last_updated_res': fields.Datetime.now()
|
||||
})
|
||||
for record in self:
|
||||
checkin = vals['checkin'] if 'checkin' in vals else record.checkin
|
||||
checkout = vals['checkout'] if 'checkout' in vals else record.checkout
|
||||
days_diff = (
|
||||
fields.Date.from_string(checkout) - \
|
||||
fields.Date.from_string(checkin)
|
||||
).days
|
||||
if record.compute_price_out_vals(vals):
|
||||
checkin = vals['checkin'] if 'checkin' in vals else record.checkin
|
||||
checkout = vals['checkout'] if 'checkout' in vals else record.checkout
|
||||
|
||||
days_diff = (
|
||||
fields.Date.from_string(checkout) - \
|
||||
fields.Date.from_string(checkin)
|
||||
).days
|
||||
record.update(record.prepare_reservation_lines(
|
||||
vals['checkin'] if 'checkin' in vals else record.checkin,
|
||||
checkin,
|
||||
days_diff,
|
||||
vals=vals)) #REVISAR el unlink
|
||||
if record.compute_qty_service_day(vals):
|
||||
for service in record.service_line_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
|
||||
))
|
||||
if ('checkin' in vals and record.checkin != vals['checkin']) or \
|
||||
('checkout' in vals and record.checkout != vals['checkout']) or \
|
||||
('state' in vals and record.state != vals['state']):
|
||||
vals.update({'to_send': True})
|
||||
('checkout' in vals and record.checkout != vals['checkout']) or \
|
||||
('state' in vals and record.state != vals['state']):
|
||||
record.update({'to_send': True})
|
||||
res = super(HotelReservation, self).write(vals)
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def compute_qty_service_day(self, vals):
|
||||
"""
|
||||
Compute if It is necesary calc price in write/create
|
||||
"""
|
||||
self.ensure_one()
|
||||
if not vals:
|
||||
vals = {}
|
||||
if 'service_line_ids' in vals:
|
||||
return False
|
||||
if ('checkin' in vals and self.checkin != vals['checkin']) or \
|
||||
('checkout' in vals and self.checkout != vals['checkout']) or \
|
||||
('adults' in vals and self.checkout != vals['adults']):
|
||||
return True
|
||||
return False
|
||||
|
||||
@api.model
|
||||
def _prepare_add_missing_fields(self, values):
|
||||
""" Deduce missing required fields from the onchange """
|
||||
@@ -507,6 +534,12 @@ class HotelReservation(models.Model):
|
||||
self.name = self.room_type_id.name + ': ' + checkin_str + ' - '\
|
||||
+ checkout_str
|
||||
|
||||
@api.onchange('checkin', 'checkout')
|
||||
def onchange_update_service_per_day(self):
|
||||
services = self.service_line_ids.filtered(lambda r: r.per_day == True)
|
||||
for service in services:
|
||||
service.onchange_product_calc_qty()
|
||||
|
||||
@api.multi
|
||||
@api.onchange('checkin', 'checkout', 'room_id')
|
||||
def onchange_room_availabiltiy_domain(self):
|
||||
@@ -748,7 +781,8 @@ class HotelReservation(models.Model):
|
||||
#~ pricelist_id = vals.get('pricelist_id') or self.pricelist_id.id
|
||||
room_type_id = vals.get('room_type_id') or self.room_type_id.id
|
||||
product = self.env['hotel.room.type'].browse(room_type_id).product_id
|
||||
old_lines_days = self.mapped('reservation_line_ids.date')
|
||||
old_lines_days = self.mapped('reservation_line_ids.date') #TODO: This is a
|
||||
# PROBLEM when self is multirecord and the records has different old lines
|
||||
partner = self.env['res.partner'].browse(vals.get('partner_id') or self.partner_id.id)
|
||||
for i in range(0, days):
|
||||
idate = (fields.Date.from_string(dfrom) + timedelta(days=i)).strftime(
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
from odoo import models, fields, api
|
||||
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
|
||||
from datetime import timedelta
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
class HotelService(models.Model):
|
||||
_name = 'hotel.service'
|
||||
@@ -22,9 +23,10 @@ class HotelService(models.Model):
|
||||
folio_id = fields.Many2one('hotel.folio', 'Folio', ondelete='cascade')
|
||||
ser_room_line = fields.Many2one('hotel.reservation', 'Room',
|
||||
default=_default_ser_room_line)
|
||||
per_day = fields.Boolean(related='product_id.per_day', 'Unit increment per day')
|
||||
per_day = fields.Boolean(related='product_id.per_day')
|
||||
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)
|
||||
pricelist_id = fields.Many2one(related='folio_id.pricelist_id')
|
||||
channel_type = fields.Selection([
|
||||
('door', 'Door'),
|
||||
@@ -48,53 +50,95 @@ class HotelService(models.Model):
|
||||
store=True,
|
||||
compute='_compute_amount_reservation')
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
if self.compute_lines_out_vals(vals):
|
||||
reservation = self.env['hotel.reservation'].browse(vals['reservation_id'])
|
||||
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
|
||||
))
|
||||
record = super(HotelService, self).create(vals)
|
||||
return record
|
||||
|
||||
@api.multi
|
||||
def write(self, vals):
|
||||
#If you write product, We must check if its necesary create or delete
|
||||
#service lines
|
||||
if vals.get('product_id'):
|
||||
product = self.env['product.product'].browse(vals.get('product_id'))
|
||||
if not product.per_day:
|
||||
vals.update({
|
||||
'service_line_ids' : [(5, 0, 0)]
|
||||
})
|
||||
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
|
||||
}
|
||||
record.update(record.prepare_service_lines(
|
||||
reservation.checkin,
|
||||
reservation.days,
|
||||
params
|
||||
))
|
||||
res = super(HotelService, self).write(vals)
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def compute_lines_out_vals(self, vals):
|
||||
"""
|
||||
Compute if It is necesary service days in write/create
|
||||
"""
|
||||
if not vals:
|
||||
vals = {}
|
||||
if 'product_id' in vals:
|
||||
product = self.env['product.product'].browse(vals['product_id']) \
|
||||
if 'product_id' in vals else self.product_id
|
||||
if (product.per_day and 'service_line_ids' not in vals):
|
||||
return True
|
||||
return False
|
||||
|
||||
@api.onchange('product_id')
|
||||
def onchange_product_calc_qty(self):
|
||||
"""
|
||||
Compute the default quantity according to the
|
||||
configuration of the selected product
|
||||
configuration of the selected product, in per_day product configuration,
|
||||
the qty is autocalculated and readonly based on service_lines qty
|
||||
"""
|
||||
for record in self:
|
||||
product = record.product_id
|
||||
reservation = record.ser_room_line
|
||||
if product and reservation:
|
||||
qty = 1
|
||||
if product.per_day:
|
||||
qty = qty * reservation.nights
|
||||
if product.per_person:
|
||||
qty = qty * (reservation.adults + reservation.children)
|
||||
record.product_qty = qty
|
||||
|
||||
@api.onchange('product_qty')
|
||||
def onchange_product_qty_days_selection(self):
|
||||
"""
|
||||
Try to calculate the days on which the product
|
||||
should be served as long as the product is per day
|
||||
"""
|
||||
for record in self:
|
||||
reservation = record.ser_room_line
|
||||
if record.product_id.per_day:
|
||||
days_diff = (
|
||||
fields.Date.from_string(reservation.checkout) - fields.Date.from_string(reservation.checkin)
|
||||
).days
|
||||
record.update(record.prepare_service_lines(
|
||||
reservation.checkin,
|
||||
days_diff))
|
||||
else:
|
||||
record.update(record.prepare_service_lines(
|
||||
reservation.checkin, 1))
|
||||
|
||||
##WIP##
|
||||
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, vals=False):
|
||||
def prepare_service_lines(self, dfrom, days, params=False):
|
||||
"""
|
||||
Respect the old manual changes on lines
|
||||
"""
|
||||
self.ensure_one()
|
||||
old_qty = 0
|
||||
cmds = [(5, 0, 0)]
|
||||
old_lines_days = self.mapped('service_line_ids.date')
|
||||
for day in self.service_line_ids:
|
||||
old_qty = old_qty + day.day_qty
|
||||
qty_day = (self.product_qty - old_qty) // (days - len(old_line_days))
|
||||
rest_day = (self.product_qty - old_qty) % (days - len(old_line_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(
|
||||
DEFAULT_SERVER_DATE_FORMAT)
|
||||
@@ -102,11 +146,13 @@ class HotelService(models.Model):
|
||||
if idate not in old_lines_days:
|
||||
cmds.append((0, False, {
|
||||
'date': idate,
|
||||
'day_qty': qty_day
|
||||
'day_qty': day_qty
|
||||
}))
|
||||
total_qty = total_qty + day_qty
|
||||
else:
|
||||
cmds.append((4, old_line.id))
|
||||
return {'service_line_ids': cmds}
|
||||
total_qty = total_qty + old_line.day_qty
|
||||
return {'service_line_ids': cmds, 'product_qty': total_qty}
|
||||
|
||||
@api.depends('qty_product', 'tax_id')
|
||||
def _compute_amount_service(self):
|
||||
@@ -122,3 +168,25 @@ class HotelService(models.Model):
|
||||
'price_total': taxes['total_included'],
|
||||
'price_subtotal': taxes['total_excluded'],
|
||||
})
|
||||
|
||||
@api.depends('service_line_ids.day_qty')
|
||||
def _compute_days_qty(self):
|
||||
for record in self:
|
||||
if record.per_day:
|
||||
qty = sum(record.service_line_ids.mapped('day_qty'))
|
||||
vals = {
|
||||
'days_qty': qty,
|
||||
'product_qty': qty
|
||||
}
|
||||
else:
|
||||
vals = {'days_qty': 0}
|
||||
record.update(vals)
|
||||
|
||||
@api.constrains('qty_product')
|
||||
def constrains_qty_per_day(self):
|
||||
for record in self:
|
||||
if record.per_day:
|
||||
service_lines = self.env['hotel.service_line']
|
||||
total_day_qty = sum(service_lines.with_context({'service_id': record.id}).mapped('day_qty'))
|
||||
if record.qty_product != total_day_qty:
|
||||
raise ValidationError (_('The quantity per line and per day does not correspond'))
|
||||
|
||||
@@ -26,7 +26,6 @@ class HotelServiceLine(models.Model):
|
||||
if limit < out_qty + record.day_qty:
|
||||
raise ValidationError(
|
||||
_("Limit exceeded for %s")% record.date)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -239,34 +239,38 @@
|
||||
<group col="9">
|
||||
<group colspan="6" string="Reservation Services" name="reservation_services" attrs="{'invisible': [('folio_id','=',False)]}">
|
||||
<field name="service_line_ids"
|
||||
context="{'default_ser_room_line': active_id, 'default_folio_id': folio_id}"
|
||||
nolabel="1" style="padding-right:10px !important;">
|
||||
<!-- <field name="service_line_ids"> -->
|
||||
<tree string="Services" editable="bottom">
|
||||
<tree string="Services">
|
||||
<!-- <field name="sequence" widget="handle"/> -->
|
||||
<field name="per_day" />
|
||||
<field name="folio_id" invisible="1"/>
|
||||
<field name="product_id"
|
||||
domain="[('sale_ok', '=', True)]"
|
||||
options="{'create': False, 'create_edit': False}" />
|
||||
<!-- <field name="layout_category_id" groups="sale.group_sale_layout"/> -->
|
||||
<field name="name"/>
|
||||
<field name="product_qty" attrs="{'readonly': [('per_day','=',True)]}"/>
|
||||
<field name="pricelist_id"/>
|
||||
<!-- <field name="ser_room_line" invisible="1" /> -->
|
||||
<!-- <field name="qty_delivered" invisible="1"
|
||||
attrs="{'readonly': [('qty_delivered_updateable', '=', False)]}"/> -->
|
||||
<!-- <field name="product_uom"
|
||||
attrs="{'readonly': [('state', 'in', ('sale','done', 'cancel'))]}"
|
||||
context="{'company_id': parent.company_id}"
|
||||
groups="product.group_uom" options='{"no_open": True}'/> -->
|
||||
<!-- <field name="analytic_tag_ids" groups="analytic.group_analytic_accounting" widget="many2many_tags"/> -->
|
||||
<!-- <field name="tax_id" widget="many2many_tags" invisible="1"/> -->
|
||||
<!-- <field name="qty_delivered_updateable" invisible="1"/> -->
|
||||
<!-- <field name="state" invisible="1"/> -->
|
||||
<!-- <field name="invoice_status" invisible="1"/> -->
|
||||
<!-- <field name="customer_lead" invisible="1"/> -->
|
||||
<!-- <field name="currency_id" invisible="1"/> -->
|
||||
<field name="product_qty" attrs="{'readonly': [('per_day','=',True)]}" force_save="1"/>
|
||||
<field name="days_qty" />
|
||||
<field name="service_line_ids" />
|
||||
</tree>
|
||||
<form string="Services">
|
||||
<!-- <field name="sequence" widget="handle"/> -->
|
||||
<field name="per_day" />
|
||||
<field name="folio_id" invisible="1"/>
|
||||
<field name="product_id"
|
||||
domain="[('sale_ok', '=', True)]"
|
||||
options="{'create': False, 'create_edit': False}" />
|
||||
<!-- <field name="layout_category_id" groups="sale.group_sale_layout"/> -->
|
||||
<field name="name"/>
|
||||
<field name="product_qty" attrs="{'readonly': [('per_day','=',True)]}" force_save="1"/>
|
||||
<field name="service_line_ids">
|
||||
<tree string="Days" >
|
||||
<field name="date" />
|
||||
<field name="day_qty" />
|
||||
</tree>
|
||||
</field>
|
||||
</form>
|
||||
</field>
|
||||
</group>
|
||||
<group colspan="4" string="Days" name="days">
|
||||
|
||||
@@ -8,51 +8,33 @@
|
||||
<field name="model">hotel.service.line</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Service Line">
|
||||
<notebook>
|
||||
<page string="Service Line">
|
||||
<group col="4" colspan="4">
|
||||
<field name="name" />
|
||||
<!-- <field name="ser_room_line" options="{'create': False, 'create_edit': False}"/> -->
|
||||
<!-- <field name="product_uom" options="{'create': False, 'create_edit': False}" invisible="1"/> -->
|
||||
<!-- <field name="order_partner_id" invisible="1"/> -->
|
||||
<field name="folio_id" invisible="1"/>
|
||||
<field name="list_price" />
|
||||
<!-- <field name="tax_id" widget="many2many_tags" invisible="1"/> -->
|
||||
|
||||
</group>
|
||||
<separator string="Manual Description" colspan="4" invisible="1"/>
|
||||
<!-- <field name="name" colspan="4" select="2"
|
||||
placeholder="-Description-" invisible="1"/> -->
|
||||
<newline />
|
||||
<group invisible="1">
|
||||
<separator string="States" colspan="4" />
|
||||
<!-- <field name="state" select="2" /> -->
|
||||
</group>
|
||||
</page>
|
||||
</notebook>
|
||||
<group>
|
||||
<field name="name" />
|
||||
<field name="day_qty"/>
|
||||
<field name="date" />
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Tree view of hotel service -->
|
||||
<!-- Tree view of hotel service Line -->
|
||||
<record model="ir.ui.view" id="hotel_service_line_view_tree">
|
||||
<field name="name">hotel.service.line.tree</field>
|
||||
<field name="model">hotel.service.line</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Hotel Services">
|
||||
<tree string="Hotel By Day">
|
||||
<field name="name" />
|
||||
<field name="list_price" string="Service rate" />
|
||||
<field name="day_qty"/>
|
||||
<field name="date" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Action for hotel service -->
|
||||
<!-- Action for hotel service line-->
|
||||
<record model="ir.actions.act_window" id="action_hotel_service_line_form">
|
||||
<field name="name">Hotel Services</field>
|
||||
<field name="res_model">hotel.service.line</field>
|
||||
<field name="view_type">form</field>
|
||||
<!-- <field name="context">{'default_isservice':1}
|
||||
</field> -->
|
||||
<field name="view_mode">tree,form</field>
|
||||
</record>
|
||||
|
||||
|
||||
@@ -6,58 +6,26 @@
|
||||
<field name="name">.hotel.service.form</field>
|
||||
<field name="model">hotel.service</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Hotel Services">
|
||||
<form string="Reservation Service">
|
||||
<sheet>
|
||||
<h1>
|
||||
<label string="Service" />
|
||||
<field name="name" select="1" />
|
||||
</h1>
|
||||
<group>
|
||||
<field name="default_code" select="1" />
|
||||
<field name="product_id" />
|
||||
<field name="product_qty" />
|
||||
</group>
|
||||
<notebook>
|
||||
<page string="Information">
|
||||
<group>
|
||||
<group colspan="4" col="4">
|
||||
<field name="service_type_id" select="2" string="Service Type" />
|
||||
<!-- <field name="categ_id" domain="[('isservicetype','=',True)]"
|
||||
select="1" /> -->
|
||||
</group>
|
||||
</group>
|
||||
<newline />
|
||||
<separator colspan='4' string="Supplier Taxes" />
|
||||
<!-- <field name="supplier_taxes_id" colspan="4" nolabel='1'
|
||||
help='List of supplier taxes related to the service provided by hotel.' /> -->
|
||||
<newline />
|
||||
<separator colspan='4' string="Customer Taxes" />
|
||||
<!-- <field name="taxes_id" colspan="4" nolabel='1'
|
||||
help='Customer taxes applied on the service.' /> -->
|
||||
</page>
|
||||
<page string="Procurement">
|
||||
<group colspan="4" col="4">
|
||||
<field name="active" select="2" />
|
||||
<field name="list_price" />
|
||||
<!-- <field name="cost_method" string="Cost Method"/> -->
|
||||
<!-- <field name="sale_ok" select="2" /> -->
|
||||
<!-- <field name="standard_price" /> -->
|
||||
<!-- <field name="rental" select="2" /> -->
|
||||
</group>
|
||||
<newline />
|
||||
<group>
|
||||
<!-- <separator string="Suplliers" />
|
||||
<field name="seller_ids" colspan="4" nolabel="1"
|
||||
widget="one2many_list" /> -->
|
||||
</group>
|
||||
</page>
|
||||
<page string="Descriptions">
|
||||
<!-- <separator string="Description" />
|
||||
<field name="description" colspan="4" nolabel="1" />
|
||||
<separator string="Sale Description" />
|
||||
<field name="description_sale" colspan="4" nolabel="1" />
|
||||
<separator string="Purchase Description" />
|
||||
<field name="description_purchase" colspan="4" nolabel="1" /> -->
|
||||
</page>
|
||||
</notebook>
|
||||
<group>
|
||||
<field name="price_subtotal" />
|
||||
<field name="price_total" />
|
||||
</group>
|
||||
<field name="service_line_ids">
|
||||
<tree string="Days" >
|
||||
<field name="date" />
|
||||
<field name="day_qty" />
|
||||
</tree>
|
||||
</field>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
@@ -68,10 +36,10 @@
|
||||
<field name="name">hotel.service.search</field>
|
||||
<field name="model">hotel.service</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Hotel Services">
|
||||
<search string="Reservation Service">
|
||||
<field name="name" />
|
||||
<field name="service_type_id" select="1" />
|
||||
<field name="list_price" string="Service rate" />
|
||||
<field name="product_id"/>
|
||||
<field name="product_qty" />
|
||||
<newline />
|
||||
<group expand="0" string="Group By...">
|
||||
<!-- <filter name="categ_id" string="Catagory"
|
||||
@@ -89,8 +57,8 @@
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Hotel Services">
|
||||
<field name="name" />
|
||||
<field name="service_type_id" />
|
||||
<field name="list_price" string="Service rate" />
|
||||
<field name="product_id" />
|
||||
<field name="product_qty" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user