This commit is contained in:
oscar alvarez 2022-05-22 01:52:05 -05:00
parent 8b04df56e1
commit 70505d0a09
10 changed files with 124 additions and 115 deletions

View File

@ -21,7 +21,6 @@ from .constants import (
TYPE_DOCUMENT TYPE_DOCUMENT
) )
STATES = { STATES = {
'readonly': Eval('state') != 'offer', 'readonly': Eval('state') != 'offer',
} }
@ -862,7 +861,7 @@ class Booking(Workflow, ModelSQL, ModelView):
for comm in self.extra_commissions: for comm in self.extra_commissions:
extras = sum(base_comm) * Decimal(comm.commission / 100) extras = sum(base_comm) * Decimal(comm.commission / 100)
res.append(extras) res.append(extras)
return sum(res) return self.currency.round(sum(res))
def send_email_to(self): def send_email_to(self):
pool = Pool() pool = Pool()
@ -1371,6 +1370,7 @@ class UpdateHolderStart(ModelView):
customer_phone = fields.Char('Customer Phone') customer_phone = fields.Char('Customer Phone')
customer_email = fields.Char('Customer Email') customer_email = fields.Char('Customer Email')
customer_type_document = fields.Selection(TYPE_DOCUMENT, 'Tipo de Documento Cliente') customer_type_document = fields.Selection(TYPE_DOCUMENT, 'Tipo de Documento Cliente')
main_guest = fields.Boolean('Main Guest')
class UpdateHolder(Wizard): class UpdateHolder(Wizard):
@ -1441,9 +1441,10 @@ class UpdateHolder(Wizard):
_party = self.start _party = self.start
rec_company = {} rec_company = {}
to_folio = {} to_folio = {}
nationality_id = _party.nationality.id if _party.nationality else None
rec = { rec = {
'name': _party.name.upper(), 'name': _party.name.upper(),
'nationality': _party.nationality.id if _party.nationality else None, 'nationality': nationality_id,
'sex': _party.sex, 'sex': _party.sex,
'birthday': _party.birthday, 'birthday': _party.birthday,
'type_document': _party.type_document, 'type_document': _party.type_document,
@ -1537,12 +1538,15 @@ class UpdateHolder(Wizard):
party, = Party.create([rec]) party, = Party.create([rec])
Booking.write([booking], {'party': party.id}) Booking.write([booking], {'party': party.id})
booking.save() booking.save()
if _party.main_guest:
for folio in booking.lines: for folio in booking.lines:
if not folio.main_guest: if not folio.main_guest:
folio.main_guest = party.id folio.main_guest = party.id
folio.save() folio.save()
break break
Guest.create([rec])
for folio in booking.lines: for folio in booking.lines:
Folio.write([folio], to_folio) Folio.write([folio], to_folio)
return 'end' return 'end'

164
folio.py
View File

@ -71,7 +71,9 @@ class Folio(ModelSQL, ModelView):
'get_unit_price_w_tax') 'get_unit_price_w_tax')
uom = fields.Many2One('product.uom', 'UOM', readonly=True) uom = fields.Many2One('product.uom', 'UOM', readonly=True)
main_guest = fields.Many2One('party.party', 'Main Guest', select=True, main_guest = fields.Many2One('party.party', 'Main Guest', select=True,
states=STATES_CHECKIN states={
'readonly': True
}
) )
contact = fields.Char('Contact', states=STATES_CHECKIN) contact = fields.Char('Contact', states=STATES_CHECKIN)
num_children = fields.Function(fields.Integer('No. Children'), num_children = fields.Function(fields.Integer('No. Children'),
@ -215,7 +217,6 @@ class Folio(ModelSQL, ModelView):
raise UserError(gettext('hotel.msg_missing_select_room')) raise UserError(gettext('hotel.msg_missing_select_room'))
rec.set_registration_number() rec.set_registration_number()
rec.check_room() rec.check_room()
rec.add_main_guest()
cls.update_room(rec.room, 'dirty') cls.update_room(rec.room, 'dirty')
cls.write(records, {'registration_state': 'check_in'}) cls.write(records, {'registration_state': 'check_in'})
@ -287,15 +288,6 @@ class Folio(ModelSQL, ModelView):
self.registration_card = number self.registration_card = number
self.save() self.save()
def add_main_guest(self):
Guest = Pool().get('hotel.folio.guest')
Guest.create([{
'folio': self.id,
'party': self.main_guest.id,
'type_guest': 'adult',
'type_document': 13,
}])
def create_invoice(self): def create_invoice(self):
pool = Pool() pool = Pool()
Booking = pool.get('hotel.booking') Booking = pool.get('hotel.booking')
@ -505,20 +497,20 @@ class Folio(ModelSQL, ModelView):
class FolioGuest(ModelSQL, ModelView): class FolioGuest(ModelSQL, ModelView):
'Folio Guest' 'Folio Guest'
__name__ = 'hotel.folio.guest' __name__ = 'hotel.folio.guest'
_rec_name = 'party'
folio = fields.Many2One('hotel.folio', 'Folio', required=True, folio = fields.Many2One('hotel.folio', 'Folio', required=True,
ondelete='CASCADE') ondelete='CASCADE')
party = fields.Many2One('party.party', 'Party', required=False) main_guest = fields.Boolean('Main Guest')
type_guest = fields.Selection([ type_guest = fields.Selection([
('adult', 'Adult'), ('adult', 'Adult'),
('child', 'Child'), ('child', 'Child'),
], 'Type Guest') ], 'Type Guest', required=True)
type_guest_string = type_guest.translated('type_guest') type_guest_string = type_guest.translated('type_guest')
nationality = fields.Many2One('party.nationality', 'Nationality') nationality = fields.Many2One('party.nationality', 'Nationality',
required=True)
origin_country = fields.Many2One('party.nationality', 'Origin Country', origin_country = fields.Many2One('party.nationality', 'Origin Country',
select=True) select=True, required=True)
target_country = fields.Many2One('party.nationality', 'Target Country', target_country = fields.Many2One('party.nationality', 'Target Country',
select=True) select=True, required=True)
# New fields for speed reason # New fields for speed reason
type_document = fields.Selection([ type_document = fields.Selection([
('12', 'Tarjeta de Identidad'), ('12', 'Tarjeta de Identidad'),
@ -526,34 +518,31 @@ class FolioGuest(ModelSQL, ModelView):
('21', 'Tarjeta de Extranjeria'), ('21', 'Tarjeta de Extranjeria'),
('22', 'Cedula de Extranjeria'), ('22', 'Cedula de Extranjeria'),
('41', 'Pasaporte'), ('41', 'Pasaporte'),
], 'Document Type') ], 'Document Type', required=True)
doc_number = fields.Char('Doc. Id', select=True) id_number = fields.Char('Id Number', select=True, required=True)
name = fields.Char('Name', select=True) name = fields.Char('Name', select=True, required=True)
mobile = fields.Char('Mobile', select=True) mobile = fields.Char('Mobile', select=True, required=True)
email = fields.Char('Email', select=True) email = fields.Char('Email', select=True, required=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', required=True)
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_person = fields.Selection([ notes = fields.Text('Notes')
('persona_natural', 'Persona Natural'),
('persona_juridica', 'Persona Juridica'),
], 'Type Person')
@fields.depends('name', 'first_name', 'second_name', @fields.depends('name', 'first_name', 'second_name',
'first_family_name', 'second_family_name', 'type_person') 'first_family_name', 'second_family_name')
def on_change_name(self): def on_change_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.name and self.type_person == 'persona_natural': if self.name:
names = self.name.split(' ') names = self.name.split(' ')
first_name = names[0] first_name = names[0]
second_family_name = names[-1] second_family_name = names[-1]
@ -572,10 +561,6 @@ class FolioGuest(ModelSQL, ModelView):
self.second_name = second_name self.second_name = second_name
self.first_name = first_name self.first_name = first_name
def get_rec_name(self, name):
if self.party:
return self.party.name
@staticmethod @staticmethod
def default_type_guest(): def default_type_guest():
return 'adult' return 'adult'
@ -584,18 +569,10 @@ class FolioGuest(ModelSQL, ModelView):
def default_sex(): def default_sex():
return 'male' return 'male'
@staticmethod
def default_type_person():
return 'persona_natural'
@staticmethod @staticmethod
def default_type_document(): def default_type_document():
return '13' return '13'
@staticmethod
def default_principal_guest():
return False
@fields.depends('nationality', 'origin_country', 'target_country') @fields.depends('nationality', 'origin_country', 'target_country')
def on_change_nationality(self): def on_change_nationality(self):
if self.nationality: if self.nationality:
@ -603,42 +580,78 @@ class FolioGuest(ModelSQL, ModelView):
self.origin_country = self.nationality.id self.origin_country = self.nationality.id
@classmethod @classmethod
def create(cls, vlist): def manage_party(cls, v):
Party = Pool().get('party.party') Party = Pool().get('party.party')
new_values = [] is_main_guest = v.pop('main_guest')
for v in vlist: _ = v.pop('type_guest', None)
# if not v.get('doc_number'): _ = v.pop('origin_country', None)
# continue _ = v.pop('target_country', None)
party = v.get('party') folio = v.pop('folio', None)
if not party: if is_main_guest:
parties = Party.search([ parties = Party.search([
('id_number', '=', v['doc_number']), ('id_number', '=', v['id_number']),
]) ])
if parties: email = v.pop('email', '')
party = parties[0] mobile = v.pop('mobile', '')
else: v['type_person'] = 'persona_natural'
party, = Party.create([{ if not parties:
'name': v['name'], v['contact_mechanisms'] = [
'id_number': v['doc_number'], ('create', [
'type_document': v['type_document'], {'type': 'email', 'value': email},
'birthday': v['birthday'], {'type': 'mobile', 'value': mobile},
'sex': v['sex'], ])
'first_name': v['first_name'], ]
'second_name': v['second_name'], party, = Party.create([v])
'first_family_name': v['first_family_name'], else:
'second_family_name': v['second_family_name'], Party.write(parties, v)
'type_person': v['type_person'], party = parties[0]
'contact_mechanisms': [ has_email = False
('create', [ has_mobile = False
{'type': 'email', 'value': v['email']}, for cm in party.contact_mechanisms:
{'type': 'mobile', 'value': v['mobile']}, if email and cm.type == 'email':
]) cm.value = email
] has_email = True
}]) elif mobile and cm.type == 'mobile':
v['party'] = party.id cm.value = mobile
new_values.append(v) has_mobile = True
cm.save()
to_write = []
if not has_mobile and mobile:
to_write.append({'type': 'mobile', 'value': mobile})
if not has_email and email:
to_write.append({'type': 'email', 'value': email})
if to_write:
Party.write(
[parties],
{'contact_mechanisms': [('create', to_write)]}
)
super(FolioGuest, cls).create(new_values) if folio:
Folio = Pool().get('hotel.folio')
folio = Folio(folio)
folio.main_guest = party.id
folio.save()
@classmethod
def create(cls, vlist):
super(FolioGuest, cls).create(vlist)
for v in vlist:
cls.manage_party(v)
@classmethod
def write(cls, records, values):
super(FolioGuest, cls).write(records, values)
fields = cls.fields_get()
for val in ('id', 'rec_name', 'write_date', 'write_uid', 'create_date'):
fields.pop(val)
data = {}
fields_list = fields.keys()
rec = records[0]
for field in fields_list:
data[field] = getattr(rec, field)
data.update(values)
cls.manage_party(data)
class OperationMaintenance(Workflow, ModelSQL, ModelView): class OperationMaintenance(Workflow, ModelSQL, ModelView):
@ -891,7 +904,6 @@ class Migration(Report):
('arrival_date', '>=', start), ('arrival_date', '>=', start),
('arrival_date', '<=', end), ('arrival_date', '<=', end),
('main_guest', '!=', None), ('main_guest', '!=', None),
('guests.party', '!=', None),
('registration_state', 'in', ['check_in', 'check_out']), ('registration_state', 'in', ['check_in', 'check_out']),
]) ])
return report_context return report_context

View File

@ -10,9 +10,10 @@ class Invoice(metaclass=PoolMeta):
@classmethod @classmethod
def post(cls, invoices): def post(cls, invoices):
super(Invoice, cls).post(invoices) super(Invoice, cls).post(invoices)
for invoice in invoices: # FIXME: esta creando notas en ceros
if invoice.type == 'out': # for invoice in invoices:
cls.set_advances_from_origin(invoice) # if invoice.type == 'out':
# cls.set_advances_from_origin(invoice)
@classmethod @classmethod
def set_advances_from_origin(cls, invoice): def set_advances_from_origin(cls, invoice):

Binary file not shown.

View File

@ -20,8 +20,8 @@ this repository contains the full copyright notices and license terms. -->
<field name="nights_quantity"/> <field name="nights_quantity"/>
<label name="unit_price"/> <label name="unit_price"/>
<field name="unit_price"/> <field name="unit_price"/>
<label name="party"/> <!-- <label name="party"/>
<field name="party"/> <field name="party"/> -->
<label name="host_quantity"/> <label name="host_quantity"/>
<field name="host_quantity"/> <field name="host_quantity"/>
<label name="breakfast_included"/> <label name="breakfast_included"/>

View File

@ -2,8 +2,6 @@
<!-- 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 col="6"> <form col="6">
<label name="party"/>
<field name="party"/>
<label name="folio"/> <label name="folio"/>
<field name="folio"/> <field name="folio"/>
<label name="type_guest"/> <label name="type_guest"/>
@ -12,16 +10,16 @@ this repository contains the full copyright notices and license terms. -->
<field name="nationality" widget="selection"/> <field name="nationality" widget="selection"/>
<label name="type_document"/> <label name="type_document"/>
<field name="type_document"/> <field name="type_document"/>
<label name="doc_number"/> <label name="id_number"/>
<field name="doc_number"/> <field name="id_number"/>
<label name="mobile"/> <label name="mobile"/>
<field name="mobile"/> <field name="mobile"/>
<label name="email"/> <label name="email"/>
<field name="email"/> <field name="email"/>
<label name="sex"/>
<field name="sex"/>
<label name="origin_country"/> <label name="origin_country"/>
<field name="origin_country" widget="selection"/> <field name="origin_country" widget="selection"/>
<label name="target_country"/> <label name="target_country"/>
<field name="target_country" widget="selection"/> <field name="target_country" widget="selection"/>
<label name="sex"/>
<field name="sex"/>
</form> </form>

View File

@ -3,11 +3,10 @@
this repository contains the full copyright notices and license terms. --> this repository contains the full copyright notices and license terms. -->
<tree> <tree>
<field name="folio"/> <field name="folio"/>
<field name="party" expand="1"/>
<field name="type_guest"/> <field name="type_guest"/>
<field name="nationality" widget="selection"/> <field name="nationality" widget="selection"/>
<field name="type_document"/> <field name="type_document"/>
<field name="doc_number"/> <field name="id_number"/>
<field name="mobile"/> <field name="mobile"/>
<field name="email"/> <field name="email"/>
<field name="sex"/> <field name="sex"/>

View File

@ -2,16 +2,17 @@
<!-- 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="type_person"/> <label name="main_guest"/>
<field name="type_person"/> <field name="main_guest"/>
<newline />
<label name="type_guest"/>
<field name="type_guest"/>
<label name="type_document"/> <label name="type_document"/>
<field name="type_document"/> <field name="type_document"/>
<label name="name"/> <label name="name"/>
<field name="name"/> <field name="name"/>
<label name="party"/> <label name="id_number"/>
<field name="party"/> <field name="id_number"/>
<label name="doc_number"/>
<field name="doc_number"/>
<label name="mobile"/> <label name="mobile"/>
<field name="mobile"/> <field name="mobile"/>
<label name="email"/> <label name="email"/>
@ -20,10 +21,6 @@ this repository contains the full copyright notices and license terms. -->
<field name="nationality"/> <field name="nationality"/>
<label name="sex"/> <label name="sex"/>
<field name="sex"/> <field name="sex"/>
<label name="type_guest"/>
<field name="type_guest"/>
<label name="birthday"/>
<field name="birthday"/>
<label name="origin_country"/> <label name="origin_country"/>
<field name="origin_country"/> <field name="origin_country"/>
<label name="target_country"/> <label name="target_country"/>
@ -36,4 +33,8 @@ this repository contains the full copyright notices and license terms. -->
<field name="first_family_name"/> <field name="first_family_name"/>
<label name="second_family_name"/> <label name="second_family_name"/>
<field name="second_family_name"/> <field name="second_family_name"/>
<label name="birthday"/>
<field name="birthday"/>
<separator string="Notes" colspan="4"/>
<field name="notes" colspan="4"/>
</form> </form>

View File

@ -2,21 +2,13 @@
<!-- 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. -->
<tree> <tree>
<field name="party" expand="1"/> <field name="main_guest"/>
<field name="type_document"/> <field name="type_document" expand="1"/>
<field name="name" expand="1"/> <field name="name" expand="1"/>
<field name="doc_number"/> <field name="id_number" expand="1"/>
<field name="nationality" expand="1"/>
<field name="type_guest" expand="1"/>
<field name="mobile"/> <field name="mobile"/>
<field name="email"/> <field name="email"/>
<field name="nationality"/>
<field name="birthday"/>
<field name="origin_country"/>
<field name="target_country"/>
<field name="sex"/> <field name="sex"/>
<field name="type_guest"/>
<field name="first_name"/>
<field name="second_name"/>
<field name="first_family_name"/>
<field name="second_family_name"/>
<field name="type_person"/>
</tree> </tree>

View File

@ -21,6 +21,8 @@ this repository contains the full copyright notices and license terms. -->
<field name="sex"/> <field name="sex"/>
<label name="birthday"/> <label name="birthday"/>
<field name="birthday"/> <field name="birthday"/>
<label name="main_guest"/>
<field name="main_guest"/>
</group> </group>
<group colspan="4" col="4" id="travel_info" string="Travel Info"> <group colspan="4" col="4" id="travel_info" string="Travel Info">
<label name="origin_country"/> <label name="origin_country"/>