Refactory 06

This commit is contained in:
Oscar 2021-10-09 12:49:43 -05:00
parent c25314760c
commit f26cf50bca
5 changed files with 159 additions and 193 deletions

View File

@ -6,7 +6,9 @@ from datetime import datetime, timedelta
from decimal import Decimal
from trytond.model import Workflow, ModelView, ModelSQL, fields
from trytond.wizard import Wizard, StateView, Button, StateTransition, StateReport
from trytond.wizard import (
Wizard, StateView, Button, StateTransition, StateReport
)
from trytond.report import Report
from trytond.pyson import Eval, If, In, Get, Not, Or, Equal, Bool
from trytond.transaction import Transaction
@ -15,7 +17,7 @@ from trytond.exceptions import UserError
from trytond.i18n import gettext
from constants import (
STATE_BOOKING, REGISTRATION_STATE, SEGMENT, GUARANTEE, SATISFACTION,
MEDIA, PLAN, SOURCE, INVOICE_METHOD, COMPLEMENTARY, INVOICE_STATES,
MEDIA, PLAN, SOURCE, INVOICE_METHOD, COMPLEMENTARY,
)
STATES = {
@ -145,13 +147,14 @@ class Booking(Workflow, ModelSQL, ModelView):
))
cls._buttons.update({
'select_rooms': {
'invisible': Eval('state') != 'offer',
'invisible': Eval('state').in_(['finished', 'cancelled', 'not_show']),
},
'create_guest': {
'invisible': Eval('state') != 'offer',
},
'cancel': {
'invisible': Eval('state').in_(['cancel', ''])
'invisible': Eval('state').in_(
['cancelled', 'not_show', 'finished'])
},
'offer': {
'invisible': Eval('state').in_(['offer', 'confirmed'])
@ -163,8 +166,7 @@ class Booking(Workflow, ModelSQL, ModelView):
'invisible': Eval('state') != 'confirmed',
},
'pay_advance': {
'invisible':
Eval('registration_state').in_(['check_out', 'offer']),
'invisible': Eval('state').in_(['finished', 'cancelled']),
},
'send_email': {
'invisible': Eval('state') != 'confirmed'
@ -248,15 +250,13 @@ class Booking(Workflow, ModelSQL, ModelView):
@ModelView.button
@Workflow.transition('offer')
def offer(cls, records):
for record in records:
record.delete_occupancy()
pass
@classmethod
@ModelView.button
@Workflow.transition('cancelled')
def cancel(cls, records):
for record in records:
record.cancel_occupancy()
pass
@classmethod
@ModelView.button
@ -302,18 +302,6 @@ class Booking(Workflow, ModelSQL, ModelView):
number = config.booking_sequence.get()
cls.write([booking], {'number': number})
def cancel_occupancy(self):
Operation = Pool().get('hotel.operation')
ops = Operation.search([('origin', '=', str(self))])
if ops:
Operation.cancel(ops)
def delete_occupancy(self):
Operation = Pool().get('hotel.operation')
for l in self.lines:
if l.operation:
Operation.delete([l.operation])
def update_folio(self, state):
Line = Pool().get('hotel.folio')
Line.write(list(self.lines), {'registration_state': state})

View File

@ -198,70 +198,6 @@ this repository contains the full copyright notices and license terms. -->
<field name="perm_delete" eval="True"/>
</record>
<record model="ir.ui.view" id="board_folio_view_tree">
<field name="model">hotel.folio</field>
<field name="type">tree</field>
<field name="name">board_folio_tree</field>
</record>
<record model="ir.ui.view" id="board_folio_view_form">
<field name="model">hotel.folio</field>
<field name="type">form</field>
<field name="name">board_folio_form</field>
</record>
<record model="ir.action.act_window" id="act_board_folio_view">
<field name="name">Board Folios</field>
<field name="res_model">hotel.folio</field>
<field name="search_value"
eval="[('create_date', '>=', DateTime(hour=0, minute=0, second=0, microsecond=0, delta_years=-1))]"
pyson="1"/>
</record>
<record model="ir.action.act_window.view" id="act_hotel_board_folio_tree_view">
<field name="sequence" eval="1"/>
<field name="view" ref="board_folio_view_tree"/>
<field name="act_window" ref="act_board_folio_view"/>
</record>
<record model="ir.action.act_window.view" id="act_hotel_board_folio_form_view">
<field name="sequence" eval="2"/>
<field name="view" ref="board_folio_view_form"/>
<field name="act_window" ref="act_board_folio_view"/>
</record>
<menuitem parent="menu_booking_form" sequence="30"
action="act_board_folio_view" id="menu_hotel_board_folio"/>
<record model="ir.action.act_window.domain" id="act_guest_moves_form_domain_arriving_today">
<field name="name">Arriving Today</field>
<field name="sequence" eval="50"/>
<field name="domain" eval="[
('arrival_date', '=', Date()),
]" pyson="1"/>
<field name="act_window" ref="act_board_folio_view"/>
</record>
<record model="ir.action.act_window.domain" id="act_guest_moves_form_domain_leaving_today">
<field name="name">Leaving Today</field>
<field name="sequence" eval="70"/>
<field name="domain" eval="[
('departure_date', '=', Date()),
]" pyson="1"/>
<field name="act_window" ref="act_board_folio_view"/>
</record>
<record model="ir.action.act_window.domain" id="act_guest_moves_form_domain_no_show_today">
<field name="name">No Show Yesterday</field>
<field name="sequence" eval="90"/>
<field name="domain" eval="[
('arrival_date', '=', Date()),
('booking.registration_state', 'in', ['no_show']),
]" pyson="1"/>
<field name="act_window" ref="act_board_folio_view"/>
</record>
<record model="ir.action.act_window.domain" id="act_guest_moves_form_domain_all">
<field name="name">All</field>
<field name="sequence" eval="90"/>
<field name="domain" eval="[
('arrival_date', '>=', Date()),
]" pyson="1"/>
<field name="act_window" ref="act_board_folio_view"/>
</record>
<!-- <record model="ir.action.act_window" id="act_open_booking_sales_form">
<field name="name">Sales</field>
<field name="res_model">sale.sale</field>

148
folio.py
View File

@ -126,16 +126,32 @@ class Folio(ModelSQL, ModelView):
],
cls._buttons.update({
'check_in': {
'invisible': Eval('registration_state').in_(['check_in', 'check_out']),
'invisible': Eval('registration_state') != 'pending',
},
'check_out': {
'invisible': Eval('registration_state').in_(['check_out', 'pending']),
'invisible': Eval('registration_state') != 'check_in',
},
'bill': {
'invisible': Eval('registration_state') != 'check_out',
}
})
@classmethod
def search_rec_name(cls, name, clause):
_, operator, value = clause
if operator.startswith('!') or operator.startswith('not '):
bool_op = 'AND'
else:
bool_op = 'OR'
domain = [
bool_op,
('main_guest', operator, value),
('registration_card', operator, value),
('product.name', operator, value),
('party.name', operator, value),
]
return domain
@classmethod
@ModelView.button
def check_in(cls, records):
@ -1462,11 +1478,6 @@ class OperationMaintenance(Workflow, ModelSQL, ModelView):
},
})
@classmethod
def trigger_create(cls, records):
for mant in records:
mant.create_operation()
@staticmethod
def default_kind():
return 'maintenance'
@ -1493,35 +1504,14 @@ class OperationMaintenance(Workflow, ModelSQL, ModelView):
@Workflow.transition('confirmed')
def confirm(cls, records):
for mant in records:
mant.update_operation({'state': 'confirmed'})
pass
@classmethod
@ModelView.button
@Workflow.transition('finished')
def finish(cls, records):
for mant in records:
mant.update_operation({'state': 'finished'})
def delete_operation(self):
Operation = Pool().get('hotel.operation')
Operation.delete([self.operation])
def create_operation(self):
Operation = Pool().get('hotel.operation')
values = {
'kind': 'maintenance',
'room': self.room,
'start_date': self.start_date,
'end_date': self.end_date,
'state': self.state,
'origin': str(self)
}
operation, = Operation.create([values])
self.write([self], {'operation': operation.id})
def update_operation(self, values):
Operation = Pool().get('hotel.operation')
Operation.write([self.operation], values)
pass
@classmethod
def write(cls, records, values):
@ -1788,13 +1778,13 @@ class ChangeRoomStart(ModelView):
class ChangeRoom(Wizard):
'Change Room'
__name__ = 'hotel.operation.change_room'
__name__ = 'hotel.folio.change_room'
"""
this is the wizard that allows the front desk employee to transfer
original room, and create a new operation occupany.
"""
start = StateView('hotel.operation.change_room.ask',
'hotel.operation_change_room_view_form', [
start = StateView('hotel.folio.change_room.ask',
'hotel.folio_change_room_view_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Change', 'change', 'tryton-ok'),
]
@ -1803,9 +1793,9 @@ class ChangeRoom(Wizard):
def transition_change(self):
pool = Pool()
Operation = pool.get('hotel.operation')
Folio = pool.get('hotel.folio')
FolioCharge = pool.get('hotel.folio.charge')
operation = Operation(Transaction().context.get('active_id'))
operation = Folio(Transaction().context.get('active_id'))
new_operation = {
'reference': operation.reference,
@ -1824,26 +1814,26 @@ class ChangeRoom(Wizard):
'lines': []
}
lines_to_transfer = []
_operation, = Operation.create([new_operation])
if self.start.tranfer_charges:
for line in operation.lines:
if line.state is None:
lines_to_transfer.append(line)
if lines_to_transfer:
FolioCharge.write([lines_to_transfer], {'operation': _operation.id})
operation.end_date = self.start.from_date
operation.state = 'closed'
operation.target = _operation.id
operation.save()
# _operation, = Operation.create([new_operation])
# if self.start.tranfer_charges:
# for line in operation.lines:
# if line.state is None:
# lines_to_transfer.append(line)
#
# if lines_to_transfer:
# FolioCharge.write([lines_to_transfer], {'operation': _operation.id})
#
# operation.end_date = self.start.from_date
# operation.state = 'closed'
# operation.target = _operation.id
# operation.save()
return 'end'
class TransferOperationStart(ModelView):
'Transfer Operation'
__name__ = 'hotel.operation.transfer_operation.ask'
operation = fields.Many2One('hotel.operation', 'Operation',
__name__ = 'hotel.folio.transfer_operation.ask'
folio = fields.Many2One('hotel.folio', 'Folio',
required=True, domain=[
('state', 'in', ['draft', 'open']),
])
@ -1856,13 +1846,13 @@ class TransferOperationStart(ModelView):
class TransferOperation(Wizard):
'Transfer Operation'
__name__ = 'hotel.operation.transfer_operation'
__name__ = 'hotel.folio.transfer_operation'
"""
this is the wizard that allows the front desk employee to transfer
original room, and create a new operation occupany.
"""
start = StateView('hotel.operation.transfer_operation.ask',
'hotel.operation_transfer_operation_view_form', [
start = StateView('hotel.folio.transfer_operation.ask',
'hotel.folio_transfer_operation_view_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Transfer', 'transfer', 'tryton-ok'),
]
@ -1875,12 +1865,12 @@ class TransferOperation(Wizard):
def transition_transfer(self):
pool = Pool()
Operation = pool.get('hotel.operation')
Operation = pool.get('hotel.folio')
FolioCharge = pool.get('hotel.folio.charge')
current_op = Operation(Transaction().context.get('active_id'))
target_op = self.start.operation
target_op = self.start.folio
if target_op.id == current_op.id:
raise AccessError(gettext('hotel.msg_operation_current'))
raise AccessError(gettext('hotel.msg_folio_current'))
lines_to_transfer = []
if self.start.tranfer_charges:
@ -1902,16 +1892,16 @@ class TransferOperation(Wizard):
class TransferChargeStart(ModelView):
'Transfer Charge'
__name__ = 'hotel.operation.transfer_charge.ask'
operation = fields.Many2One('hotel.operation', 'Operation',
__name__ = 'hotel.folio.transfer_charge.ask'
folio = fields.Many2One('hotel.folio', 'Operation',
required=True, domain=[('state', '=', 'check_in')])
class TransferCharge(Wizard):
'Transfer Operation'
__name__ = 'hotel.operation.transfer_charge'
start = StateView('hotel.operation.transfer_charge.ask',
'hotel.operation_transfer_charge_view_form', [
__name__ = 'hotel.folio.transfer_charge'
start = StateView('hotel.folio.transfer_charge.ask',
'hotel.folio_transfer_charge_view_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Transfer', 'transfer', 'tryton-ok'),
]
@ -1938,55 +1928,55 @@ class OperationByConsumerReport(Report):
def get_context(cls, records, header, data):
report_context = super().get_context(records, header, data)
pool = Pool()
Operation = pool.get('hotel.operation')
Folio = pool.get('hotel.folio')
user = pool.get('res.user')(Transaction().user)
consumer_lines = []
total_amount = 0
if records:
line = records[0]
operation = Operation(line.operation.id)
total_amount = operation.room_amount
for l in operation.lines:
folio = Folio(line.folio.id)
total_amount = folio.room_amount
for l in folio.lines:
if l.invoice_to.id == line.invoice_to.id:
consumer_lines.append(l)
total_amount += l.amount
setattr(operation, 'lines', consumer_lines)
setattr(operation, 'total_amount', total_amount)
setattr(folio, 'lines', consumer_lines)
setattr(folio, 'total_amount', total_amount)
report_context['records'] = [operation]
report_context['records'] = [folio]
report_context['company'] = user.company
return report_context
class OperationBill(Wizard):
'Operation Bill'
__name__ = 'hotel.operation.bill'
__name__ = 'hotel.folio.bill'
start_state = 'create_bill'
create_bill = StateTransition()
def transition_create_bill(self):
Operation = Pool().get('hotel.operation')
Folio = Pool().get('hotel.folio')
ids = Transaction().context['active_ids']
operations = Operation.browse(ids)
Operation.bill(operations)
folios = Folio.browse(ids)
Folio.bill(folios)
return 'end'
class OperationVoucher(ModelSQL):
'Operation - Voucher'
__name__ = 'hotel.operation-account.voucher'
_table = 'operation_vouchers_rel'
operation = fields.Many2One('hotel.operation', 'Operation',
__name__ = 'hotel.folio-account.voucher'
_table = 'folio_vouchers_rel'
folio = fields.Many2One('hotel.folio', 'Folio',
ondelete='CASCADE', select=True, required=True)
voucher = fields.Many2One('account.voucher', 'Voucher', select=True,
domain=[('voucher_type', '=', 'receipt')], ondelete='RESTRICT',
required=True)
@classmethod
def set_voucher_origin(cls, voucher_id, operation_id):
def set_voucher_origin(cls, voucher_id, folio_id):
cls.create([{
'voucher': voucher_id,
'operation': operation_id,
'folio': folio_id,
}])
@ -2029,7 +2019,7 @@ class StatisticsByMonthReport(Report):
@classmethod
def get_context(cls, records, header, data):
report_context = super().get_context(records, header, data)
Operation = Pool().get('hotel.operation')
Operation = Pool().get('hotel.folio')
Period = Pool().get('account.period')
Company = Pool().get('company.company')
Rooms = Pool().get('hotel.room')
@ -2068,7 +2058,7 @@ class StatisticsByMonthReport(Report):
reason_other = []
reason_other_foreign = []
total_guests = []
operations = Operation.search(['OR',
folios = Operation.search(['OR',
[
('start_date', '>=', period.start_date),
('start_date', '<=', period.end_date),

View File

@ -27,6 +27,68 @@ this repository contains the full copyright notices and license terms. -->
<field name="action" ref="report_folio"/>
</record>
<record model="ir.ui.view" id="board_folio_view_tree">
<field name="model">hotel.folio</field>
<field name="type">tree</field>
<field name="name">board_folio_tree</field>
</record>
<record model="ir.ui.view" id="board_folio_view_form">
<field name="model">hotel.folio</field>
<field name="type">form</field>
<field name="name">board_folio_form</field>
</record>
<record model="ir.action.act_window" id="act_board_folio_view">
<field name="name">Board Folios</field>
<field name="res_model">hotel.folio</field>
<field name="search_value"
eval="[('create_date', '>=', DateTime(hour=0, minute=0, second=0, microsecond=0, delta_years=-1))]"
pyson="1"/>
</record>
<record model="ir.action.act_window.view" id="act_hotel_board_folio_tree_view">
<field name="sequence" eval="1"/>
<field name="view" ref="board_folio_view_tree"/>
<field name="act_window" ref="act_board_folio_view"/>
</record>
<record model="ir.action.act_window.view" id="act_hotel_board_folio_form_view">
<field name="sequence" eval="2"/>
<field name="view" ref="board_folio_view_form"/>
<field name="act_window" ref="act_board_folio_view"/>
</record>
<menuitem parent="menu_booking_form" sequence="30"
action="act_board_folio_view" id="menu_hotel_board_folio"/>
<record model="ir.action.act_window.domain" id="act_guest_moves_form_domain_arriving_today">
<field name="name">Arriving Today</field>
<field name="sequence" eval="50"/>
<field name="domain" eval="[('arrival_date', '=', Date())]" pyson="1"/>
<field name="act_window" ref="act_board_folio_view"/>
</record>
<record model="ir.action.act_window.domain" id="act_guest_moves_form_domain_leaving_today">
<field name="name">Leaving Today</field>
<field name="sequence" eval="70"/>
<field name="domain" eval="[
('departure_date', '=', Date()),
]" pyson="1"/>
<field name="act_window" ref="act_board_folio_view"/>
</record>
<record model="ir.action.act_window.domain" id="act_guest_moves_form_domain_no_show_today">
<field name="name">No Show Yesterday</field>
<field name="sequence" eval="90"/>
<field name="domain" eval="[
('arrival_date', '=', Date()),
('booking.registration_state', 'in', ['no_show']),
]" pyson="1"/>
<field name="act_window" ref="act_board_folio_view"/>
</record>
<record model="ir.action.act_window.domain" id="act_guest_moves_form_domain_all">
<field name="name">All</field>
<field name="sequence" eval="90"/>
<field name="domain" eval="[
('arrival_date', '>=', Date()),
]" pyson="1"/>
<field name="act_window" ref="act_board_folio_view"/>
</record>
<!-- <record model="ir.ui.view" id="operation_view_tree">
<field name="model">hotel.operation</field>
<field name="type">tree</field>

View File

@ -14,20 +14,16 @@ this repository contains the full copyright notices and license terms. -->
<field name="booking_date"/>
<label name="price_list"/>
<field name="price_list" widget="selection"/>
<label name="payment_term"/>
<field name="payment_term"/>
<label name="media"/>
<field name="media"/>
<label name="party_seller"/>
<field name="party_seller" widget="selection"/>
<label name="plan"/>
<field name="plan"/>
<label name="breakfast_included"/>
<field name="breakfast_included"/>
<label name="taxes_exception"/>
<field name="taxes_exception"/>
<!-- <label name="breakfast_included"/>
<field name="breakfast_included"/> -->
<button name="select_rooms" string="Select Rooms"
icon="tryton-open" colspan="2"/>
<button name="pay_advance" string="Add Advance"
icon="tryton-open" colspan="2"/>
<button name="send_email" string="Send Email"
icon="tryton-open" colspan="2"/>
<notebook colspan="6">
@ -83,36 +79,30 @@ this repository contains the full copyright notices and license terms. -->
<field name="vouchers" colspan="4"/>
</page>
</notebook>
<group col="7" colspan="6" id="advances">
<button name="pay_advance" string="Add Advance" icon="tryton-open"
colspan="2"/>
<label name="total_advance"/>
<field name="total_advance"/>
<button name="no_show" string="No Show" icon="tryton-cancel"/>
<group col="4" colspan="4" id="buttons">
<label name="payment_term"/>
<field name="payment_term" widget="selection"/>
<label name="media"/>
<field name="media"/>
<label name="taxes_exception"/>
<field name="taxes_exception"/>
<label name="state"/>
<field name="state"/>
<button name="cancel" string="Cancel" icon="tryton-cancel"/>
<button name="not_show" string="Not Show" icon="tryton-cancel"/>
<button name="offer" string="Offer" icon="tryton-clear"/>
<button name="confirm" string="Confirm" icon="tryton-forward"/>
</group>
<group col="8" colspan="6" id="amounts">
<group col="2" colspan="2" id="amounts">
<label name="untaxed_amount"/>
<field name="untaxed_amount"/>
<label name="tax_amount"/>
<field name="tax_amount"/>
<label name="total_amount"/>
<field name="total_amount"/>
<label name="total_advance"/>
<field name="total_advance"/>
<label name="pending_to_pay"/>
<field name="pending_to_pay"/>
</group>
<group col="4" colspan="6" id="buttons">
<button name="offer" string="Offer"
icon="tryton-clear"/>
<button name="cancel" string="Cancel"
icon="tryton-cancel"/>
<button name="not_show" string="Not Show"
icon="tryton-cancel"/>
<button name="confirm" string="Confirm"
icon="tryton-forward"/>
<!-- <label name="satisfaction"/>
<field name="satisfaction"/> -->
</group>
</form>