lims_report_html: generate results report: allow to set the report template

This commit is contained in:
Adrián Bernardi 2021-09-23 17:23:44 -03:00
parent 9743e692a8
commit eb7bcae6e0
7 changed files with 102 additions and 32 deletions

View File

@ -1304,7 +1304,7 @@ class ResultsReportVersionDetail(Workflow, ModelSQL, ModelView):
return 'lims-white'
@classmethod
def _get_fields_from_samples(cls, samples):
def _get_fields_from_samples(cls, samples, generate_report_form=None):
detail_default = {}
if len(samples) > 1:
detail_default['report_type_forced'] = 'polisample'
@ -3228,7 +3228,7 @@ class GenerateReport(Wizard):
'samples': [('create', samples)],
}
details.update(ResultsDetail._get_fields_from_samples(
samples))
samples, self.start))
versions = {
'laboratory': laboratory_id,
'details': [('create', [details])],

View File

@ -105,11 +105,12 @@ class ResultsReportVersionDetail(metaclass=PoolMeta):
sample.diagnosis_states = states
@classmethod
def _get_fields_from_samples(cls, samples):
def _get_fields_from_samples(cls, samples, generate_report_form=None):
pool = Pool()
Notebook = pool.get('lims.notebook')
Diagnostician = pool.get('lims.diagnostician')
detail_default = super()._get_fields_from_samples(samples)
detail_default = super()._get_fields_from_samples(samples,
generate_report_form)
for sample in samples:
notebook = Notebook(sample['notebook'])
if notebook.fraction.sample.diagnostician:

View File

@ -25,11 +25,13 @@ def register():
results_report.ResultsReportVersionDetailSection,
results_report.ResultsReportVersionDetailTrendChart,
results_report.ResultsReportVersionDetailSample,
results_report.GenerateReportStart,
notebook.Notebook,
module='lims_report_html', type_='model')
Pool.register(
action.ReportTranslationSet,
sample.CreateSample,
results_report.GenerateReport,
module='lims_report_html', type_='wizard')
Pool.register(
results_report.ResultReport,

View File

@ -22,6 +22,10 @@ msgctxt "field:lims.notebook,resultrange_origin:"
msgid "Comparison range"
msgstr "Rango de comparación"
msgctxt "field:lims.notebook.generate_results_report.start,template:"
msgid "Report Template"
msgstr "Plantilla de Informe"
msgctxt "field:lims.result_report.template,charts_x_row:"
msgid "Charts per Row"
msgstr "Gráficos por fila"

View File

@ -128,35 +128,48 @@ class ResultsReportVersionDetail(metaclass=PoolMeta):
cls.write(sections, {'sections': value})
@classmethod
def _get_fields_from_samples(cls, samples):
Notebook = Pool().get('lims.notebook')
detail_default = super()._get_fields_from_samples(samples)
def _get_fields_from_samples(cls, samples, generate_report_form=None):
pool = Pool()
Notebook = pool.get('lims.notebook')
detail_default = super()._get_fields_from_samples(samples,
generate_report_form)
result_template = None
if generate_report_form and generate_report_form.template:
result_template = generate_report_form.template
resultrange_origin = None
for sample in samples:
notebook = Notebook(sample['notebook'])
result_template = cls._get_result_template_from_sample(notebook)
if result_template:
detail_default['template'] = result_template.id
if result_template.resultrange_origin:
detail_default['resultrange_origin'] = (
result_template.resultrange_origin.id)
if result_template.trend_charts:
detail_default['trend_charts'] = [('create', [{
'chart': c.chart.id,
'order': c.order,
} for c in result_template.trend_charts])]
detail_default['charts_x_row'] = (
result_template.charts_x_row)
if result_template.sections:
detail_default['sections'] = [('create', [{
'name': s.name,
'data': s.data,
'data_id': s.data_id,
'position': s.position,
'order': s.order,
} for s in result_template.sections])]
resultrange_origin = notebook.fraction.sample.resultrange_origin
if resultrange_origin:
detail_default['resultrange_origin'] = resultrange_origin.id
nb = Notebook(sample['notebook'])
if not result_template:
result_template = cls._get_result_template_from_sample(nb)
if not resultrange_origin:
resultrange_origin = nb.fraction.sample.resultrange_origin
if result_template:
detail_default['template'] = result_template.id
if not resultrange_origin:
resultrange_origin = result_template.resultrange_origin
if result_template.trend_charts:
detail_default['trend_charts'] = [('create', [{
'chart': c.chart.id,
'order': c.order,
} for c in result_template.trend_charts])]
detail_default['charts_x_row'] = (
result_template.charts_x_row)
if result_template.sections:
detail_default['sections'] = [('create', [{
'name': s.name,
'data': s.data,
'data_id': s.data_id,
'position': s.position,
'order': s.order,
} for s in result_template.sections])]
if resultrange_origin:
detail_default['resultrange_origin'] = resultrange_origin.id
return detail_default
@classmethod
@ -766,3 +779,38 @@ class TemplateTranslations:
return ReportTemplate.gettext(self.template, singular,
self.language)
return singular
class GenerateReportStart(metaclass=PoolMeta):
__name__ = 'lims.notebook.generate_results_report.start'
template = fields.Many2One('lims.result_report.template',
'Report Template', domain=[('type', 'in', [None, 'base'])],
states={'readonly': Bool(Eval('report'))},
depends=['report'])
class GenerateReport(metaclass=PoolMeta):
__name__ = 'lims.notebook.generate_results_report'
def default_start(self, fields):
pool = Pool()
Notebook = pool.get('lims.notebook')
res = super().default_start(fields)
res['template'] = None
if res['report']:
return res
template = None
for notebook in Notebook.browse(Transaction().context['active_ids']):
if not notebook.fraction.sample.result_template:
continue
if not template:
template = notebook.fraction.sample.result_template.id
elif template != notebook.fraction.sample.result_template.id:
return res
res['template'] = template
return res

View File

@ -52,5 +52,13 @@
<field name="template_extension">results</field>
</record>
<!-- Wizard Generate Results Report -->
<record model="ir.ui.view" id="notebook_generate_results_report_view_form">
<field name="model">lims.notebook.generate_results_report.start</field>
<field name="inherit" ref="lims.notebook_generate_results_report_view_form"/>
<field name="name">notebook_generate_results_report_form</field>
</record>
</data>
</tryton>

View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<data>
<xpath expr="/form/group[@id='append_samples']" position="after">
<label name="template"/>
<field name="template"/>
</xpath>
</data>