mirror of
https://bitbucket.org/presik/trytonpsk-hotel.git
synced 2023-12-14 07:52:52 +01:00
97 lines
3.5 KiB
Python
97 lines
3.5 KiB
Python
#This file is part of Hotel module for Tryton. The COPYRIGHT file at
|
|
#the top level of this repository contains the full copyright notices
|
|
#and license terms.
|
|
from trytond.pool import PoolMeta, Pool
|
|
from trytond.model import fields
|
|
from trytond.wizard import Wizard, StateView, Button, StateTransition
|
|
from trytond.transaction import Transaction
|
|
from trytond.exceptions import UserError
|
|
from trytond.i18n import gettext
|
|
|
|
TYPE = [
|
|
('', ''),
|
|
('service_acomplished', 'Service Acomplished'),
|
|
('direct', 'Direct'),
|
|
('implicit', 'Implicit'),
|
|
]
|
|
|
|
|
|
class Party(metaclass=PoolMeta):
|
|
__name__ = 'party.party'
|
|
'''
|
|
Party field and function aditions for channels management. Sales
|
|
commissions, taxes and price lists.
|
|
'''
|
|
sale_commission = fields.Numeric('Sales Commission %', digits=(3, 2),
|
|
help="Add the percentage of sales commission for this channel.",)
|
|
# Must be required if party is hotel channel.
|
|
# states={
|
|
# 'readonly': ~Eval('active', True),
|
|
# 'required': Bool(Eval('vat_country')),
|
|
# },
|
|
# depends=['active', 'vat_country'], size=12, select=True)
|
|
sale_commission_type = fields.Selection(TYPE, 'Sales Commission Type')
|
|
visa_category = fields.Char('Visa Category')
|
|
visa_number = fields.Char('Visa Number')
|
|
visa_date = fields.Date('Visa Date')
|
|
|
|
|
|
class CreateGuest(Wizard):
|
|
'Create Party to Guest'
|
|
__name__ = 'hotel.party.guest'
|
|
start = StateView('party.party',
|
|
'hotel.view_party_guest', [
|
|
Button('Exit', 'end', 'tryton-cancel'),
|
|
Button('Create', 'create_', 'tryton-ok', default=True),
|
|
]
|
|
)
|
|
create_ = StateTransition()
|
|
|
|
def transition_create_(self):
|
|
pool = Pool()
|
|
Party = pool.get('party.party')
|
|
Booking = pool.get('hotel.booking')
|
|
id = Transaction().context.get('active_id', False)
|
|
record = Booking(id)
|
|
parties = Party.search([
|
|
('id_number', '=', self.start.id_number)
|
|
])
|
|
if parties:
|
|
raise UserError(gettext('El usuario ya existe!'))
|
|
else:
|
|
contact_mechanisms = []
|
|
for contact in self.start.contact_mechanisms:
|
|
contact_mechanisms.append({
|
|
'type': contact.type, 'value': contact.value
|
|
})
|
|
|
|
if self.start.type_document == '31':
|
|
type_person = 'persona_juridica'
|
|
else:
|
|
type_person = 'persona_natural'
|
|
|
|
to_create = {
|
|
'name': self.start.name,
|
|
'id_number': self.start.id_number,
|
|
'type_document': self.start.type_document,
|
|
'type_person': type_person,
|
|
'birthday': self.start.birthday,
|
|
'sex': self.start.sex,
|
|
'first_name': self.start.first_name,
|
|
'second_name': self.start.second_name,
|
|
'first_family_name': self.start.first_family_name,
|
|
'second_family_name': self.start.second_family_name,
|
|
'contact_mechanisms': [('create', contact_mechanisms)],
|
|
'addresses': [('create', [{
|
|
'street': '',
|
|
}])]
|
|
}
|
|
party, = Party.create([to_create])
|
|
party_id = party.id
|
|
Booking.write([record], {'party': party_id})
|
|
if record.lines:
|
|
for folio in record.lines:
|
|
if not folio.main_guest:
|
|
folio.main_guest = party_id
|
|
folio.save()
|
|
return 'end'
|