lims: execute Results Report via wizard

This commit is contained in:
Adrián Bernardi 2020-09-01 20:11:28 -03:00
parent 00bb13f43b
commit c71ededea0
4 changed files with 127 additions and 93 deletions

View file

@ -322,7 +322,8 @@ def register():
results_report.OpenSamplesPendingReporting,
results_report.GenerateReport,
results_report.OpenSampleEntry,
results_report.PrintResultsReport,
results_report.PrintResultReport,
results_report.PrintGlobalResultReport,
certification.DuplicateAnalysisFamily,
results_report.ServiceResultsReport,
results_report.FractionResultsReport,

View file

@ -6782,7 +6782,7 @@ msgctxt "model:ir.action,name:report_entry_labels"
msgid "Entry Labels"
msgstr "Etiquetas de ingreso"
msgctxt "model:ir.action,name:report_global_results_report"
msgctxt "model:ir.action,name:report_global_result_report"
msgid "Global Results Report"
msgstr "Informe global de resultados"
@ -6814,7 +6814,7 @@ msgctxt "model:ir.action,name:report_referral"
msgid "Referral Report"
msgstr "Informe de Derivación"
msgctxt "model:ir.action,name:report_results_report"
msgctxt "model:ir.action,name:report_result_report"
msgid "Results Report"
msgstr "Informe de resultados"
@ -7057,10 +7057,6 @@ msgctxt "model:ir.action,name:wiz_lims_notebook_uncertainty_calc"
msgid "Uncertainty Calculation"
msgstr "07) Cálculo de incertidumbre"
msgctxt "model:ir.action,name:wiz_lims_print_results_report"
msgid "Print Global Report"
msgstr "Imprimir Informe global"
msgctxt "model:ir.action,name:wiz_lims_relate_analysis"
msgid "Relate Analysis"
msgstr "Relacionar análisis"
@ -7137,6 +7133,14 @@ msgctxt "model:ir.action,name:wiz_print_analysis_pending_inform"
msgid "Pending analysis Unchecked"
msgstr "Análisis pendientes sin tildar"
msgctxt "model:ir.action,name:wiz_print_global_result_report"
msgid "Global Results Report"
msgstr "Informe global de resultados"
msgctxt "model:ir.action,name:wiz_print_result_report"
msgid "Results Report"
msgstr "Informe de resultados"
msgctxt "model:ir.action,name:wiz_referral_service"
msgid "Refer Service"
msgstr "Derivar Servicio"

View file

@ -8,7 +8,7 @@ from PyPDF2 import PdfFileMerger
from trytond.model import ModelView, ModelSQL, fields
from trytond.wizard import Wizard, StateTransition, StateView, StateAction, \
Button
StateReport, Button
from trytond.pool import Pool
from trytond.pyson import PYSONEncoder, Eval, Equal, Bool, Not, And, Or, If
from trytond.transaction import Transaction
@ -2778,70 +2778,6 @@ class OpenSampleEntry(Wizard):
return action, {}
class PrintResultsReport(Wizard):
'Print Results Report'
__name__ = 'lims.print_results_report'
start = StateTransition()
print_ = StateAction('lims.report_global_results_report')
def transition_start(self):
pool = Pool()
ResultsReport = pool.get('lims.results_report')
ResultsDetail = pool.get('lims.results_report.version.detail')
for active_id in Transaction().context['active_ids']:
results_report = ResultsReport(active_id)
format_field = 'report_format'
if results_report.english_report:
format_field = 'report_format_eng'
with Transaction().set_user(0):
details = ResultsDetail.search([
('report_version.results_report.id', '=',
results_report.id),
('valid', '=', True),
(format_field, '=', 'pdf'),
])
if not details:
raise UserError(gettext('lims.msg_empty_report'))
if results_report.english_report:
results_report.report_format_eng = 'pdf'
results_report.report_cache_eng = self._get_global_report(
details, True)
else:
results_report.report_format = 'pdf'
results_report.report_cache = self._get_global_report(
details, False)
results_report.save()
return 'print_'
def _get_global_report(self, details, english_report=False):
merger = PdfFileMerger(strict=False)
if english_report:
for detail in details:
filedata = BytesIO(detail.report_cache_eng)
merger.append(filedata)
else:
for detail in details:
filedata = BytesIO(detail.report_cache)
merger.append(filedata)
output = BytesIO()
merger.write(output)
return bytearray(output.getvalue())
def do_print_(self, action):
data = {}
data['id'] = Transaction().context['active_ids'].pop()
data['ids'] = [data['id']]
return action, data
def transition_print_(self):
if Transaction().context['active_ids']:
return 'print_'
return 'end'
class ServiceResultsReport(Wizard):
'Service Results Report'
__name__ = 'lims.service.results_report'
@ -3142,6 +3078,28 @@ class NewResultsReportVersion(Wizard):
return 'end'
class PrintResultReport(Wizard):
'Print Results Report'
__name__ = 'lims.print_result_report'
start = StateTransition()
print_ = StateReport('lims.result_report')
def transition_start(self):
return 'print_'
def do_print_(self, action):
data = {}
data['id'] = Transaction().context['active_ids'].pop()
data['ids'] = [data['id']]
return action, data
def transition_print_(self):
if Transaction().context['active_ids']:
return 'print_'
return 'end'
class ResultReport(Report):
'Results Report'
__name__ = 'lims.result_report'
@ -4083,6 +4041,70 @@ class ResultReportTranscription(ResultReport):
return result
class PrintGlobalResultReport(Wizard):
'Print Global Results Report'
__name__ = 'lims.print_global_result_report'
start = StateTransition()
print_ = StateReport('lims.global_result_report')
def transition_start(self):
pool = Pool()
ResultsReport = pool.get('lims.results_report')
ResultsDetail = pool.get('lims.results_report.version.detail')
for active_id in Transaction().context['active_ids']:
results_report = ResultsReport(active_id)
format_field = 'report_format'
if results_report.english_report:
format_field = 'report_format_eng'
with Transaction().set_user(0):
details = ResultsDetail.search([
('report_version.results_report.id', '=',
results_report.id),
('valid', '=', True),
(format_field, '=', 'pdf'),
])
if not details:
raise UserError(gettext('lims.msg_empty_report'))
if results_report.english_report:
results_report.report_format_eng = 'pdf'
results_report.report_cache_eng = self._get_global_report(
details, True)
else:
results_report.report_format = 'pdf'
results_report.report_cache = self._get_global_report(
details, False)
results_report.save()
return 'print_'
def _get_global_report(self, details, english_report=False):
merger = PdfFileMerger(strict=False)
if english_report:
for detail in details:
filedata = BytesIO(detail.report_cache_eng)
merger.append(filedata)
else:
for detail in details:
filedata = BytesIO(detail.report_cache)
merger.append(filedata)
output = BytesIO()
merger.write(output)
return bytearray(output.getvalue())
def do_print_(self, action):
data = {}
data['id'] = Transaction().context['active_ids'].pop()
data['ids'] = [data['id']]
return action, data
def transition_print_(self):
if Transaction().context['active_ids']:
return 'print_'
return 'end'
class GlobalResultReport(Report):
'Global Results Report'
__name__ = 'lims.global_result_report'

View file

@ -602,19 +602,6 @@
<field name="group" ref="group_lims_laboratory_reports"/>
</record>
<!-- Wizard Print Global Results Report -->
<record model="ir.action.wizard" id="wiz_lims_print_results_report">
<field name="name">Print Global Report</field>
<field name="wiz_name">lims.print_results_report</field>
</record>
<record model="ir.action.keyword" id="lims_print_results_report_keyword">
<field name="keyword">form_print</field>
<field name="model">lims.results_report,-1</field>
<field name="action" ref="wiz_lims_print_results_report"/>
</record>
<!-- Wizard Service Results Report -->
<record model="ir.action.wizard" id="wiz_lims_service_results_report">
@ -757,9 +744,22 @@
<field name="action" ref="wiz_results_report_version_detail_line_repeat_analysis"/>
</record>
<!-- Wizard Print Results Report -->
<record model="ir.action.wizard" id="wiz_print_result_report">
<field name="name">Results Report</field>
<field name="wiz_name">lims.print_result_report</field>
</record>
<record model="ir.action.keyword" id="wiz_print_result_report_keyword">
<field name="keyword">form_print</field>
<field name="model">lims.results_report.version.detail,-1</field>
<field name="action" ref="wiz_print_result_report"/>
</record>
<!-- Results Report -->
<record model="ir.action.report" id="report_results_report">
<record model="ir.action.report" id="report_result_report">
<field name="name">Results Report</field>
<field name="model">lims.results_report.version.detail</field>
<field name="report_name">lims.result_report</field>
@ -767,12 +767,6 @@
<field name="extension">pdf</field>
</record>
<record model="ir.action.keyword" id="report_results_report_keyword">
<field name="keyword">form_print</field>
<field name="model">lims.results_report.version.detail,-1</field>
<field name="action" ref="report_results_report"/>
</record>
<!-- Transcription Results Report -->
<record model="ir.action.report" id="report_results_report_transcription">
@ -789,9 +783,22 @@
<field name="action" ref="report_results_report_transcription"/>
</record>
<!-- Wizard Print Global Results Report -->
<record model="ir.action.wizard" id="wiz_print_global_result_report">
<field name="name">Global Results Report</field>
<field name="wiz_name">lims.print_global_result_report</field>
</record>
<record model="ir.action.keyword" id="wiz_print_global_result_report_keyword">
<field name="keyword">form_print</field>
<field name="model">lims.results_report,-1</field>
<field name="action" ref="wiz_print_global_result_report"/>
</record>
<!-- Global Results Report -->
<record model="ir.action.report" id="report_global_results_report">
<record model="ir.action.report" id="report_global_result_report">
<field name="name">Global Results Report</field>
<field name="report_name">lims.global_result_report</field>
<field name="report">lims/report/global_results_report.fodt</field>