lims_diagnosis: add diagnosis to html results report

This commit is contained in:
Adrián Bernardi 2020-05-15 11:35:43 -03:00
parent 5fc82f1962
commit 66962b8386
6 changed files with 65 additions and 3 deletions

View file

@ -32,3 +32,6 @@ def register():
Pool.register(
sample.CreateSample,
module='lims_diagnosis', type_='wizard')
Pool.register(
results_report.ResultReport,
module='lims_report_html', type_='report')

View file

@ -4,6 +4,8 @@
from trytond.model import ModelSQL, ModelView, fields, DictSchemaMixin
from trytond.pool import PoolMeta
from trytond.exceptions import UserError
from trytond.i18n import gettext
__all__ = ['DiagnosisState', 'DiagnosisTemplate', 'DiagnosisTemplateState',
'ReportTemplate']
@ -45,3 +47,17 @@ class ReportTemplate(metaclass=PoolMeta):
diagnosis_template = fields.Many2One('lims.diagnosis.template',
'Diagnosis Template')
@classmethod
def validate(cls, templates):
for template in templates:
template.check_diagnosis_macro()
def check_diagnosis_macro(self):
if not self.diagnosis_template:
return
signature = 'show_diagnosis_content'
if str(self.content).find(signature) == -1:
raise UserError(gettext(
'lims_diagnosis.missing_diagnosis_signature',
signature=signature))

View file

@ -99,6 +99,10 @@ msgctxt "model:ir.action,name:act_html_diagnosis_template_list"
msgid "Diagnosis Templates"
msgstr "Plantillas de Diagnóstico"
msgctxt "model:ir.message,text:missing_diagnosis_signature"
msgid "Signature missing for diagnosis: %(signature)s"
msgstr "Falta la firma para el diagnóstico: %(signature)s"
msgctxt "model:ir.ui.menu,name:menu_diagnosis_state_list"
msgid "Diagnosis States"
msgstr "Estados de Diagnóstico"

View file

@ -1,5 +1,8 @@
<?xml version="1.0"?>
<tryton>
<data grouped="1">
<record model="ir.message" id="missing_diagnosis_signature">
<field name="text">Signature missing for diagnosis: %(signature)s</field>
</record>
</data>
</tryton>

View file

@ -3,10 +3,11 @@
# the full copyright notices and license terms.
from trytond.model import ModelView, fields
from trytond.pool import PoolMeta
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval
__all__ = ['ResultsReportVersionDetail', 'ResultsReportVersionDetailSample']
__all__ = ['ResultsReportVersionDetail', 'ResultsReportVersionDetailSample',
'ResultReport']
class ResultsReportVersionDetail(metaclass=PoolMeta):
@ -73,3 +74,38 @@ class ResultsReportVersionDetailSample(metaclass=PoolMeta):
return [s.id for s in
self.version_detail.diagnosis_template.diagnosis_states]
return []
class ResultReport(metaclass=PoolMeta):
__name__ = 'lims.result_report'
@classmethod
def get_results_report_template(cls, action, detail_id):
content = super(ResultReport, cls).get_results_report_template(
action, detail_id)
signature = 'show_diagnosis_content'
diagnosis_content = (
'{%% macro %s(sample) %%}\n%s\n{%% endmacro %%}' % (
signature, '{{ sample.diagnosis }}'))
return '%s\n\n%s' % (diagnosis_content, content)
@classmethod
def get_context(cls, records, data):
ResultsSample = Pool().get('lims.results_report.version.detail.sample')
report_context = super(ResultReport, cls).get_context(records, data)
if 'id' in data:
report_id = data['id']
else:
report_id = records[0].id
for fraction in report_context['fractions']:
detail_sample = ResultsSample.search([
('version_detail', '=', report_id),
('notebook.fraction.sample.number', '=', fraction['fraction']),
], limit=1)
if not detail_sample:
fraction['diagnosis'] = ''
continue
fraction['diagnosis'] = detail_sample[0].diagnosis
return report_context

View file

@ -2,7 +2,7 @@
<data>
<xpath expr="/form/notebook/page[@id='lines']" position="after">
<page id="diagnosis" string="Diagnosis">
<!-- <field name="diagnosis" colspan="4" widget="html"/>-->
<field name="diagnosis" colspan="4" widget="html"/>
<field name="diagnosis" colspan="4"/>
<field name="diagnosis_states"/>
<field name="diagnosis_states_domain" colspan="4" invisible="1"/>