Skip to content

Commit

Permalink
Merge f536696 into 9511195
Browse files Browse the repository at this point in the history
  • Loading branch information
MariteSomEnergia committed Sep 30, 2022
2 parents 9511195 + f536696 commit 9ec32b1
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 19 deletions.
71 changes: 71 additions & 0 deletions som_generationkwh/report/report_llibre_registre_socis_summary.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
## -*- coding: utf-8 -*-
<%
import ast
pool = objects[0].pool
cursor = objects[0]._cr
uid = user.id
summary_dades = data.get('dades', [])
header = data.get('header', {})
%>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<head>
<style>
html {
margin: 24px;
}
.apo_table {
border-collapse: collapse;
margin-bottom: 8px;
}
.apo_table, .apo_table th, .apo_table td {
border: 1px solid black;
}
.apo_table td, .apo_table th {
padding: 8px;
}
.apo_table td {
white-space: nowrap;
}
<!-- Print pages management -->
.keep-together {
page-break-inside: avoid;
}
.break-before {
page-break-before: always;
}
.break-after {
page-break-after: always;
}
</style>
</head>
<body>
% if len(summary_dades) > 0:
<div class="break-after">
<br />
<br />
<h1>SOM ENERGIA SCCL</h1>
<br />
<h2>RESUMEN DEL LIBR0 DE SOCIOS Y APORTACIONES SOCIALES</h2>
<br />
<br />
<p>Fecha de apertura: ${header['date_from']}</p>
<p>Fecha de cierre: ${header['date_to']}</p>
<br />
<br />
<p>Ejercicio económico ${header['date_to'][:4]}</p>
</div>

<div>
<p><b>Número de altas : </b>${summary_dades['numero_altes']}</p>
<p><b>Número de bajas : </b>${summary_dades['numero_baixes']}</p>
<p><b>Total de aportaciones de capital voluntarias : </b>${_(u"%s") % (formatLang(summary_dades['total_import_voluntari'], digits=2))}</p>
<p><b>Total de capital voluntario retirado : </b>${formatLang(summary_dades['total_import_voluntari_retirat'], digits=2)}€</p>
</div>
% endif
</body>
</html>
15 changes: 15 additions & 0 deletions som_generationkwh/somenergia_soci_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,20 @@ ${text_legal}
<field name="model">somenergia.soci</field>
<field name="value" eval="'ir.actions.report.xml,'+str(ref('report_llibre_registre_socis'))"/>
</record>
<record model="ir.actions.report.xml" id="report_llibre_registre_socis_summary">
<field name="report_type">webkit</field>
<field name="report_name">somenergia.soci.report_llibre_registre_socis_summary</field>
<field eval="[(6,0,[])]" name="groups_id"/>
<field eval="0" name="multi"/>
<field eval="0" name="auto"/>
<field eval="0" name="header"/>
<field name="model">somenergia.soci</field>
<field name="type">ir.actions.report.xml</field>
<field name="name">Resum del Llibre Registre Socis</field>
<field name="report_webkit"
eval="'som_generationkwh/report/report_llibre_registre_socis_summary.mako'"/>
<field name="webkit_header" ref="report_sense_fons_apaisat"/>
<field name="report_rml" eval="False"/>
</record>
</data>
</openerp>
98 changes: 79 additions & 19 deletions som_generationkwh/wizard/wizard_llibre_registre_socis.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os
from osv import osv, fields
from report import report_sxw

from zipfile import ZipFile

class WizardLlibreRegistreSocis(osv.osv_memory):
"""Assistent per generar registre de socis"""
Expand All @@ -25,22 +25,72 @@ def generate_report(self, cursor, uid, ids, context=None):
aw.work()
return {}


@job(queue="print_report", timeout=3000)
def generate_one_report(self, cursor, uid, ids, context=None):
wiz = self.browse(cursor, uid, ids[0])

dades = self.get_report_data(cursor, uid, ids, context)
summary_dades = self.get_report_summary(dades)

header = {}
header['date_from'] = context['date_from']
header['date_to'] = context['date_to']

document_binary = self.generate_report_pdf(cursor, uid, ids, dades, header, context)
document_binary_summary = self.generate_report_summary_pdf(cursor, uid, ids, summary_dades, header, context)

path = "/tmp/reports"
if not os.path.exists(path):
try:
os.mkdir(path)
except OSError:
print ("Creation of the directory %s failed" % path)

path_filename, filename = self.create_file(path, "llibre_registre_socis_", header['date_to'][:4],document_binary[0])
path_filenamesummary, filenamesummary = self.create_file(path, "resum_llibre_registre_socis_", header['date_to'][:4],document_binary_summary[0])

filename_zip = path + "/llibre_registre_socis_" + str(header['date_to'][:4]) + ".zip"
zipObj = ZipFile(filename_zip, 'w')
zipObj.write(path_filename, filename)
zipObj.write(path_filenamesummary, filenamesummary)
zipObj.close()

ar_obj = self.pool.get('async.reports')
datas = ar_obj.get_datas_email_params(cursor, uid, {}, context)
ar_obj.send_mail(cursor, uid, datas['from'], filename_zip, datas['email_to'], filename_zip.split("/")[-1])

def create_file(self, path, file_header, date, document):
filename = file_header + str(date) + ".pdf"
path_filename = path + "/" + filename

f = open(path_filename, 'wb+' )
try:
bits = base64.b64decode(base64.b64encode(document))
f.write(bits)
finally:
f.close()

return path_filename,filename

def generate_report_pdf(self, cursor, uid, ids, dades, header, context):
report_printer = webkit_report.WebKitParser(
'report.somenergia.soci.report_llibre_registre_socis',
'somenergia.soci',
'som_generationkwh/report/report_llibre_registre_socis.mako',
parser=report_sxw.rml_parse
)
return self.generate_report_document(cursor, uid, ids, dades, header, report_printer, context)

def generate_report_summary_pdf(self, cursor, uid, ids, summary_dades, header, context):
report_printer = webkit_report.WebKitParser(
'report.somenergia.soci.report_llibre_registre_socis_summary',
'somenergia.soci',
'som_generationkwh/report/report_llibre_registre_socis_summary.mako',
parser=report_sxw.rml_parse
)
return self.generate_report_document(cursor, uid, ids, summary_dades, header, report_printer, context)

def generate_report_document(self, cursor, uid, ids, dades, header, report_printer, context):
data = {
'model': 'giscedata.facturacio.factura',
'report_type': 'webkit',
Expand All @@ -54,23 +104,33 @@ def generate_one_report(self, cursor, uid, ids, context=None):
)
if not document_binary:
raise Exception("We can't create the report")
path = "/tmp/reports"
if not os.path.exists(path):
try:
os.mkdir(path)
except OSError:
print ("Creation of the directory %s failed" % path)
filename = path + "/llibre_registre_socis_" + str(header['date_to'][:4]) + ".pdf"
f = open(filename, 'wb+' )
try:
bits = base64.b64decode(base64.b64encode(document_binary[0]))
f.write(bits)
finally:
f.close()

ar_obj = self.pool.get('async.reports')
datas = ar_obj.get_datas_email_params(cursor, uid, {}, context)
ar_obj.send_mail(cursor, uid, datas['from'], filename, datas['email_to'], filename.split("/")[-1])
return document_binary

def get_report_summary(self, dades):
numero_altes = 0
numero_baixes = 0
total_import_voluntari = 0
total_import_voluntari_retirat = 0

for dada in dades:
for inversio in dada['inversions']:
if inversio['concepte'] == u'Obligatoria':
if inversio['import'] > 0:
numero_altes += 1
else:
numero_baixes += 1
elif inversio['concepte'] == u'Voluntaria':
if inversio['import'] > 0:
total_import_voluntari += inversio['import']
else:
total_import_voluntari_retirat += inversio['import'] * -1
return {
'numero_altes': numero_altes,
'numero_baixes': numero_baixes,
'total_import_voluntari': total_import_voluntari,
'total_import_voluntari_retirat':total_import_voluntari_retirat,
}

def get_report_data(self, cursor, uid, ids, context=None):
soci_obj = self.pool.get('somenergia.soci')
Expand Down Expand Up @@ -120,7 +180,7 @@ def get_aportacions_obligatories_values(self, cursor, uid, soci, context=None):
'concepte': u'Obligatoria',
'import': 100
})
if data['date'] >= context['date_from'] and data['date'] <= context['date_to'] and data['data_baixa_soci']:
if data['data_baixa_soci'] and data['data_baixa_soci'] >= context['date_from'] and data['data_baixa_soci'] <= context['date_to']:
inversions.append({
'data': data['data_baixa_soci'],
'concepte': u'Obligatoria',
Expand Down

0 comments on commit 9ec32b1

Please sign in to comment.