lims, lims_report_html: results report: store comments in different languages

This commit is contained in:
Adrián Bernardi 2022-01-24 21:50:48 -03:00
parent 71523a526a
commit a40e48d270
6 changed files with 111 additions and 18 deletions

View File

@ -88,6 +88,7 @@ def register():
results_report.ResultsReportVersion,
results_report.ResultsReportVersionDetail,
results_report.ResultsReportCachedReport,
results_report.ResultsReportComment,
results_report.ResultsReportVersionDetailSample,
results_report.ResultsReportVersionDetailLine,
certification.AnalysisFamily,

View File

@ -4912,6 +4912,18 @@ msgctxt "field:lims.results_report.cached_report,version_detail:"
msgid "Report Detail"
msgstr "Detalle de informe"
msgctxt "field:lims.results_report.comment,comments:"
msgid "Comments"
msgstr "Observaciones"
msgctxt "field:lims.results_report.comment,report_language:"
msgid "Language"
msgstr "Idioma"
msgctxt "field:lims.results_report.comment,version_detail:"
msgid "Report Detail"
msgstr "Detalle de informe"
msgctxt "field:lims.results_report.version,details:"
msgid "Detail lines"
msgstr "Líneas de detalle"
@ -9622,6 +9634,10 @@ msgctxt "model:lims.results_report.cached_report,name:"
msgid "Cached Results Report"
msgstr "Informe de resultados cacheados"
msgctxt "model:lims.results_report.comment,name:"
msgid "Results Report Comment"
msgstr "Comentario de Informe de resultados"
msgctxt "model:lims.results_report.version,name:"
msgid "Results Report Version"
msgstr "Versión de informe de resultados"

View File

@ -606,8 +606,9 @@ class ResultsReportVersionDetail(Workflow, ModelSQL, ModelView):
resultrange_origin_domain = fields.Function(fields.Many2Many(
'lims.range.type', None, None, 'Origin domain'),
'on_change_with_resultrange_origin_domain')
comments = fields.Text('Comments', translate=True, depends=_depends,
states={'readonly': ~Eval('state').in_(['draft', 'revised'])})
comments = fields.Function(fields.Text('Comments',
states={'readonly': ~Eval('state').in_(['draft', 'revised'])},
depends=_depends), 'get_comments', setter='set_comments')
fractions_comments = fields.Function(fields.Text('Fractions comments'),
'get_fractions_comments')
cie_fraction_type = fields.Function(fields.Boolean('QA'),
@ -1015,6 +1016,39 @@ class ResultsReportVersionDetail(Workflow, ModelSQL, ModelView):
(self.id, self.report_language.id))
return bool(cursor.fetchone())
def get_comments(self, name):
pool = Pool()
ReportComment = pool.get('lims.results_report.comment')
comments = ReportComment.search([
('version_detail', '=', self.id),
('report_language', '=', self.report_language.id),
])
if comments:
return comments[0].comments
return None
@classmethod
def set_comments(cls, details, name, value):
pool = Pool()
ReportComment = pool.get('lims.results_report.comment')
detail_id = details[0].id
report_language_id = details[0].report_language.id
comments = ReportComment.search([
('version_detail', '=', detail_id),
('report_language', '=', report_language_id),
])
ReportComment.delete(comments)
if not value:
return
ReportComment.create([{
'version_detail': detail_id,
'report_language': report_language_id,
'comments': value,
}])
@classmethod
@ModelView.button
@Workflow.transition('draft')
@ -1621,6 +1655,54 @@ class ResultsReportCachedReport(ModelSQL):
]
class ResultsReportComment(ModelSQL):
'Results Report Comment'
__name__ = 'lims.results_report.comment'
version_detail = fields.Many2One('lims.results_report.version.detail',
'Report Detail', ondelete='CASCADE', select=True, required=True)
report_language = fields.Many2One('ir.lang', 'Language', required=True)
comments = fields.Text('Comments')
@classmethod
def __register__(cls, module_name):
TableHandler = backend.TableHandler
ResultsDetail = Pool().get('lims.results_report.version.detail')
comments_table_exist = TableHandler.table_exist(cls._table)
detail_table_h = ResultsDetail.__table_handler__(module_name)
comments_exist = detail_table_h.column_exist('comments')
super().__register__(module_name)
if comments_exist and not comments_table_exist:
cls._migrate_report_comment()
@classmethod
def _migrate_report_comment(cls):
cursor = Transaction().connection.cursor()
pool = Pool()
ResultsReport = pool.get('lims.results_report')
ResultsVersion = pool.get('lims.results_report.version')
ResultsDetail = pool.get('lims.results_report.version.detail')
table = cls.__table__()
cursor.execute('SELECT rd.id, rr.report_language, rd.comments '
'FROM "' + ResultsDetail._table + '" rd '
'INNER JOIN "' + ResultsVersion._table + '" rv '
'ON rd.report_version = rv.id '
'INNER JOIN "' + ResultsReport._table + '" rr '
'ON rv.results_report = rr.id '
'WHERE rd.comments IS NOT NULL')
res = cursor.fetchall()
if res:
cursor.execute(*table.insert([
table.version_detail,
table.report_language,
table.comments,
], res))
class ResultsReportVersionDetailSample(ModelSQL, ModelView):
'Results Report Version Detail Sample'
__name__ = 'lims.results_report.version.detail.sample'

View File

@ -150,7 +150,7 @@ msgctxt "field:lims.results_report.version.detail,charts_x_row:"
msgid "Charts per Row"
msgstr "Gráficos por fila"
msgctxt "field:lims.results_report.version.detail,comments_plain:"
msgctxt "field:lims.results_report.version.detail,comments_html:"
msgid "Comments"
msgstr "Observaciones"

View File

@ -56,8 +56,9 @@ class ResultsReportVersionDetail(metaclass=PoolMeta):
('1', '1'),
('2', '2'),
], 'Charts per Row')
comments_plain = fields.Function(fields.Text('Comments', translate=True),
'get_comments_plain', setter='set_comments_plain')
comments_html = fields.Function(fields.Text('Comments',
states={'readonly': ~Eval('state').in_(['draft', 'revised'])},
depends=['state']), 'get_comments', setter='set_comments')
@classmethod
def __setup__(cls):
@ -70,10 +71,10 @@ class ResultsReportVersionDetail(metaclass=PoolMeta):
@classmethod
def view_attributes(cls):
return super().view_attributes() + [
('//page[@id="comments"]', 'states', {
('//page[@id="comments_html"]', 'states', {
'invisible': Not(Bool(Eval('template_type'))),
}),
('//page[@id="comments_plain"]', 'states', {
('//page[@id="comments"]', 'states', {
'invisible': Eval('template_type') == 'base',
}),
]
@ -239,13 +240,6 @@ class ResultsReportVersionDetail(metaclass=PoolMeta):
} for s in detail.sections])]
return detail_default
def get_comments_plain(self, name):
return self.comments
@classmethod
def set_comments_plain(cls, records, name, value):
cls.write(records, {'comments': value})
class ResultsReportVersionDetailSection(ModelSQL, ModelView):
'Results Report Version Detail Section'

View File

@ -15,12 +15,12 @@
<field name="template"/>
</xpath>
<xpath expr="/form/notebook/page[@name='comments']" position="replace">
<page id="comments_plain" string="Comments">
<field name="comments_plain" colspan="4" widget="text"/>
<page id="comments" string="Comments">
<field name="comments" colspan="4" widget="text"/>
<field name="template_type" colspan="4" invisible="1"/>
</page>
<page id="comments" string="Comments">
<field name="comments" colspan="4" widget="html"/>
<page id="comments_html" string="Comments">
<field name="comments_html" colspan="4" widget="html"/>
<field name="template_type" colspan="4" invisible="1"/>
</page>
<page name="sections">