mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[WIP] Wizard Node Reservation
Added date and price by day to each room type in the wizard
This commit is contained in:
@@ -48,7 +48,7 @@ class HotelRoomType(models.Model):
|
|||||||
)
|
)
|
||||||
reservation_line_ids = reservation_line_ids['reservation_line_ids']
|
reservation_line_ids = reservation_line_ids['reservation_line_ids']
|
||||||
# QUESTION Why add [[5, 0, 0], ¿?
|
# QUESTION Why add [[5, 0, 0], ¿?
|
||||||
del reservation_line_ids[0]
|
# del reservation_line_ids[0]
|
||||||
|
|
||||||
return reservation_line_ids
|
return reservation_line_ids
|
||||||
|
|
||||||
|
|||||||
@@ -41,17 +41,17 @@ class HotelNodeReservationWizard(models.TransientModel):
|
|||||||
price_total = fields.Float(string='Total Price', compute='_compute_price_total', store=True)
|
price_total = fields.Float(string='Total Price', compute='_compute_price_total', store=True)
|
||||||
|
|
||||||
# FIXED @constrains parameter 'room_type_wizard_ids.room_qty' is not a field name
|
# FIXED @constrains parameter 'room_type_wizard_ids.room_qty' is not a field name
|
||||||
@api.constrains('room_type_wizard_ids')
|
# @api.constrains('room_type_wizard_ids')
|
||||||
def _check_room_type_wizard_total_qty(self):
|
# def _check_room_type_wizard_total_qty(self):
|
||||||
for rec in self:
|
# for rec in self:
|
||||||
total_qty = 0
|
# total_qty = 0
|
||||||
for rec_room_type in rec.room_type_wizard_ids:
|
# for rec_room_type in rec.room_type_wizard_ids:
|
||||||
total_qty += rec_room_type.room_qty
|
# total_qty += rec_room_type.room_qty
|
||||||
|
#
|
||||||
if total_qty == 0:
|
# if total_qty == 0:
|
||||||
msg = _("It is not possible to create the reservation.") + " " + \
|
# msg = _("It is not possible to create the reservation.") + " " + \
|
||||||
_("Maybe you forgot adding the quantity to at least one type of room?.")
|
# _("Maybe you forgot adding the quantity to at least one type of room?.")
|
||||||
raise ValidationError(msg)
|
# raise ValidationError(msg)
|
||||||
|
|
||||||
@api.depends('room_type_wizard_ids.price_total')
|
@api.depends('room_type_wizard_ids.price_total')
|
||||||
def _compute_price_total(self):
|
def _compute_price_total(self):
|
||||||
@@ -75,50 +75,111 @@ class HotelNodeReservationWizard(models.TransientModel):
|
|||||||
}))
|
}))
|
||||||
self.room_type_wizard_ids = cmds
|
self.room_type_wizard_ids = cmds
|
||||||
|
|
||||||
@api.multi
|
@api.model
|
||||||
def create_node_reservation(self):
|
def create(self, vals):
|
||||||
self.ensure_one()
|
# TODO review node.room.type.wizard @api.constrains('room_qty')
|
||||||
|
from pprint import pprint
|
||||||
try:
|
try:
|
||||||
noderpc = odoorpc.ODOO(self.node_id.odoo_host, self.node_id.odoo_protocol, self.node_id.odoo_port)
|
node = self.env["project.project"].browse(vals['node_id'])
|
||||||
noderpc.login(self.node_id.odoo_db, self.node_id.odoo_user, self.node_id.odoo_password)
|
|
||||||
|
|
||||||
# prepare required fields for hotel folio
|
noderpc = odoorpc.ODOO(node.odoo_host, node.odoo_protocol, node.odoo_port)
|
||||||
remote_partner_id = noderpc.env['res.partner'].search([('email', '=', self.partner_id.email)]).pop()
|
noderpc.login(node.odoo_db, node.odoo_user, node.odoo_password)
|
||||||
vals = {
|
|
||||||
|
# prepare required fields for hotel.folio
|
||||||
|
remote_vals = {}
|
||||||
|
partner = self.env["res.partner"].browse(vals['partner_id'])
|
||||||
|
remote_partner_id = noderpc.env['res.partner'].search([('email', '=', partner.email)]).pop()
|
||||||
|
# TODO create partner if does not exist in remote node
|
||||||
|
remote_vals.update({
|
||||||
'partner_id': remote_partner_id,
|
'partner_id': remote_partner_id,
|
||||||
}
|
})
|
||||||
# prepare hotel folio room_lines
|
|
||||||
|
# prepare hotel.folio.room_lines
|
||||||
room_lines = []
|
room_lines = []
|
||||||
for rec in self.room_type_wizard_ids:
|
for cmds in vals['room_type_wizard_ids']:
|
||||||
for x in range(rec.room_qty):
|
# cmds is a list of triples: [0, 'virtual_1008', {'checkin': '2018-11-05', ...
|
||||||
wdb.set_trace()
|
room_type_wizard_values = cmds[2]
|
||||||
# prepare hotel reservation lines with details by day
|
remote_room_type_id = self.env['hotel.node.room.type'].search([
|
||||||
reservation_line_cmds = rec.room_type_line_ids.mapped(lambda reservation_line: (0, False, {
|
('id', '=', room_type_wizard_values['room_type_id'])
|
||||||
'date': reservation_line.date,
|
]).remote_room_type_id
|
||||||
'price': reservation_line.price,
|
# prepare room_lines a number of times `room_qty` times
|
||||||
}))
|
for room in range(room_type_wizard_values['room_qty']):
|
||||||
# add discount
|
# prepare hotel.reservation.reservation_line_ids
|
||||||
|
reservation_line_cmds = []
|
||||||
|
for room_type_line_cmds in room_type_wizard_values['room_type_line_ids']:
|
||||||
|
reservation_line = room_type_line_cmds[2]
|
||||||
|
reservation_line_cmds.append((0, False, {
|
||||||
|
'date': reservation_line['date'],
|
||||||
|
'price': reservation_line['price'],
|
||||||
|
}))
|
||||||
|
# add discount ¿?
|
||||||
room_lines.append((0, False, {
|
room_lines.append((0, False, {
|
||||||
'room_type_id': rec.room_type_id.remote_room_type_id,
|
'room_type_id': remote_room_type_id,
|
||||||
'checkin': rec.checkin,
|
'checkin': room_type_wizard_values['checkin'],
|
||||||
'checkout': rec.checkout,
|
'checkout': room_type_wizard_values['checkout'],
|
||||||
'reservation_line_ids': reservation_line_cmds,
|
'reservation_line_ids': reservation_line_cmds,
|
||||||
}))
|
}))
|
||||||
vals.update({'room_lines': room_lines})
|
remote_vals.update({'room_lines': room_lines})
|
||||||
|
|
||||||
from pprint import pprint
|
pprint(remote_vals)
|
||||||
pprint(vals)
|
# if total_qty == 0:
|
||||||
|
# msg = _("It is not possible to create the reservation.") + " " + \
|
||||||
folio_id = noderpc.env['hotel.folio'].create(vals)
|
# _("Maybe you forgot adding the quantity to at least one type of room?.")
|
||||||
_logger.info('User #%s created a hotel.folio with ID: [%s]',
|
# raise ValidationError(msg)
|
||||||
|
folio_id = noderpc.env['hotel.folio'].create(remote_vals)
|
||||||
|
_logger.info('User #%s created a remote hotel.folio with ID: [%s]',
|
||||||
self._context.get('uid'), folio_id)
|
self._context.get('uid'), folio_id)
|
||||||
|
|
||||||
noderpc.logout()
|
noderpc.logout()
|
||||||
|
|
||||||
# TODO return a wizard and preview the resevation
|
|
||||||
|
|
||||||
except (odoorpc.error.RPCError, odoorpc.error.InternalError, urllib.error.URLError) as err:
|
except (odoorpc.error.RPCError, odoorpc.error.InternalError, urllib.error.URLError) as err:
|
||||||
|
_logger.error(err)
|
||||||
raise ValidationError(err)
|
raise ValidationError(err)
|
||||||
|
else:
|
||||||
|
return super().create(vals)
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def create_node_reservation(self):
|
||||||
|
_logger.info('# TODO: return a wizard and preview the reservation')
|
||||||
|
# self.ensure_one()
|
||||||
|
# # NOTE This function is executed __after__ create(self, vals) where _compute_restrictions are executed again
|
||||||
|
# try:
|
||||||
|
# noderpc = odoorpc.ODOO(self.node_id.odoo_host, self.node_id.odoo_protocol, self.node_id.odoo_port)
|
||||||
|
# noderpc.login(self.node_id.odoo_db, self.node_id.odoo_user, self.node_id.odoo_password)
|
||||||
|
#
|
||||||
|
# # prepare required fields for hotel folio
|
||||||
|
# remote_partner_id = noderpc.env['res.partner'].search([('email', '=', self.partner_id.email)]).pop()
|
||||||
|
# vals = {
|
||||||
|
# 'partner_id': remote_partner_id,
|
||||||
|
# }
|
||||||
|
# # prepare hotel folio room_lines
|
||||||
|
# room_lines = []
|
||||||
|
# for rec in self.room_type_wizard_ids:
|
||||||
|
# for x in range(rec.room_qty):
|
||||||
|
# # prepare hotel reservation lines with details by day
|
||||||
|
# reservation_line_cmds = rec.room_type_line_ids.mapped(lambda reservation_line: (0, False, {
|
||||||
|
# 'date': reservation_line.date,
|
||||||
|
# 'price': reservation_line.price,
|
||||||
|
# }))
|
||||||
|
# # add discount
|
||||||
|
# room_lines.append((0, False, {
|
||||||
|
# 'room_type_id': rec.room_type_id.remote_room_type_id,
|
||||||
|
# 'checkin': rec.checkin,
|
||||||
|
# 'checkout': rec.checkout,
|
||||||
|
# 'reservation_line_ids': reservation_line_cmds,
|
||||||
|
# }))
|
||||||
|
# vals.update({'room_lines': room_lines})
|
||||||
|
#
|
||||||
|
# from pprint import pprint
|
||||||
|
# pprint(vals)
|
||||||
|
#
|
||||||
|
# folio_id = noderpc.env['hotel.folio'].create(vals)
|
||||||
|
# _logger.info('User #%s created a hotel.folio with ID: [%s]',
|
||||||
|
# self._context.get('uid'), folio_id)
|
||||||
|
#
|
||||||
|
# noderpc.logout()
|
||||||
|
# except (odoorpc.error.RPCError, odoorpc.error.InternalError, urllib.error.URLError) as err:
|
||||||
|
# raise ValidationError(err)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _open_wizard_action_search(self):
|
def _open_wizard_action_search(self):
|
||||||
@@ -172,14 +233,14 @@ class NodeRoomTypeWizard(models.TransientModel):
|
|||||||
|
|
||||||
@api.constrains('room_qty')
|
@api.constrains('room_qty')
|
||||||
def _check_room_qty(self):
|
def _check_room_qty(self):
|
||||||
total_qty = 0
|
# At least one model cache has been invalidated, signaling through the database.
|
||||||
|
wdb.set_trace()
|
||||||
for rec in self:
|
for rec in self:
|
||||||
if (rec.room_type_availability < rec.room_qty) or (rec.room_qty > 0 and rec.nights < rec.min_stay):
|
if (rec.room_type_availability < rec.room_qty) or (rec.room_qty > 0 and rec.nights < rec.min_stay):
|
||||||
msg = _("At least one room type has not availability or does not meet restrictions.") + " " + \
|
msg = _("At least one room type has not availability or does not meet restrictions.") + " " + \
|
||||||
_("Please, review room type %s between %s and %s.") % (rec.room_type_id.name, rec.checkin, rec.checkout)
|
_("Please, review room type %s between %s and %s.") % (rec.room_type_id.name, rec.checkin, rec.checkout)
|
||||||
_logger.warning(msg)
|
_logger.warning(msg)
|
||||||
raise ValidationError(msg)
|
raise ValidationError(msg)
|
||||||
total_qty += rec.room_qty
|
|
||||||
|
|
||||||
@api.depends('room_qty', 'price_unit', 'discount')
|
@api.depends('room_qty', 'price_unit', 'discount')
|
||||||
def _compute_price_total(self):
|
def _compute_price_total(self):
|
||||||
@@ -217,7 +278,7 @@ class NodeRoomTypeWizard(models.TransientModel):
|
|||||||
# cmds.append((0, False, {
|
# cmds.append((0, False, {
|
||||||
# 'date': (fields.Date.from_string(rec.checkin) + timedelta(days=x)).strftime(
|
# 'date': (fields.Date.from_string(rec.checkin) + timedelta(days=x)).strftime(
|
||||||
# DEFAULT_SERVER_DATE_FORMAT),
|
# DEFAULT_SERVER_DATE_FORMAT),
|
||||||
# 'price': 25.0,
|
# 'price': 11.50,
|
||||||
# }))
|
# }))
|
||||||
# from pprint import pprint
|
# from pprint import pprint
|
||||||
# pprint(cmds)
|
# pprint(cmds)
|
||||||
|
|||||||
@@ -30,7 +30,12 @@
|
|||||||
<field name="room_type_id" string="Room Type" readonly="1" force_save="1"/>
|
<field name="room_type_id" string="Room Type" readonly="1" force_save="1"/>
|
||||||
<field name="room_type_availability" readonly="1"/>
|
<field name="room_type_availability" readonly="1"/>
|
||||||
<field name="room_qty"/>
|
<field name="room_qty"/>
|
||||||
<field name="room_type_line_ids"/>
|
<field name="room_type_line_ids" widget="one2many_list" invisible="1">
|
||||||
|
<tree editable="bottom">
|
||||||
|
<field name="date"/>
|
||||||
|
<field name="price"/>
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
<field name="checkin" widget="date"/>
|
<field name="checkin" widget="date"/>
|
||||||
<field name="checkout" widget="date"/>
|
<field name="checkout" widget="date"/>
|
||||||
<field name="nights"/>
|
<field name="nights"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user