trytonpsk-hotel/party.py

173 lines
5.8 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, ModelView
from trytond.wizard import Wizard, StateView, Button, StateTransition, StateReport
from trytond.transaction import Transaction
__all__ = ['Party', 'CreateGuest', 'CreateGuestStart']
TYPE = [
('', ''),
('service_acomplished', 'Service Acomplished'),
('direct', 'Direct'),
('implicit', 'Implicit'),
]
TYPE_DOCUMENT = [
('', ''),
('11', 'Civil Registry of Birth'),
('12', 'Identity Card'),
('13', 'Citizenship Card'),
('21', 'Tarjeta de Extranjeria'),
('22', 'Alien Registration Card'),
('31', 'NIT'),
('41', 'Passport'),
('42', 'Type of Foreign Document'),
('43', 'Without Foreign Identification or for use as defined by the DIAN'),
]
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 CreateGuestStart(ModelView):
'Create Party to Guest Start'
__name__ = 'hotel.party.guest.start'
full_name = fields.Char('Name')
first_name = fields.Char('First Name')
second_name = fields.Char('Second Name')
first_family_name = fields.Char('First Family Name')
second_family_name = fields.Char('Second Family Name')
type_document = fields.Selection(TYPE_DOCUMENT, 'Type Document')
id_number = fields.Char('Id Number')
type_document = fields.Selection([
('12', 'Tarjeta de Identidad'),
('13', 'Cedula de Ciudadania'),
('21', 'Tarjeta de Extranjeria'),
('22', 'Cedula de Extranjeria'),
('41', 'Pasaporte'),
], 'Document Type')
mobile = fields.Char('Mobile', select=True)
email = fields.Char('Email', select=True)
birthday = fields.Date('Birthday', select=True)
sex = fields.Selection([
('female', 'Female'),
('male', 'Male'),
('', ''),
], 'Sex')
type_person = fields.Selection([
('persona_natural', 'Persona Natural'),
('persona_juridica', 'Persona Juridica'),
], 'Type Person')
@fields.depends('full_name', 'first_name', 'second_name',
'first_family_name', 'second_family_name','type_person')
def on_change_full_name(self):
second_family_name = None
first_family_name = None
second_name = None
first_name = None
if self.full_name and self.type_person == 'persona_natural':
names = self.full_name.split(' ')
first_name = names[0]
second_family_name = names[-1]
if len(names) > 1:
first_family_name = names[-2]
if len(names) == 2:
second_family_name = None
first_family_name = names[1]
elif len(names) == 5:
second_name = names[1] + ' ' + names[2]
elif len(names) == 4:
second_name = names[1]
self.second_family_name = second_family_name
self.first_family_name = first_family_name
self.second_name = second_name
self.first_name = first_name
@staticmethod
def default_sex():
return 'male'
@staticmethod
def default_type_person():
return 'persona_natural'
@staticmethod
def default_type_document():
return '13'
class CreateGuest(Wizard):
'Create Party to Guest'
__name__ = 'hotel.party.guest'
start = StateView('hotel.party.guest.start',
'hotel.view_party_guest', [
Button('Exit', 'end', 'tryton-cancel'),
Button('Create', 'create_', 'tryton-ok', default=True),
]
)
create_ = StateTransition()
@classmethod
def __setup__(cls):
super(CreateGuest, cls).__setup__()
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:
self.get_message(('El usuario %s ya existe')%(self.start.name))
else:
party, = Party.create([{
'name': self.start.name,
'id_number': self.start.id_number,
'type_document': self.start.type_document,
'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', [
{'type': 'email', 'value': self.start.email},
{'type': 'mobile', 'value': self.start.mobile},
])
]
}])
party_id = party.id
Booking.write([record], {'party': party_id})
return 'end'
def get_message(self, message):
self.raise_user_error(message)