Fix create guest

This commit is contained in:
Oscar 2021-09-13 07:13:11 -05:00
parent c202ba6ca8
commit d671b5204b
10 changed files with 109 additions and 127 deletions

View File

@ -46,7 +46,7 @@ def register():
channel.ChannelTax, channel.ChannelTax,
booking.Guest, booking.Guest,
booking.SelectRoomsAsk, booking.SelectRoomsAsk,
party.CreateGuestStart, # party.CreateGuestStart,
booking.BookingVoucher, booking.BookingVoucher,
booking.RoomsOccupancyStart, booking.RoomsOccupancyStart,
booking.BookingForecastStart, booking.BookingForecastStart,

View File

@ -92,7 +92,7 @@ MEDIA = [
] ]
PLAN = [ PLAN = [
('', ''), ('no_breakfast', 'No Breakfast'),
('all_inclusive', 'All Inclusive'), ('all_inclusive', 'All Inclusive'),
('bed_breakfast', 'Bed & Breakfast'), ('bed_breakfast', 'Bed & Breakfast'),
('full_american', 'Full American'), ('full_american', 'Full American'),
@ -242,7 +242,7 @@ class Booking(Workflow, ModelSQL, ModelView):
'invisible': Eval('state') != 'offer', 'invisible': Eval('state') != 'offer',
}, },
'create_guest': { 'create_guest': {
'invisible': Eval('state') != 'offer',
}, },
'cancel': { 'cancel': {
'invisible': Eval('state').in_(['cancel', '']) and 'invisible': Eval('state').in_(['cancel', '']) and
@ -864,6 +864,7 @@ class BookingLine(ModelSQL, ModelView):
# if not accommodation: # if not accommodation:
# kind = 'statement' # kind = 'statement'
breakfast_included = line.booking.plan != 'no_breakfast' or False
values = { values = {
'kind': kind, 'kind': kind,
'accommodation': accommodation, 'accommodation': accommodation,
@ -877,6 +878,7 @@ class BookingLine(ModelSQL, ModelView):
'complementary': line.booking.complementary, 'complementary': line.booking.complementary,
'type_complementary': line.booking.type_complementary, 'type_complementary': line.booking.type_complementary,
'taxes_exception': line.booking.taxes_exception, 'taxes_exception': line.booking.taxes_exception,
'breakfast_included': breakfast_included,
} }
if line.room: if line.room:
values['room'] = line.room.id values['room'] = line.room.id
@ -1484,7 +1486,7 @@ class GuestsListReport(Report):
occupancy_rate = round(_rooms_occupied / num_rooms, 2) occupancy_rate = round(_rooms_occupied / num_rooms, 2)
else: else:
occupancy_rate = 0 occupancy_rate = 0
print('operations ...', operations)
operations_ = [] operations_ = []
for op in operations: for op in operations:
for guest in op.guests: for guest in op.guests:

View File

@ -371,5 +371,16 @@ this repository contains the full copyright notices and license terms. -->
<menuitem parent="hotel.menu_reporting" id="menu_hotel_booking_daily" <menuitem parent="hotel.menu_reporting" id="menu_hotel_booking_daily"
action="wizard_print_booking_daily"/> action="wizard_print_booking_daily"/>
<record model="ir.action.wizard" id="wizard_party_guest">
<field name="name">Create Guest</field>
<field name="wiz_name">hotel.party.guest</field>
<field name="model">hotel.booking</field>
</record>
<record model="ir.ui.view" id="view_party_guest">
<field name="model">party.party</field>
<field name="type">form</field>
<field name="name">create_guest_form</field>
</record>
</data> </data>
</tryton> </tryton>

View File

@ -100,6 +100,7 @@ class Operation(Workflow, ModelSQL, ModelView):
unit_price_w_tax = fields.Function(fields.Numeric('Unit Price With Tax'), unit_price_w_tax = fields.Function(fields.Numeric('Unit Price With Tax'),
'get_unit_price_w_tax') 'get_unit_price_w_tax')
taxes_exception = fields.Boolean('Taxes Exception', states=STATES_OP) taxes_exception = fields.Boolean('Taxes Exception', states=STATES_OP)
breakfast_included = fields.Boolean('Breakfast Included', states=STATES_OP)
add_default_charges = fields.Boolean('Add Default Charges', states=STATES_OP) add_default_charges = fields.Boolean('Add Default Charges', states=STATES_OP)
# sale = fields.Function(fields.Many2One('sale.sale', 'Sale'), 'get_sale') # sale = fields.Function(fields.Many2One('sale.sale', 'Sale'), 'get_sale')
sale_line = fields.Many2One('sale.line', 'Sale Line', select=True) sale_line = fields.Many2One('sale.line', 'Sale Line', select=True)

177
party.py
View File

@ -2,10 +2,10 @@
#the top level of this repository contains the full copyright notices #the top level of this repository contains the full copyright notices
#and license terms. #and license terms.
from trytond.pool import PoolMeta, Pool from trytond.pool import PoolMeta, Pool
from trytond.model import fields, ModelView from trytond.model import fields
from trytond.wizard import Wizard, StateView, Button, StateTransition from trytond.wizard import Wizard, StateView, Button, StateTransition
from trytond.transaction import Transaction from trytond.transaction import Transaction
from trytond.model.exceptions import AccessError from trytond.exceptions import UserError
from trytond.i18n import gettext from trytond.i18n import gettext
TYPE = [ TYPE = [
@ -15,19 +15,6 @@ TYPE = [
('implicit', 'Implicit'), ('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): class Party(metaclass=PoolMeta):
__name__ = 'party.party' __name__ = 'party.party'
@ -49,79 +36,79 @@ class Party(metaclass=PoolMeta):
visa_date = fields.Date('Visa Date') visa_date = fields.Date('Visa Date')
class CreateGuestStart(ModelView): # class CreateGuestStart(ModelView):
'Create Party to Guest Start' # 'Create Party to Guest Start'
__name__ = 'hotel.party.guest.start' # __name__ = 'hotel.party.guest.start'
full_name = fields.Char('Name') # full_name = fields.Char('Name')
first_name = fields.Char('First Name') # first_name = fields.Char('First Name')
second_name = fields.Char('Second Name') # second_name = fields.Char('Second Name')
first_family_name = fields.Char('First Family Name') # first_family_name = fields.Char('First Family Name')
second_family_name = fields.Char('Second Family Name') # second_family_name = fields.Char('Second Family Name')
type_document = fields.Selection(TYPE_DOCUMENT, 'Type Document') # type_document = fields.Selection(TYPE_DOCUMENT, 'Type Document')
id_number = fields.Char('Id Number') # id_number = fields.Char('Id Number')
type_document = fields.Selection([ # type_document = fields.Selection([
('12', 'Tarjeta de Identidad'), # ('12', 'Tarjeta de Identidad'),
('13', 'Cedula de Ciudadania'), # ('13', 'Cedula de Ciudadania'),
('21', 'Tarjeta de Extranjeria'), # ('21', 'Tarjeta de Extranjeria'),
('22', 'Cedula de Extranjeria'), # ('22', 'Cedula de Extranjeria'),
('41', 'Pasaporte'), # ('41', 'Pasaporte'),
], 'Document Type') # ], 'Document Type')
mobile = fields.Char('Mobile', select=True) # mobile = fields.Char('Mobile', select=True)
email = fields.Char('Email', select=True) # email = fields.Char('Email', select=True)
birthday = fields.Date('Birthday', select=True) # birthday = fields.Date('Birthday', select=True)
sex = fields.Selection([ # sex = fields.Selection([
('female', 'Female'), # ('female', 'Female'),
('male', 'Male'), # ('male', 'Male'),
('', ''), # ('', ''),
], 'Sex') # ], 'Sex')
type_person = fields.Selection([ # type_person = fields.Selection([
('persona_natural', 'Persona Natural'), # ('persona_natural', 'Persona Natural'),
('persona_juridica', 'Persona Juridica'), # ('persona_juridica', 'Persona Juridica'),
], 'Type Person') # ], 'Type Person')
#
@fields.depends('full_name', 'first_name', 'second_name', # @fields.depends('full_name', 'first_name', 'second_name',
'first_family_name', 'second_family_name','type_person') # 'first_family_name', 'second_family_name','type_person')
def on_change_full_name(self): # def on_change_full_name(self):
second_family_name = None # second_family_name = None
first_family_name = None # first_family_name = None
second_name = None # second_name = None
first_name = None # first_name = None
if self.full_name and self.type_person == 'persona_natural': # if self.full_name and self.type_person == 'persona_natural':
names = self.full_name.split(' ') # names = self.full_name.split(' ')
first_name = names[0] # first_name = names[0]
second_family_name = names[-1] # second_family_name = names[-1]
if len(names) > 1: # if len(names) > 1:
first_family_name = names[-2] # first_family_name = names[-2]
if len(names) == 2: # if len(names) == 2:
second_family_name = None # second_family_name = None
first_family_name = names[1] # first_family_name = names[1]
elif len(names) == 5: # elif len(names) == 5:
second_name = names[1] + ' ' + names[2] # second_name = names[1] + ' ' + names[2]
elif len(names) == 4: # elif len(names) == 4:
second_name = names[1] # second_name = names[1]
#
self.second_family_name = second_family_name # self.second_family_name = second_family_name
self.first_family_name = first_family_name # self.first_family_name = first_family_name
self.second_name = second_name # self.second_name = second_name
self.first_name = first_name # self.first_name = first_name
#
@staticmethod # @staticmethod
def default_sex(): # def default_sex():
return 'male' # return 'male'
#
@staticmethod # @staticmethod
def default_type_person(): # def default_type_person():
return 'persona_natural' # return 'persona_natural'
#
@staticmethod # @staticmethod
def default_type_document(): # def default_type_document():
return '13' # return '13'
class CreateGuest(Wizard): class CreateGuest(Wizard):
'Create Party to Guest' 'Create Party to Guest'
__name__ = 'hotel.party.guest' __name__ = 'hotel.party.guest'
start = StateView('hotel.party.guest.start', start = StateView('party.party',
'hotel.view_party_guest', [ 'hotel.view_party_guest', [
Button('Exit', 'end', 'tryton-cancel'), Button('Exit', 'end', 'tryton-cancel'),
Button('Create', 'create_', 'tryton-ok', default=True), Button('Create', 'create_', 'tryton-ok', default=True),
@ -129,10 +116,6 @@ class CreateGuest(Wizard):
) )
create_ = StateTransition() create_ = StateTransition()
@classmethod
def __setup__(cls):
super(CreateGuest, cls).__setup__()
def transition_create_(self): def transition_create_(self):
pool = Pool() pool = Pool()
Party = pool.get('party.party') Party = pool.get('party.party')
@ -143,10 +126,16 @@ class CreateGuest(Wizard):
('id_number', '=', self.start.id_number) ('id_number', '=', self.start.id_number)
]) ])
if parties: if parties:
self.get_message(('El usuario %s ya existe')%(self.start.name)) raise UserError(gettext('El usuario ya existe!'))
else: else:
contact_mechanisms = []
for contact in self.start.contact_mechanisms:
contact_mechanisms.append({
'type': contact.type, 'value': contact.value
})
party, = Party.create([{ party, = Party.create([{
'name': self.start.full_name, 'name': self.start.name,
'id_number': self.start.id_number, 'id_number': self.start.id_number,
'type_document': self.start.type_document, 'type_document': self.start.type_document,
'birthday': self.start.birthday, 'birthday': self.start.birthday,
@ -155,16 +144,8 @@ class CreateGuest(Wizard):
'second_name': self.start.second_name, 'second_name': self.start.second_name,
'first_family_name': self.start.first_family_name, 'first_family_name': self.start.first_family_name,
'second_family_name': self.start.second_family_name, 'second_family_name': self.start.second_family_name,
'contact_mechanisms': [ 'contact_mechanisms': [('create', contact_mechanisms)]
('create', [
{'type': 'email', 'value': self.start.email},
{'type': 'mobile', 'value': self.start.mobile},
])
]
}]) }])
party_id = party.id party_id = party.id
Booking.write([record], {'party': party_id}) Booking.write([record], {'party': party_id})
return 'end' return 'end'
def get_message(self, message):
raise AccessError(gettext('hotel.msg_error', s=message))

View File

@ -3,16 +3,6 @@
this repository contains the full copyright notices and license terms. --> this repository contains the full copyright notices and license terms. -->
<tryton> <tryton>
<data> <data>
<record model="ir.action.wizard" id="wizard_party_guest">
<field name="name">Create Party Guest</field>
<field name="wiz_name">hotel.party.guest</field>
<field name="model">hotel.party</field>
</record>
<record model="ir.ui.view" id="view_party_guest">
<field name="model">hotel.party.guest.start</field>
<field name="type">form</field>
<field name="name">party_guest</field>
</record>
<record model="ir.ui.view" id="party_view_form"> <record model="ir.ui.view" id="party_view_form">
<field name="model">party.party</field> <field name="model">party.party</field>
<field name="inherit" ref="party.party_view_form"/> <field name="inherit" ref="party.party_view_form"/>

View File

@ -1,5 +1,5 @@
[tryton] [tryton]
version=6.0.2 version=6.0.3
depends: depends:
party party
company company

View File

@ -26,10 +26,12 @@ this repository contains the full copyright notices and license terms. -->
<field name="party_seller" widget="selection"/> <field name="party_seller" widget="selection"/>
<label name="taxes_exception"/> <label name="taxes_exception"/>
<field name="taxes_exception"/> <field name="taxes_exception"/>
<label name="plan"/>
<field name="plan"/>
<button name="select_rooms" string="Select Rooms"
icon="tryton-open"/>
<button name="send_email" string="Send Email" <button name="send_email" string="Send Email"
icon="tryton-open" colspan="2"/> icon="tryton-open" colspan="2"/>
<button name="select_rooms" string="Select Rooms"
icon="tryton-open" colspan="2"/>
<notebook colspan="6"> <notebook colspan="6">
<page string="Lines" id="lines"> <page string="Lines" id="lines">
<field name="lines" colspan="4" <field name="lines" colspan="4"
@ -76,15 +78,11 @@ this repository contains the full copyright notices and license terms. -->
<label name="guarantee"/> <label name="guarantee"/>
<field name="guarantee"/> <field name="guarantee"/>
<newline/> <newline/>
<separator id="marketing_guest" string="Guest information" colspan="4"/>
<label name="plan"/>
<field name="plan"/>
<label name="segment"/>
<field name="segment"/>
<newline/>
<separator id="marketing_advertisement" string="Advertisement information" colspan="4"/> <separator id="marketing_advertisement" string="Advertisement information" colspan="4"/>
<label name="source_contact"/> <label name="source_contact"/>
<field name="source_contact"/> <field name="source_contact"/>
<label name="segment"/>
<field name="segment"/>
</page> </page>
<page string="Advances Payments" id="vouchers"> <page string="Advances Payments" id="vouchers">
<field name="vouchers" colspan="4"/> <field name="vouchers" colspan="4"/>

View File

@ -9,5 +9,6 @@ this repository contains the full copyright notices and license terms. -->
<field name="booking_date" widget="date"/> <field name="booking_date" widget="date"/>
<field name="price_list"/> <field name="price_list"/>
<field name="total_amount"/> <field name="total_amount"/>
<field name="total_advance"/>
<field name="state"/> <field name="state"/>
</tree> </tree>

View File

@ -2,16 +2,12 @@
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of <!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. --> this repository contains the full copyright notices and license terms. -->
<form> <form>
<label name="full_name"/> <label name="name"/>
<field name="full_name"/> <field name="name"/>
<label name="type_document"/> <label name="type_document"/>
<field name="type_document"/> <field name="type_document"/>
<label name="id_number"/> <label name="id_number"/>
<field name="id_number"/> <field name="id_number"/>
<label name="mobile"/>
<field name="mobile"/>
<label name="email"/>
<field name="email"/>
<label name="birthday"/> <label name="birthday"/>
<field name="birthday"/> <field name="birthday"/>
<label name="sex"/> <label name="sex"/>
@ -30,4 +26,6 @@ this repository contains the full copyright notices and license terms. -->
<label name="second_family_name"/> <label name="second_family_name"/>
<field name="second_family_name"/> <field name="second_family_name"/>
</group> </group>
<field name="contact_mechanisms" colspan="4"
view_ids="party.contact_mechanism_view_tree_sequence"/>
</form> </form>