diff --git a/lims/results_report.py b/lims/results_report.py
index 36ae7b7..8a66bce 100644
--- a/lims/results_report.py
+++ b/lims/results_report.py
@@ -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])],
diff --git a/lims_diagnosis/results_report.py b/lims_diagnosis/results_report.py
index f9e1b62..604c10b 100644
--- a/lims_diagnosis/results_report.py
+++ b/lims_diagnosis/results_report.py
@@ -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:
diff --git a/lims_report_html/__init__.py b/lims_report_html/__init__.py
index 0ae13eb..2caef6d 100644
--- a/lims_report_html/__init__.py
+++ b/lims_report_html/__init__.py
@@ -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,
diff --git a/lims_report_html/locale/es.po b/lims_report_html/locale/es.po
index 72cdf1f..c2fe9bc 100644
--- a/lims_report_html/locale/es.po
+++ b/lims_report_html/locale/es.po
@@ -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"
diff --git a/lims_report_html/results_report.py b/lims_report_html/results_report.py
index 73a4298..67a31d1 100644
--- a/lims_report_html/results_report.py
+++ b/lims_report_html/results_report.py
@@ -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
diff --git a/lims_report_html/results_report.xml b/lims_report_html/results_report.xml
index 30afe84..35ec306 100644
--- a/lims_report_html/results_report.xml
+++ b/lims_report_html/results_report.xml
@@ -52,5 +52,13 @@
results
+
+
+
+ lims.notebook.generate_results_report.start
+
+ notebook_generate_results_report_form
+
+
diff --git a/lims_report_html/view/notebook_generate_results_report_form.xml b/lims_report_html/view/notebook_generate_results_report_form.xml
new file mode 100644
index 0000000..ac8f0b8
--- /dev/null
+++ b/lims_report_html/view/notebook_generate_results_report_form.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+