Siat fixes
This commit is contained in:
parent
f4328d2697
commit
c51df4a982
|
@ -27,6 +27,7 @@ from . import account
|
|||
from . import analytic
|
||||
from . import price_list
|
||||
from . import rate_plan
|
||||
from . import siat
|
||||
|
||||
|
||||
def register():
|
||||
|
@ -106,6 +107,7 @@ def register():
|
|||
price_list.HotelPriceList,
|
||||
rate_plan.RatePlan,
|
||||
rate_plan.RatePlanRule,
|
||||
siat.SiatSyncStart,
|
||||
module='hotel', type_='model')
|
||||
Pool.register(
|
||||
booking.BookingReport,
|
||||
|
@ -147,4 +149,5 @@ def register():
|
|||
sale.InvoiceIncomeDaily,
|
||||
party.CreateGuest,
|
||||
operation.NightAuditWizard,
|
||||
siat.SiatSyncWizard,
|
||||
module='hotel', type_='wizard')
|
||||
|
|
17
folio.py
17
folio.py
|
@ -440,25 +440,24 @@ class Folio(ModelSQL, ModelView):
|
|||
_check_accommodation(self)
|
||||
else:
|
||||
_check_charges(self)
|
||||
self._send_siat()
|
||||
self.sync_send_siat()
|
||||
|
||||
def _send_siat(self):
|
||||
def sync_send_siat(self):
|
||||
pool = Pool()
|
||||
Company = pool.get('company.company')
|
||||
Configuration = pool.get('company.company')
|
||||
config = Configuration.get_config()
|
||||
company_id = Transaction().context.get('company')
|
||||
company = Company(company_id)
|
||||
config = pool.get('hotel.configuration').get_configuration()
|
||||
company = self.booking.company
|
||||
try:
|
||||
res = send_siat(company, self.main_guest, self, config.token_siat)
|
||||
print("Respuesta SIAT ...", res)
|
||||
if res:
|
||||
now = datetime.now()
|
||||
for guest in self.guests:
|
||||
if not guest.siat_send_date:
|
||||
guest.siat_send_date = now()
|
||||
guest.save()
|
||||
except:
|
||||
print("Error en plataforma SIAT...", e)
|
||||
except Exception as error:
|
||||
print("Error en plataforma SIAT...!", error)
|
||||
raise UserError(gettext('Error en plataforma SIAT...!'))
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
|
|
87
siat.py
87
siat.py
|
@ -1,5 +1,11 @@
|
|||
import requests
|
||||
|
||||
from trytond.pool import Pool
|
||||
from trytond.model import ModelView, fields
|
||||
from trytond.wizard import Wizard, StateView, Button, StateTransition
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
|
||||
HEADERS = {
|
||||
'Accept': 'application/json',
|
||||
'Content-type': 'application/json',
|
||||
|
@ -32,16 +38,25 @@ def send_siat(company, guest, folio, token):
|
|||
nationality = guest.nationality.rec_name if guest.nationality else ''
|
||||
country = guest.country.rec_name if guest.country else ""
|
||||
rooms = len(folio.booking.lines)
|
||||
first_name = guest.first_name or ''
|
||||
second_name = guest.second_name or ''
|
||||
first_family_name = guest.first_family_name or ''
|
||||
second_family_name = guest.second_family_name or ''
|
||||
if not first_name or not first_family_name:
|
||||
return
|
||||
num_acom = len(folio.guests) - 1
|
||||
if num_acom <= 0:
|
||||
num_acom = 0
|
||||
main_guest = {
|
||||
"nombre_establecimiento": company.party.name,
|
||||
"nit_establecimiento": company.party.id_number,
|
||||
"rnt_establecimiento": company.rnt_code,
|
||||
"numero_identificacion": guest.id_number,
|
||||
"tipo_identificacion": TYPE_DOC[guest.type_document],
|
||||
"nombres": guest.first_name + guest.second_name,
|
||||
"apellidos": guest.first_family_name + guest.second_family_name,
|
||||
"nombres": first_name + second_name,
|
||||
"apellidos": first_family_name + second_family_name,
|
||||
"lugar_nacimiento": guest.nationality,
|
||||
"fecha_nacimiento": guest.birthday,
|
||||
"fecha_nacimiento": str(guest.birthday or ''),
|
||||
"genero": SEX[guest.sex],
|
||||
"nacionalidad": nationality,
|
||||
"n_habitaciones": rooms,
|
||||
|
@ -53,14 +68,14 @@ def send_siat(company, guest, folio, token):
|
|||
"pais_procedencia": country,
|
||||
"departamento_procedencia": subdivision,
|
||||
"cuidad_procedencia": city,
|
||||
"check_in": folio.arrival_date,
|
||||
"check_out": folio.departure_date,
|
||||
"costo": folio.total_amount,
|
||||
"numero_acompanantes": len(folio.guests),
|
||||
"check_in": str(folio.arrival_date),
|
||||
"check_out": str(folio.departure_date),
|
||||
"costo": int(folio.total_amount),
|
||||
"numero_acompanantes": num_acom,
|
||||
"medio_pago": None,
|
||||
"medio_reserva": "Ninguno",
|
||||
"tipo_acomodacion": folio.product.name,
|
||||
"numero_habitacion": folio.room.rec_name,
|
||||
"numero_habitacion": folio.room.code,
|
||||
}
|
||||
print(main_guest)
|
||||
res = requests.post(URL_GUEST, data=main_guest, headers=HEADERS, auth=True)
|
||||
|
@ -69,14 +84,19 @@ def send_siat(company, guest, folio, token):
|
|||
for guest in folio.guests:
|
||||
if folio.main_guest:
|
||||
continue
|
||||
|
||||
first_name = guest.first_name or ''
|
||||
second_name = guest.second_name or ''
|
||||
first_family_name = guest.first_family_name or ''
|
||||
second_family_name = guest.second_family_name or ''
|
||||
country = guest.country.rec_name if guest.country else ""
|
||||
guests.append({
|
||||
"numguestsero_identificacion": guest.id_number,
|
||||
"tipo_identificacion": TYPE_DOC[guest.type_document],
|
||||
"nombres": guest.first_name + guest.second_name,
|
||||
"apellidos": guest.first_family_name + guest.second_family_name,
|
||||
"nombres": first_name + second_name,
|
||||
"apellidos": first_family_name + second_family_name,
|
||||
"lugar_nacimiento": "",
|
||||
"fecha_nacimiento": guest.birthday,
|
||||
"fecha_nacimiento": str(guest.birthday or ''),
|
||||
"genero": SEX[guest.sex],
|
||||
"nacionalidad": country,
|
||||
"ocupacion": "",
|
||||
|
@ -86,9 +106,48 @@ def send_siat(company, guest, folio, token):
|
|||
"pais_procedencia": country,
|
||||
"departamento_procedencia": subdivision,
|
||||
"cuidad_procedencia": city,
|
||||
"check_in": guest.arrival_date,
|
||||
"check_out": guest.departure_date,
|
||||
"numero_habitacion": guest.room.rec_name,
|
||||
"check_in": str(folio.arrival_date),
|
||||
"check_out": str(folio.departure_date),
|
||||
"numero_habitacion": folio.room.code,
|
||||
"padre": res['id'],
|
||||
})
|
||||
requests.post(URL_OTHERS, data=guests, headers=HEADERS, auth=True)
|
||||
|
||||
|
||||
class SiatSyncStart(ModelView):
|
||||
'Siat Sync Start'
|
||||
__name__ = 'hotel.siat_sync.start'
|
||||
company = fields.Many2One('company.company', 'Company', required=True)
|
||||
start_date = fields.Date('Start Date', required=True)
|
||||
end_date = fields.Date('End Date', required=True)
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
return Transaction().context.get('company')
|
||||
|
||||
|
||||
class SiatSyncWizard(Wizard):
|
||||
'Siat Sync Wizard'
|
||||
__name__ = 'hotel.siat_sync.wizard'
|
||||
start = StateView(
|
||||
'hotel.siat_sync.start',
|
||||
'hotel.siat_sync_start_view_form', [
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Ok', 'accept', 'tryton-ok'),
|
||||
]
|
||||
)
|
||||
accept = StateTransition()
|
||||
|
||||
def transition_accept(self):
|
||||
pool = Pool()
|
||||
Folio = pool.get('hotel.folio')
|
||||
print("self.start.company...", self.start.company)
|
||||
folios = Folio.search([
|
||||
('booking.company', '=', self.start.company),
|
||||
('guests.siat_send_date', '=', None),
|
||||
('arrival_date', '>=', self.start.start_date),
|
||||
('departure_date', '<=', self.start.end_date),
|
||||
])
|
||||
for folio in folios:
|
||||
folio.sync_send_siat()
|
||||
return 'end'
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data>
|
||||
|
||||
<record model="ir.ui.view" id="siat_sync_start_view_form">
|
||||
<field name="model">hotel.siat_sync.start</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">siat_sync_start_form</field>
|
||||
</record>
|
||||
<record model="ir.action.wizard" id="act_hotel_siat_sync_wizard">
|
||||
<field name="name">Siat Sync</field>
|
||||
<field name="wiz_name">hotel.siat_sync.wizard</field>
|
||||
</record>
|
||||
<menuitem name="Siat Sync" parent="hotel.menu_hotel_wizards"
|
||||
sequence="10" action="act_hotel_siat_sync_wizard"
|
||||
id="menu_hotel_siat_sync"/>
|
||||
|
||||
</data>
|
||||
</tryton>
|
|
@ -1,5 +1,5 @@
|
|||
[tryton]
|
||||
version=6.0.105
|
||||
version=6.0.106
|
||||
depends:
|
||||
party
|
||||
company
|
||||
|
@ -42,3 +42,4 @@ xml:
|
|||
commission.xml
|
||||
analytic.xml
|
||||
rate_plan.xml
|
||||
siat.xml
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<form>
|
||||
<label name="start_date"/>
|
||||
<field name="start_date"/>
|
||||
<label name="end_date"/>
|
||||
<field name="end_date"/>
|
||||
<label name="company"/>
|
||||
<field name="company" widget="selection"/>
|
||||
</form>
|
Loading…
Reference in New Issue