mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[DEL] Duplicate Reservations
This commit is contained in:
@@ -26,7 +26,6 @@
|
||||
'security/ir.model.access.csv',
|
||||
'wizard/massive_changes.xml',
|
||||
'wizard/split_reservation.xml',
|
||||
'wizard/duplicate_reservation.xml',
|
||||
'wizard/service_on_day.xml',
|
||||
'views/res_config.xml',
|
||||
'data/menus.xml',
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
from . import folio_make_invoice_advance
|
||||
from . import massive_changes
|
||||
from . import split_reservation
|
||||
from . import duplicate_reservation
|
||||
from . import massive_price_reservation_days
|
||||
from . import wizard_reservation
|
||||
from . import service_on_day
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
# Copyright 2017 Dario Lodeiros
|
||||
# Copyright 2018 Alexandre Díaz
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from openerp.exceptions import ValidationError
|
||||
from datetime import timedelta
|
||||
from openerp import models, fields, api, _
|
||||
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
|
||||
|
||||
|
||||
class DuplicateReservationWizard(models.TransientModel):
|
||||
_name = 'hotel.wizard.duplicate.reservation'
|
||||
|
||||
num = fields.Integer('Num. New Reservations', default=1, min=1)
|
||||
|
||||
@api.multi
|
||||
def duplicate_reservation(self):
|
||||
self.ensure_one()
|
||||
hotel_reservation_obj = self.env['hotel.reservation']
|
||||
reservation_id = hotel_reservation_obj.browse(
|
||||
self.env.context.get('active_id'))
|
||||
if not reservation_id:
|
||||
return False
|
||||
|
||||
if reservation_id.splitted:
|
||||
raise ValidationError(_("Can't duplicate splitted reservations"))
|
||||
|
||||
hotel_room_type_obj = self.env['hotel.room.type']
|
||||
|
||||
cmds_reservation_lines = []
|
||||
for rline in reservation_id.reservation_lines:
|
||||
cmds_reservation_lines.append((0, False, {
|
||||
'date': rline.date,
|
||||
'price': rline.price,
|
||||
}))
|
||||
|
||||
# Check Input
|
||||
avails = hotel_room_type_obj.check_availability_room_type(
|
||||
reservation_id.checkin,
|
||||
(fields.Date.from_string(reservation_id.checkout) -
|
||||
timedelta(days=1)).strftime(
|
||||
DEFAULT_SERVER_DATE_FORMAT
|
||||
),
|
||||
room_type_id=reservation_id.room_type_id.id)
|
||||
total_free_rooms = len(avails)
|
||||
|
||||
if total_free_rooms < self.num:
|
||||
raise ValidationError(_("Too much duplicated reservations! \
|
||||
There are no '%d' free rooms") % self.num)
|
||||
|
||||
for i in range(0, self.num):
|
||||
free_rooms = hotel_room_type_obj.check_availability_room_type(
|
||||
reservation_id.checkin,
|
||||
(fields.Date.from_string(reservation_id.checkout) -
|
||||
timedelta(days=1)).strftime(
|
||||
DEFAULT_SERVER_DATE_FORMAT
|
||||
),
|
||||
room_type_id=reservation_id.room_type_id.id)
|
||||
if any(free_rooms):
|
||||
new_reservation_id = hotel_reservation_obj.create({
|
||||
'room_id': free_rooms[0].id,
|
||||
'room_type_id': free_rooms[0].room_type_id.id,
|
||||
'folio_id': reservation_id.folio_id.id,
|
||||
'checkin': reservation_id.checkin,
|
||||
'checkout': reservation_id.checkout,
|
||||
'adults': reservation_id.adults,
|
||||
'children': reservation_id.children,
|
||||
'name': reservation_id.name,
|
||||
'reservation_lines': cmds_reservation_lines,
|
||||
})
|
||||
if new_reservation_id:
|
||||
rpartner_id = reservation_id.order_id.partner_id
|
||||
new_reservation_id.order_id.partner_id = rpartner_id
|
||||
break
|
||||
else:
|
||||
raise ValidationError(_("Unexpected Error: Can't found a \
|
||||
free room"))
|
||||
return True
|
||||
@@ -1,35 +0,0 @@
|
||||
<?xml version="1.0" ?>
|
||||
<odoo>
|
||||
|
||||
<record model="ir.ui.view" id="view_hotel_duplicate_reservation_wizard">
|
||||
<field name="name">hotel.wizard.duplicate.reservation</field>
|
||||
<field name="model">hotel.wizard.duplicate.reservation</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Duplicate Rerservation" >
|
||||
<!-- Common Fields -->
|
||||
<group>
|
||||
<field name="num" required="1" />
|
||||
</group>
|
||||
<footer>
|
||||
<button name="duplicate_reservation" string="Duplicate" type="object"
|
||||
class="oe_highlight" />
|
||||
or
|
||||
<button string="Cancel" class="oe_link" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_hotel_duplicate_reservation" model="ir.actions.act_window">
|
||||
<field name="name">Duplicate Reservation</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">hotel.wizard.duplicate.reservation</field>
|
||||
<field name="view_id" ref="view_hotel_duplicate_reservation_wizard"/>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="binding_model_id" ref="model_hotel_reservation" />
|
||||
<field name="binding_type">report</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user