mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[ADD] RESIDENCIA in INE xml
This commit is contained in:
@@ -30,61 +30,92 @@ import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _get_default_date(option):
|
||||
# def _get_default_date(option):
|
||||
# now = datetime.datetime.now()
|
||||
# month = int(now.month)-1
|
||||
# year = int(now.year)
|
||||
# if month <= 0:
|
||||
# month = 12
|
||||
# year -= year
|
||||
# start_date = datetime.datetime(year, month, 1)
|
||||
# end_date = calendar.monthrange(year, month)[1] - 1
|
||||
# month_end_date = start_date + datetime.timedelta(days=end_date)
|
||||
# if option == "start":
|
||||
# return start_date
|
||||
# return month_end_date
|
||||
|
||||
|
||||
def get_years():
|
||||
year_list = []
|
||||
for i in range(2017, get_year()+1):
|
||||
year_list.append((i, str(i)))
|
||||
return year_list
|
||||
|
||||
|
||||
def get_year():
|
||||
now = datetime.datetime.now()
|
||||
return int(now.year)
|
||||
|
||||
|
||||
def get_month():
|
||||
now = datetime.datetime.now()
|
||||
month = int(now.month)-1
|
||||
year = int(now.year)
|
||||
if month <= 0:
|
||||
month = 12
|
||||
year -= year
|
||||
start_date = datetime.datetime(year, month, 1)
|
||||
end_date = calendar.monthrange(year, month)[1] - 1
|
||||
month_end_date = start_date + datetime.timedelta(days=end_date)
|
||||
if option == "start":
|
||||
return start_date
|
||||
return month_end_date
|
||||
return month
|
||||
|
||||
|
||||
class Wizard(models.TransientModel):
|
||||
_name = 'ine.wizard'
|
||||
|
||||
@api.onchange('ine_start')
|
||||
def onchange_ine_start(self):
|
||||
if self.ine_start > self.ine_end:
|
||||
self.ine_start = self.ine_end
|
||||
|
||||
txt_filename = fields.Char()
|
||||
txt_binary = fields.Binary()
|
||||
ine_start = fields.Date("Fecha inicio", default=_get_default_date('start'))
|
||||
ine_end = fields.Date("Fecha final", default=_get_default_date('end'))
|
||||
|
||||
ine_month = fields.Selection([(1, 'January'), (2, 'February'),
|
||||
(3, 'March'), (4, 'April'),
|
||||
(5, 'May'), (6, 'June'), (7, 'July'),
|
||||
(8, 'August'), (9, 'September'),
|
||||
(10, 'October'), (11, 'November'),
|
||||
(12, 'December'), ],
|
||||
string='Month', default=get_month())
|
||||
ine_year = fields.Selection(get_years(), default=get_year(), string='Year')
|
||||
|
||||
adr_screen = fields.Char()
|
||||
rev_screen = fields.Char()
|
||||
|
||||
@api.one
|
||||
def generate_file(self):
|
||||
|
||||
_logger.warning("Start Export INE XML file")
|
||||
# month_first_date = datetime.datetime(self.ine_year, self.ine_month, 1)
|
||||
last_day = calendar.monthrange(self.ine_year, self.ine_month)[1]
|
||||
ine_start_search = datetime.date(self.ine_year, self.ine_month, 1)
|
||||
ine_end_search = ine_start_search + datetime.timedelta(days=last_day)
|
||||
compan = self.env.user.company_id
|
||||
active_room = self.env['hotel.room'].search([('in_ine', '=', True)])
|
||||
message = ""
|
||||
if not compan.property_name:
|
||||
message = 'The NAME of the property is not established'
|
||||
if not compan.name:
|
||||
message = 'The NAME of the company is not established'
|
||||
if not compan.vat:
|
||||
message = 'The VAT of the property is not established'
|
||||
message = 'The VAT is not established'
|
||||
if not compan.ine_tourism:
|
||||
message = 'The tourism number of the property is not established'
|
||||
if message != "":
|
||||
raise UserError(message)
|
||||
return
|
||||
encuesta = ET.Element("ENCUESTA")
|
||||
cabezera = ET.SubElement(encuesta, "CABECERA")
|
||||
fecha = ET.SubElement(cabezera, "FECHA_REFERENCIA")
|
||||
ET.SubElement(fecha, "MES").text = self.ine_start[5:7]
|
||||
ET.SubElement(fecha, "ANYO").text = self.ine_start[0:4]
|
||||
ET.SubElement(fecha, "MES").text = str(self.ine_month)
|
||||
ET.SubElement(fecha, "ANYO").text = str(self.ine_year)
|
||||
ET.SubElement(cabezera, "DIAS_ABIERTO_MES_REFERENCIA").text = (
|
||||
str(int(self.ine_end[8:10]) - int(self.ine_start[8:10]) + 1))
|
||||
str(last_day))
|
||||
ET.SubElement(cabezera, "RAZON_SOCIAL").text = compan.name
|
||||
ET.SubElement(cabezera, "NOMBRE_ESTABLECIMIENTO").text = (
|
||||
compan.property_name)
|
||||
ET.SubElement(cabezera, "CIF_NIF").text = compan.vat[2:]
|
||||
ET.SubElement(cabezera, "NUMERO_REGISTRO").text = compan.tourism
|
||||
ET.SubElement(cabezera, "NUMERO_REGISTRO").text = compan.ine_tourism
|
||||
ET.SubElement(cabezera, "DIRECCION").text = compan.street
|
||||
ET.SubElement(cabezera, "CODIGO_POSTAL").text = compan.zip
|
||||
ET.SubElement(cabezera, "LOCALIDAD").text = compan.city
|
||||
@@ -93,31 +124,103 @@ class Wizard(models.TransientModel):
|
||||
).text = compan.state_id.display_name
|
||||
ET.SubElement(cabezera, "TELEFONO_1").text = (
|
||||
compan.phone.replace(' ', '')[0:12])
|
||||
ET.SubElement(cabezera, "TIPO").text = compan.category_id.tipo
|
||||
ET.SubElement(cabezera, "CATEGORIA").text = compan.category_id.name
|
||||
# Debug Stop -------------------
|
||||
import wdb; wdb.set_trace()
|
||||
# Debug Stop -------------------
|
||||
active_room = self.env['hotel.room'].search_count(
|
||||
[('capacity', '>', 0)])
|
||||
ET.SubElement(cabezera, "HABITACIONES").text = str(active_room)
|
||||
ET.SubElement(cabezera, "TIPO").text = (
|
||||
compan.ine_category_id.category_type)
|
||||
ET.SubElement(cabezera, "CATEGORIA").text = compan.ine_category_id.name
|
||||
|
||||
ET.SubElement(cabezera, "HABITACIONES").text = str(len(active_room))
|
||||
ET.SubElement(cabezera, "PLAZAS_DISPONIBLES_SIN_SUPLETORIAS"
|
||||
).text = str(compan.seats)
|
||||
).text = str(compan.ine_seats)
|
||||
ET.SubElement(cabezera, "URL").text = compan.website
|
||||
alojamiento = ET.SubElement(encuesta, "ALOJAMIENTO")
|
||||
|
||||
all_room_nights = self.env['hotel.reservation.line'].search([
|
||||
('date', '>=', ine_start_search),
|
||||
('date', '<=', ine_end_search),
|
||||
('reservation_id.room_id.in_ine', '=', True),
|
||||
])
|
||||
room_nights = all_room_nights.filtered(
|
||||
lambda n: (self.get_codeine(n.reservation_id)))
|
||||
|
||||
# Creating the empty dictionary system
|
||||
dic_tabla = []
|
||||
for room_night in room_nights:
|
||||
ine_code = self.get_codeine(room_night.reservation_id)
|
||||
if not next((item for item in dic_tabla if item["ine"] == ine_code), False):
|
||||
for x in range(1, last_day+1):
|
||||
dic_tabla.append({'ine': ine_code,
|
||||
'dia': x,
|
||||
'entradas': 0,
|
||||
'salidas': 0,
|
||||
'pernocta': 0
|
||||
})
|
||||
|
||||
# Adding overnight stays per day and INE code
|
||||
for dia in range(1, last_day+1):
|
||||
_logger.info("INE: Calculating %s de %s reservation", dia, last_day)
|
||||
for room_night in room_nights.filtered(lambda x: x.date == str(self.ine_year)+'-'+str(self.ine_month).zfill(2)+'-'+str(dia).zfill(2)):
|
||||
ine_code = self.get_codeine(room_night.reservation_id)
|
||||
for idx, val in enumerate(dic_tabla):
|
||||
if val['ine'] == ine_code and val['dia'] == dia:
|
||||
dic_tabla[idx]['pernocta'] += room_night.reservation_id.adults
|
||||
|
||||
# Debug Stop -------------------
|
||||
# import wdb; wdb.set_trace()
|
||||
# Debug Stop -------------------
|
||||
# Calculating outputs and entries
|
||||
count = 1
|
||||
last_stay = 0
|
||||
for idx, row in enumerate(dic_tabla):
|
||||
if count == last_day:
|
||||
last_stay = 0
|
||||
count = 1
|
||||
count += 1
|
||||
if last_stay < dic_tabla[idx]['pernocta']:
|
||||
dic_tabla[idx]['entradas'] += dic_tabla[idx]['pernocta']
|
||||
elif last_stay > dic_tabla[idx]['pernocta']:
|
||||
dic_tabla[idx]['salidas'] += last_stay - dic_tabla[idx]['pernocta']
|
||||
last_stay = dic_tabla[idx]['pernocta']
|
||||
|
||||
# "Print" outputs and entries
|
||||
ine_residen = ""
|
||||
for idx, row in enumerate(dic_tabla):
|
||||
if ine_residen != dic_tabla[idx]['ine']:
|
||||
ine_residen = dic_tabla[idx]['ine']
|
||||
residencia = ET.SubElement(alojamiento, "RESIDENCIA")
|
||||
if len(dic_tabla[idx]['ine']) > 3:
|
||||
ET.SubElement(residencia, "ID_PROVINCIA_ISLA"
|
||||
).text = str(dic_tabla[idx]['ine'])
|
||||
else:
|
||||
ET.SubElement(residencia, "ID_PAIS"
|
||||
).text = str(dic_tabla[idx]['ine'])
|
||||
if (dic_tabla[idx]['entradas'] != 0) or (dic_tabla[idx]['salidas'] != 0) or (dic_tabla[idx]['pernocta'] != 0):
|
||||
movimiento = ET.SubElement(residencia, "MOVIMIENTO")
|
||||
ET.SubElement(movimiento, "N_DIA").text = "%02d" % dic_tabla[idx]['dia']
|
||||
ET.SubElement(movimiento, "ENTRADAS").text = str(dic_tabla[idx]['entradas'])
|
||||
ET.SubElement(movimiento, "SALIDAS").text = str(dic_tabla[idx]['salidas'])
|
||||
ET.SubElement(movimiento, "PERNOCTACIONES").text = str(dic_tabla[idx]['pernocta'])
|
||||
|
||||
|
||||
xmlstr = '<?xml version="1.0" encoding="ISO-8859-1"?>'
|
||||
xmlstr += ET.tostring(encuesta)
|
||||
xmlstr += ET.tostring(encuesta).decode('utf-8')
|
||||
return self.write({
|
||||
'txt_filename': 'INE_'+str(self.ine_month)+'_'+str(
|
||||
self.ine_year) + '.' + 'xml',
|
||||
self.ine_year) + '.' + 'xml',
|
||||
# 'adr_screen': _('ADR in the month of the survey: ')+str(
|
||||
# round(month_adr_sum/month_adr_rooms, 2))+_('€ and '),
|
||||
# 'rev_screen': ' RevPar : '+str(round(
|
||||
# month_adr_sum/month_revpar_staff_rooms, 2))+'€',
|
||||
'txt_binary': base64.encodestring(xmlstr)
|
||||
'txt_binary': base64.encodestring(xmlstr.encode())
|
||||
})
|
||||
|
||||
@api.model
|
||||
def get_codeine(self, reserva):
|
||||
response = False
|
||||
code = reserva[0].partner_id.code_ine_id
|
||||
if code:
|
||||
response = code.code
|
||||
else:
|
||||
for l in reserva[0].folio_id.checkin_partner_ids:
|
||||
if l.code_ine_id:
|
||||
response = l.code_ine_id.code
|
||||
return response
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
<act_window
|
||||
id="action_ine_download"
|
||||
name="Action INE File Download"
|
||||
name="I.N.E. File Download"
|
||||
res_model="ine.wizard"
|
||||
view_mode="form"
|
||||
/>
|
||||
@@ -16,8 +16,8 @@
|
||||
<form>
|
||||
<sheet>
|
||||
<group string="Generar estadistica para el I.N.E." colspan="1">
|
||||
<field name="ine_start" style="width:110px;"/>
|
||||
<field name="ine_end" style="width:110px"/>
|
||||
<field name="ine_year" style="width:110px;"/>
|
||||
<field name="ine_month" style="width:110px"/>
|
||||
</group>
|
||||
<div>
|
||||
<button name="generate_file" class="oe_form_button_save btn btn-primary btn-sm" type="object" string="Generate file"/>
|
||||
|
||||
Reference in New Issue
Block a user