trytonpsk-hotel/party.py

98 lines
3.5 KiB
Python
Raw Normal View History

2020-04-16 14:45:13 +02:00
#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
2021-09-13 14:13:11 +02:00
from trytond.model import fields
2021-07-21 14:56:53 +02:00
from trytond.wizard import Wizard, StateView, Button, StateTransition
from trytond.transaction import Transaction
2021-09-13 14:13:11 +02:00
from trytond.exceptions import UserError
2021-07-21 14:56:53 +02:00
from trytond.i18n import gettext
2020-04-16 14:45:13 +02:00
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'
2021-09-13 14:13:11 +02:00
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:
2021-09-13 14:13:11 +02:00
raise UserError(gettext('El usuario ya existe!'))
else:
2021-09-13 14:13:11 +02:00
contact_mechanisms = []
for contact in self.start.contact_mechanisms:
contact_mechanisms.append({
'type': contact.type, 'value': contact.value
})
2021-11-25 04:52:03 +01:00
if self.start.type_document == '31':
type_person = 'persona_juridica'
else:
type_person = 'persona_natural'
to_create = {
2021-09-13 14:13:11 +02:00
'name': self.start.name,
'id_number': self.start.id_number,
'type_document': self.start.type_document,
2021-11-25 04:52:03 +01:00
'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,
2021-11-25 04:52:03 +01:00
'contact_mechanisms': [('create', contact_mechanisms)],
'addresses': [('create', [{
'street': '',
}])]
}
party, = Party.create([to_create])
party_id = party.id
Booking.write([record], {'party': party_id})
2021-11-25 04:52:03 +01:00
if record.lines:
for folio in record.lines:
if not folio.main_guest:
folio.main_guest = party_id
folio.save()
return 'end'