From d671b5204bb2f003ad93402af01a7860db74084f Mon Sep 17 00:00:00 2001 From: Oscar Date: Mon, 13 Sep 2021 07:13:11 -0500 Subject: [PATCH] Fix create guest --- __init__.py | 2 +- booking.py | 8 +- booking.xml | 11 ++ operation.py | 1 + party.py | 177 ++++++++---------- party.xml | 10 - tryton.cfg | 2 +- view/booking_form.xml | 14 +- view/booking_tree.xml | 1 + ...{party_guest.xml => create_guest_form.xml} | 10 +- 10 files changed, 109 insertions(+), 127 deletions(-) rename view/{party_guest.xml => create_guest_form.xml} (84%) diff --git a/__init__.py b/__init__.py index 7609c0a..04ce86b 100644 --- a/__init__.py +++ b/__init__.py @@ -46,7 +46,7 @@ def register(): channel.ChannelTax, booking.Guest, booking.SelectRoomsAsk, - party.CreateGuestStart, + # party.CreateGuestStart, booking.BookingVoucher, booking.RoomsOccupancyStart, booking.BookingForecastStart, diff --git a/booking.py b/booking.py index f852d89..12d5304 100644 --- a/booking.py +++ b/booking.py @@ -92,7 +92,7 @@ MEDIA = [ ] PLAN = [ - ('', ''), + ('no_breakfast', 'No Breakfast'), ('all_inclusive', 'All Inclusive'), ('bed_breakfast', 'Bed & Breakfast'), ('full_american', 'Full American'), @@ -242,7 +242,7 @@ class Booking(Workflow, ModelSQL, ModelView): 'invisible': Eval('state') != 'offer', }, 'create_guest': { - + 'invisible': Eval('state') != 'offer', }, 'cancel': { 'invisible': Eval('state').in_(['cancel', '']) and @@ -864,6 +864,7 @@ class BookingLine(ModelSQL, ModelView): # if not accommodation: # kind = 'statement' + breakfast_included = line.booking.plan != 'no_breakfast' or False values = { 'kind': kind, 'accommodation': accommodation, @@ -877,6 +878,7 @@ class BookingLine(ModelSQL, ModelView): 'complementary': line.booking.complementary, 'type_complementary': line.booking.type_complementary, 'taxes_exception': line.booking.taxes_exception, + 'breakfast_included': breakfast_included, } if line.room: values['room'] = line.room.id @@ -1484,7 +1486,7 @@ class GuestsListReport(Report): occupancy_rate = round(_rooms_occupied / num_rooms, 2) else: occupancy_rate = 0 - print('operations ...', operations) + operations_ = [] for op in operations: for guest in op.guests: diff --git a/booking.xml b/booking.xml index d443c65..48de0ec 100644 --- a/booking.xml +++ b/booking.xml @@ -371,5 +371,16 @@ this repository contains the full copyright notices and license terms. --> + + Create Guest + hotel.party.guest + hotel.booking + + + party.party + form + create_guest_form + + diff --git a/operation.py b/operation.py index 0b7ee3f..a6f1f8d 100644 --- a/operation.py +++ b/operation.py @@ -100,6 +100,7 @@ class Operation(Workflow, ModelSQL, ModelView): unit_price_w_tax = fields.Function(fields.Numeric('Unit Price With Tax'), 'get_unit_price_w_tax') 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) # sale = fields.Function(fields.Many2One('sale.sale', 'Sale'), 'get_sale') sale_line = fields.Many2One('sale.line', 'Sale Line', select=True) diff --git a/party.py b/party.py index 5ab9422..e01abd4 100644 --- a/party.py +++ b/party.py @@ -2,10 +2,10 @@ #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.model import fields from trytond.wizard import Wizard, StateView, Button, StateTransition from trytond.transaction import Transaction -from trytond.model.exceptions import AccessError +from trytond.exceptions import UserError from trytond.i18n import gettext TYPE = [ @@ -15,19 +15,6 @@ TYPE = [ ('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' @@ -49,79 +36,79 @@ class Party(metaclass=PoolMeta): 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 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', + start = StateView('party.party', 'hotel.view_party_guest', [ Button('Exit', 'end', 'tryton-cancel'), Button('Create', 'create_', 'tryton-ok', default=True), @@ -129,10 +116,6 @@ class CreateGuest(Wizard): ) create_ = StateTransition() - @classmethod - def __setup__(cls): - super(CreateGuest, cls).__setup__() - def transition_create_(self): pool = Pool() Party = pool.get('party.party') @@ -143,10 +126,16 @@ class CreateGuest(Wizard): ('id_number', '=', self.start.id_number) ]) if parties: - self.get_message(('El usuario %s ya existe')%(self.start.name)) + 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 + }) + party, = Party.create([{ - 'name': self.start.full_name, + 'name': self.start.name, 'id_number': self.start.id_number, 'type_document': self.start.type_document, 'birthday': self.start.birthday, @@ -155,16 +144,8 @@ class CreateGuest(Wizard): '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}, - ]) - ] + 'contact_mechanisms': [('create', contact_mechanisms)] }]) party_id = party.id Booking.write([record], {'party': party_id}) return 'end' - - def get_message(self, message): - raise AccessError(gettext('hotel.msg_error', s=message)) diff --git a/party.xml b/party.xml index 1e6f7b1..b36207d 100644 --- a/party.xml +++ b/party.xml @@ -3,16 +3,6 @@ this repository contains the full copyright notices and license terms. --> - - Create Party Guest - hotel.party.guest - hotel.party - - - hotel.party.guest.start - form - party_guest - party.party diff --git a/tryton.cfg b/tryton.cfg index db36b22..7a46426 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -1,5 +1,5 @@ [tryton] -version=6.0.2 +version=6.0.3 depends: party company diff --git a/view/booking_form.xml b/view/booking_form.xml index 3bdbd44..8baf9ec 100644 --- a/view/booking_form.xml +++ b/view/booking_form.xml @@ -26,10 +26,12 @@ this repository contains the full copyright notices and license terms. -->