lims_report_html: add default report template in Party and Laboratory

This commit is contained in:
Adrián Bernardi 2021-11-24 17:39:57 -03:00
parent 14c6fa258e
commit 54a62034a4
11 changed files with 107 additions and 0 deletions

View File

@ -6,6 +6,8 @@ from trytond.pool import Pool
from . import action
from . import html_template
from . import configuration
from . import laboratory
from . import party
from . import sample
from . import analysis
from . import results_report
@ -20,6 +22,8 @@ def register():
html_template.ReportTemplateSection,
html_template.ReportTemplateTrendChart,
configuration.Configuration,
laboratory.Laboratory,
party.Party,
sample.Fraction,
sample.Sample,
sample.CreateSampleStart,

View File

@ -0,0 +1,13 @@
# This file is part of lims_report_html module for Tryton.
# The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms.
from trytond.model import fields
from trytond.pool import PoolMeta
class Laboratory(metaclass=PoolMeta):
__name__ = 'lims.laboratory'
result_template = fields.Many2One('lims.result_report.template',
'Report Template', domain=[('type', 'in', [None, 'base'])])

View File

@ -0,0 +1,14 @@
<?xml version="1.0"?>
<tryton>
<data>
<!-- Laboratory -->
<record model="ir.ui.view" id="laboratory_view_form">
<field name="model">lims.laboratory</field>
<field name="inherit" ref="lims.lims_laboratory_view_form"/>
<field name="name">laboratory_form</field>
</record>
</data>
</tryton>

View File

@ -22,6 +22,10 @@ msgctxt "field:lims.fraction,result_template:"
msgid "Report Template"
msgstr "Plantilla de Informe"
msgctxt "field:lims.laboratory,result_template:"
msgid "Report Template"
msgstr "Plantilla de Informe"
msgctxt "field:lims.notebook,result_template:"
msgid "Report Template"
msgstr "Plantilla de Informe"
@ -226,6 +230,10 @@ msgctxt "field:lims.sample,resultrange_origin:"
msgid "Comparison range"
msgstr "Rango de comparación"
msgctxt "field:party.party,result_template:"
msgid "Report Template"
msgstr "Plantilla de Informe"
msgctxt "model:ir.action,name:act_html_template_list"
msgid "Results Report Templates"
msgstr "Plantillas de Informe de resultados"

13
lims_report_html/party.py Normal file
View File

@ -0,0 +1,13 @@
# This file is part of lims_report_html module for Tryton.
# The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms.
from trytond.model import fields
from trytond.pool import PoolMeta
class Party(metaclass=PoolMeta):
__name__ = 'party.party'
result_template = fields.Many2One('lims.result_report.template',
'Report Template', domain=[('type', 'in', [None, 'base'])])

View File

@ -0,0 +1,14 @@
<?xml version="1.0"?>
<tryton>
<data>
<!-- Party -->
<record model="ir.ui.view" id="party_view_form">
<field name="model">party.party</field>
<field name="inherit" ref="party.party_view_form"/>
<field name="name">party_party_form</field>
</record>
</data>
</tryton>

View File

@ -176,6 +176,7 @@ class ResultsReportVersionDetail(metaclass=PoolMeta):
def _get_result_template_from_sample(cls, notebook):
pool = Pool()
Service = pool.get('lims.service')
Laboratory = pool.get('lims.laboratory')
Configuration = pool.get('lims.configuration')
result_template = notebook.fraction.sample.result_template
@ -197,6 +198,13 @@ class ResultsReportVersionDetail(metaclass=PoolMeta):
if not ok:
result_template = None
if not result_template:
laboratory_id = Transaction().context.get(
'samples_pending_reporting_laboratory', None)
if laboratory_id:
laboratory = Laboratory(laboratory_id)
result_template = laboratory.result_template
if not result_template:
config_ = Configuration(1)
result_template = config_.result_template

View File

@ -62,6 +62,21 @@ class CreateSampleStart(metaclass=PoolMeta):
class CreateSample(metaclass=PoolMeta):
__name__ = 'lims.create_sample'
def default_start(self, fields):
Party = Pool().get('party.party')
defaults = super().default_start(fields)
party_id = defaults['party']
if party_id:
party = Party(party_id)
if party.result_template:
defaults['result_template'] = party.result_template.id
if party.result_template.resultrange_origin:
defaults['resultrange_origin'] = (
party.result_template.resultrange_origin.id)
return defaults
def _get_samples_defaults(self, entry_id):
samples_defaults = super()._get_samples_defaults(entry_id)

View File

@ -5,6 +5,8 @@ depends:
xml:
html_template.xml
configuration.xml
laboratory.xml
party.xml
sample.xml
analysis.xml
results_report.xml

View File

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

View File

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<data>
<xpath
expr="/form/notebook/page[@id='lims']/field[@name='report_language']"
position="after">
<label name="result_template"/>
<field name="result_template"/>
</xpath>
</data>