lims_report_html: results report: add wizard for uploading attachments to sections

This commit is contained in:
Adrián Bernardi 2022-12-20 21:43:48 -03:00
parent 1335e59360
commit d7f707273a
6 changed files with 181 additions and 0 deletions

View File

@ -34,12 +34,14 @@ def register():
results_report.ResultsReportVersionDetailTrendChart,
results_report.ResultsReportVersionDetailSample,
results_report.GenerateReportStart,
results_report.RelateAttachmentResultsReportStart,
notebook.Notebook,
module='lims_report_html', type_='model')
Pool.register(
action.ReportTranslationSet,
sample.CreateSample,
results_report.GenerateReport,
results_report.RelateAttachmentResultsReport,
module='lims_report_html', type_='wizard')
Pool.register(
results_report.ResultReport,

View File

@ -182,6 +182,21 @@ msgctxt "field:lims.results_report.version.detail,trend_charts:"
msgid "Trend Charts"
msgstr "Gráficos de tendencia"
msgctxt ""
"field:lims.results_report.version.detail.relate_attachment.start,attachment:"
msgid "Attachment"
msgstr "Adjunto"
msgctxt ""
"field:lims.results_report.version.detail.relate_attachment.start,attachment_domain:"
msgid "Attachment domain"
msgstr "Dominio para Adjunto"
msgctxt ""
"field:lims.results_report.version.detail.relate_attachment.start,position:"
msgid "Position"
msgstr "Posición"
msgctxt "field:lims.results_report.version.detail.sample,attachments:"
msgid "Attachments"
msgstr "Adjuntos"
@ -246,6 +261,11 @@ msgctxt "model:ir.action,name:report_result_report_html"
msgid "Results Report"
msgstr "Informe de resultados"
msgctxt ""
"model:ir.action,name:wiz_results_report_version_detail_relate_attachment"
msgid "Relate Attachment to Results Report"
msgstr "Relacionar adjunto a Informe de resultados"
msgctxt "model:ir.message,text:msg_no"
msgid "No"
msgstr "No"
@ -286,6 +306,11 @@ msgctxt "model:lims.report.template.trend.chart,name:"
msgid "Results Report Template Trend Chart"
msgstr "Gráfico de tendencia de Plantilla de Informe de resultados"
msgctxt ""
"model:lims.results_report.version.detail.relate_attachment.start,name:"
msgid "Relate Attachment to Results Report"
msgstr "Relacionar adjunto a Informe de resultados"
msgctxt "model:lims.results_report.version.detail.section,name:"
msgid "Results Report Version Detail Section"
msgstr "Sección de Detalle de versión de Informe de resultados"
@ -350,6 +375,16 @@ msgctxt "selection:lims.results_report.version.detail,template_type:"
msgid "HTML - Header"
msgstr "HTML - Encabezado"
msgctxt ""
"selection:lims.results_report.version.detail.relate_attachment.start,position:"
msgid "Following"
msgstr "Siguiente"
msgctxt ""
"selection:lims.results_report.version.detail.relate_attachment.start,position:"
msgid "Previous"
msgstr "Anterior"
msgctxt "selection:lims.results_report.version.detail.section,position:"
msgid "Following"
msgstr "Siguiente"
@ -369,3 +404,17 @@ msgstr "Encabezado y Pie de página"
msgctxt "view:lims.results_report.version.detail:"
msgid "Comments"
msgstr "Observaciones"
msgctxt "view:lims.results_report.version.detail:"
msgid "Relate Attachment"
msgstr "Relacionar archivo adjunto"
msgctxt ""
"wizard_button:lims.results_report.version.detail.relate_attachment,start,end:"
msgid "Cancel"
msgstr "Cancelar"
msgctxt ""
"wizard_button:lims.results_report.version.detail.relate_attachment,start,relate:"
msgid "Relate"
msgstr "Relacionar"

View File

@ -6,6 +6,7 @@ from PyPDF2 import PdfFileMerger
from PyPDF2.utils import PdfReadError
from trytond.model import ModelView, ModelSQL, fields
from trytond.wizard import Wizard, StateTransition, StateView, Button
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval, Not, Bool
from trytond.transaction import Transaction
@ -59,6 +60,12 @@ class ResultsReportVersionDetail(metaclass=PoolMeta):
del cls.resultrange_origin.states['invisible']
if 'required' in cls.resultrange_origin.states:
del cls.resultrange_origin.states['required']
cls._buttons.update({
'relate_attachment': {
'invisible': Eval('state').in_(['released', 'annulled']),
'depends': ['state'],
},
})
@classmethod
def view_attributes(cls):
@ -243,6 +250,12 @@ class ResultsReportVersionDetail(metaclass=PoolMeta):
def set_comments_plain(cls, records, name, value):
cls.write(records, {'comments': value})
@classmethod
@ModelView.button_action(
'lims_report_html.wiz_results_report_version_detail_relate_attachment')
def relate_attachment(cls, details):
pass
class ResultsReportVersionDetailSection(ModelSQL, ModelView):
'Results Report Version Detail Section'
@ -290,6 +303,92 @@ class ResultsReportVersionDetailTrendChart(ModelSQL, ModelView):
order = fields.Integer('Order')
class RelateAttachmentResultsReportStart(ModelView):
'Relate Attachment to Results Report'
__name__ = 'lims.results_report.version.detail.relate_attachment.start'
position = fields.Selection([
('previous', 'Previous'),
('following', 'Following'),
], 'Position', required=True)
attachment = fields.Many2One('ir.attachment', 'Attachment', required=True,
domain=[('id', 'in', Eval('attachment_domain'))],
depends=['attachment_domain'])
attachment_domain = fields.Many2Many('ir.attachment', None, None,
'Attachment domain')
class RelateAttachmentResultsReport(Wizard):
'Relate Attachment to Results Report'
__name__ = 'lims.results_report.version.detail.relate_attachment'
start = StateView(
'lims.results_report.version.detail.relate_attachment.start',
'lims_report_html.'
'results_report_version_detail_relate_attachment_start_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Relate', 'relate', 'tryton-ok', default=True),
])
relate = StateTransition()
def default_start(self, fields):
pool = Pool()
ResultsDetail = pool.get('lims.results_report.version.detail')
detail = ResultsDetail(Transaction().context['active_id'])
attachments = self.get_attachments(detail)
return {'attachment_domain': [a.id for a in attachments]}
def _get_resource(self, obj):
return '%s,%s' % (obj.__name__, obj.id)
def get_attachments(self, detail):
pool = Pool()
Attachment = pool.get('ir.attachment')
resources = []
resources.append(self._get_resource(detail))
for sample in detail.samples:
resources.append(self._get_resource(sample))
resources.append(self._get_resource(sample.notebook))
resources.append(self._get_resource(sample.notebook.fraction))
resources.append(self._get_resource(
sample.notebook.fraction.sample))
resources.append(self._get_resource(
sample.notebook.fraction.sample.entry))
for line in sample.notebook_lines:
if not line.notebook_line:
continue
resources.append(self._get_resource(line))
resources.append(self._get_resource(line.notebook_line))
attachments = Attachment.search([
('resource', 'in', resources),
])
return attachments
def transition_relate(self):
pool = Pool()
ResultsDetailSection = pool.get(
'lims.results_report.version.detail.section')
detail_id = Transaction().context['active_id']
defaults = {
'version_detail': detail_id,
'position': self.start.position,
'name': self.start.attachment.name,
'data': self.start.attachment.data,
'data_id': self.start.attachment.file_id,
'order': None,
}
ResultsDetailSection.create([defaults])
return 'end'
def end(self):
return 'reload'
class ResultsReportVersionDetailSample(metaclass=PoolMeta):
__name__ = 'lims.results_report.version.detail.sample'

View File

@ -15,6 +15,16 @@
<field name="name">results_report_version_detail_form</field>
</record>
<record model="ir.model.button" id="results_report_version_detail_relate_attachment_button">
<field name="name">relate_attachment</field>
<field name="model" search="[('model', '=', 'lims.results_report.version.detail')]"/>
</record>
<record model="ir.model.button-res.group"
id="results_report_version_detail_relate_attachment_button_group_lims_laboratory_reports">
<field name="button" ref="results_report_version_detail_relate_attachment_button"/>
<field name="group" ref="lims.group_lims_laboratory_reports"/>
</record>
<!-- Results Report Version Detail Section -->
<record model="ir.ui.view" id="results_report_version_detail_section_view_form">
@ -41,6 +51,19 @@
<field name="name">results_report_version_detail_chart_list</field>
</record>
<!-- Wizard Relate Attachment to Results Report -->
<record model="ir.ui.view" id="results_report_version_detail_relate_attachment_start_form">
<field name="model">lims.results_report.version.detail.relate_attachment.start</field>
<field name="type">form</field>
<field name="name">results_report_version_detail_relate_attachment_form</field>
</record>
<record model="ir.action.wizard" id="wiz_results_report_version_detail_relate_attachment">
<field name="name">Relate Attachment to Results Report</field>
<field name="wiz_name">lims.results_report.version.detail.relate_attachment</field>
</record>
<!-- Results Report -->
<record model="ir.action.report" id="report_result_report_html">

View File

@ -25,6 +25,7 @@
<field name="template_type" colspan="4" invisible="1"/>
</page>
<page name="sections">
<button name="relate_attachment" colspan="4" string="Relate Attachment"/>
<field name="previous_sections" colspan="4"/>
<field name="following_sections" colspan="4"/>
</page>

View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<form>
<label name="position"/>
<field name="position"/>
<label name="attachment"/>
<field name="attachment"/>
</form>