lims: add 'Single sending of report per Entry' option

This commit is contained in:
Adrián Bernardi 2022-03-10 11:55:14 -03:00
parent 0a81ea0e86
commit d21db3cb24
8 changed files with 123 additions and 25 deletions

View file

@ -89,8 +89,10 @@ class Entry(Workflow, ModelSQL, ModelView):
'Package state')
packages_quantity = fields.Integer('Packages quantity')
email_report = fields.Boolean('Email report')
single_sending_report = fields.Boolean('Single sending of report',
select=True)
single_sending_report = fields.Boolean(
'Single sending of report per Sample', select=True)
entry_single_sending_report = fields.Boolean(
'Single sending of report per Entry', select=True)
report_language = fields.Many2One('ir.lang',
'Results Report Language', required=True,
domain=[('translatable', '=', True)])
@ -221,6 +223,10 @@ class Entry(Workflow, ModelSQL, ModelView):
def default_single_sending_report():
return False
@staticmethod
def default_entry_single_sending_report():
return False
@staticmethod
def default_report_language():
Config = Pool().get('lims.configuration')
@ -298,6 +304,7 @@ class Entry(Workflow, ModelSQL, ModelView):
report_language = None
email = False
single_sending = False
entry_single_sending = False
no_ack = False
invoice_contacts = []
@ -331,6 +338,7 @@ class Entry(Workflow, ModelSQL, ModelView):
report_language = self.party.report_language
email = self.party.email_report
single_sending = self.party.single_sending_report
entry_single_sending = self.party.entry_single_sending_report
no_ack = self.party.no_acknowledgment_of_receipt
if self.party.addresses:
@ -349,6 +357,7 @@ class Entry(Workflow, ModelSQL, ModelView):
self.report_language = report_language
self.email_report = email
self.single_sending_report = single_sending
self.entry_single_sending_report = entry_single_sending
self.no_acknowledgment_of_receipt = no_ack
self.invoice_contacts = invoice_contacts

View file

@ -1323,6 +1323,10 @@ msgctxt "field:lims.entry,email_report:"
msgid "Email report"
msgstr "Informe por e-mail"
msgctxt "field:lims.entry,entry_single_sending_report:"
msgid "Single sending of report per Entry"
msgstr "Envío único de Informe por Partida"
msgctxt "field:lims.entry,icon:"
msgid "Icon"
msgstr "Icono"
@ -1408,8 +1412,8 @@ msgid "Sent date"
msgstr "Fecha de enviado"
msgctxt "field:lims.entry,single_sending_report:"
msgid "Single sending of report"
msgstr "Envío único de Informe"
msgid "Single sending of report per Sample"
msgstr "Envío único de Informe por Muestra"
msgctxt "field:lims.entry,state:"
msgid "State"
@ -4867,6 +4871,14 @@ msgctxt "field:lims.results_report,entry:"
msgid "Entry"
msgstr "Ingreso"
msgctxt "field:lims.results_report,entry_single_sending_report:"
msgid "Single sending per Entry"
msgstr "Envío único por Partida"
msgctxt "field:lims.results_report,entry_single_sending_report_ready:"
msgid "Single sending per Entry Ready"
msgstr "Listo para Envío único por Partida"
msgctxt "field:lims.results_report,generation_type:"
msgid "Generation type"
msgstr "Tipo de generación"
@ -4916,12 +4928,12 @@ msgid "Samples"
msgstr "Muestras"
msgctxt "field:lims.results_report,single_sending_report:"
msgid "Single sending"
msgstr "Envío único"
msgid "Single sending per Sample"
msgstr "Envío único por Muestra"
msgctxt "field:lims.results_report,single_sending_report_ready:"
msgid "Single sending Ready"
msgstr "Listo para Envío único"
msgid "Single sending per Sample Ready"
msgstr "Listo para Envío único por Muestra"
msgctxt "field:lims.results_report,versions:"
msgid "Laboratories"
@ -6495,6 +6507,10 @@ msgctxt "field:party.party,email_report:"
msgid "Email report"
msgstr "Informe por e-mail"
msgctxt "field:party.party,entry_single_sending_report:"
msgid "Single sending of report per Entry"
msgstr "Envío único de Informe por Partida"
msgctxt "field:party.party,entry_zone:"
msgid "Entry Zone"
msgstr "Zona de Ingreso"
@ -6520,8 +6536,8 @@ msgid "Sample Producers"
msgstr "Productores de muestra"
msgctxt "field:party.party,single_sending_report:"
msgid "Single sending of report"
msgstr "Envío único de Informe"
msgid "Single sending of report per Sample"
msgstr "Envío único de Informe por Muestra"
msgctxt "field:product.uom,maximum_concentration:"
msgid "Maximum concentration"

View file

@ -16,7 +16,10 @@ class Party(metaclass=PoolMeta):
__name__ = 'party.party'
email_report = fields.Boolean('Email report')
single_sending_report = fields.Boolean('Single sending of report')
single_sending_report = fields.Boolean(
'Single sending of report per Sample')
entry_single_sending_report = fields.Boolean(
'Single sending of report per Entry')
report_language = fields.Many2One('ir.lang',
'Results Report Language',
domain=[('translatable', '=', True)])
@ -86,6 +89,10 @@ class Party(metaclass=PoolMeta):
def default_single_sending_report():
return False
@staticmethod
def default_entry_single_sending_report():
return False
@staticmethod
def default_report_language():
Config = Pool().get('lims.configuration')

View file

@ -43,10 +43,17 @@ class ResultsReport(ModelSQL, ModelView):
report_language = fields.Many2One('ir.lang', 'Language', required=True,
domain=[('translatable', '=', True)])
single_sending_report = fields.Function(fields.Boolean(
'Single sending'), 'get_entry_field',
'Single sending per Sample'), 'get_entry_field',
searcher='search_entry_field')
single_sending_report_ready = fields.Function(fields.Boolean(
'Single sending Ready'), 'get_single_sending_report_ready')
'Single sending per Sample Ready'),
'get_single_sending_report_ready')
entry_single_sending_report = fields.Function(fields.Boolean(
'Single sending per Entry'), 'get_entry_field',
searcher='search_entry_field')
entry_single_sending_report_ready = fields.Function(fields.Boolean(
'Single sending per Entry Ready'),
'get_entry_single_sending_report_ready')
ready_to_send = fields.Function(fields.Boolean(
'Ready to Send'), 'get_ready_to_send',
searcher='search_ready_to_send')
@ -247,6 +254,42 @@ class ResultsReport(ModelSQL, ModelView):
result[r.id] = True
return result
@classmethod
def get_entry_single_sending_report_ready(cls, reports, name):
cursor = Transaction().connection.cursor()
pool = Pool()
EntryDetailAnalysis = pool.get('lims.entry.detail.analysis')
NotebookLine = pool.get('lims.notebook.line')
Service = pool.get('lims.service')
Fraction = pool.get('lims.fraction')
Sample = pool.get('lims.sample')
result = {}
for r in reports:
result[r.id] = False
if not r.entry_single_sending_report:
continue
cursor.execute('SELECT COUNT(*) '
'FROM "' + EntryDetailAnalysis._table + '" ad '
'INNER JOIN "' + NotebookLine._table + '" nl '
'ON ad.id = nl.analysis_detail '
'INNER JOIN "' + Service._table + '" srv '
'ON srv.id = nl.service '
'INNER JOIN "' + Fraction._table + '" f '
'ON f.id = srv.fraction '
'INNER JOIN "' + Sample._table + '" s '
'ON s.id = f.sample '
'WHERE s.entry = %s '
'AND ad.report_grouper = %s '
'AND nl.report = TRUE '
'AND nl.annulled = FALSE '
'AND nl.results_report IS NULL',
(r.entry.id, r.report_grouper,))
if cursor.fetchone()[0] > 0:
continue
result[r.id] = True
return result
@classmethod
def get_ready_to_send(cls, reports, name):
result = {}
@ -254,6 +297,9 @@ class ResultsReport(ModelSQL, ModelView):
result[r.id] = False
if r.single_sending_report and not r.single_sending_report_ready:
continue
if (r.entry_single_sending_report and
not r.entry_single_sending_report_ready):
continue
if not r.has_report_cached(r.report_language):
continue
result[r.id] = True
@ -274,12 +320,17 @@ class ResultsReport(ModelSQL, ModelView):
'FROM "' + ResultsReport._table + '" r '
'INNER JOIN "' + Entry._table + '" e '
'ON r.entry = e.id '
'WHERE e.single_sending_report = TRUE')
'WHERE e.single_sending_report = TRUE '
'OR e.entry_single_sending_report = TRUE')
single_sending_ids = [x[0] for x in cursor.fetchall()]
with Transaction().set_user(0):
for report in ResultsReport.browse(single_sending_ids):
if not report.single_sending_report_ready:
excluded_ids.append(report.id)
for r in ResultsReport.browse(single_sending_ids):
if (r.single_sending_report and
not r.single_sending_report_ready):
excluded_ids.append(r.id)
if (r.entry_single_sending_report and
not r.entry_single_sending_report_ready):
excluded_ids.append(r.id)
excluded_ids = ', '.join(str(r) for r in [0] + excluded_ids)
cursor.execute('SELECT rr.id '

View file

@ -10,13 +10,15 @@
<field name="invoice_party"/>
<notebook>
<page string="General" id="general">
<group col="8" colspan="4" id="options_holder">
<group col="10" colspan="4" id="options_holder">
<label name="report_language"/>
<field name="report_language" widget="selection"/>
<label name="email_report"/>
<field name="email_report" xexpand="0" width="25"/>
<label name="single_sending_report"/>
<field name="single_sending_report" xexpand="0" width="25"/>
<label name="entry_single_sending_report"/>
<field name="entry_single_sending_report" xexpand="0" width="25"/>
<label name="no_acknowledgment_of_receipt"/>
<field name="no_acknowledgment_of_receipt" xexpand="0" width="25"/>
</group>

View file

@ -9,6 +9,8 @@
<field name="email_report"/>
<label name="single_sending_report"/>
<field name="single_sending_report"/>
<label name="entry_single_sending_report"/>
<field name="entry_single_sending_report"/>
<label name="no_acknowledgment_of_receipt"/>
<field name="no_acknowledgment_of_receipt"/>
</group>

View file

@ -6,17 +6,21 @@
<field name="party"/>
<label name="report_language"/>
<field name="report_language" widget="selection"/>
<group col="6" colspan="2" id="fields_group">
<label name="single_sending_report"/>
<field name="single_sending_report" xexpand="0" width="25"/>
<label name="single_sending_report_ready"/>
<field name="single_sending_report_ready" xexpand="0" width="25"/>
</group>
<group col="6" colspan="4" id="fields_group2">
<group col="4" colspan="2" id="fields_group2">
<label name="create_date2"/>
<field name="create_date2"/>
<label name="write_date2"/>
<field name="write_date2"/>
</group>
<group col="8" colspan="4" id="single_sending">
<label name="single_sending_report"/>
<field name="single_sending_report" xexpand="0" width="25"/>
<label name="single_sending_report_ready"/>
<field name="single_sending_report_ready" xexpand="0" width="25"/>
<label name="entry_single_sending_report"/>
<field name="entry_single_sending_report" xexpand="0" width="25"/>
<label name="entry_single_sending_report_ready"/>
<field name="entry_single_sending_report_ready" xexpand="0" width="25"/>
</group>
<field name="versions" colspan="4"/>
</form>

View file

@ -378,6 +378,13 @@ class SendResultsReport(Wizard):
report.number)
continue
if (report.entry_single_sending_report and not
report.entry_single_sending_report_ready):
logger.warning('Send Results Report: %s: '
'IGNORED: NOT READY TO SINGLE SENDING',
report.number)
continue
report_cache = {}
for lang in Lang.search([('translatable', '=', True)]):
if not report.has_report_cached(lang):