lims_email: add format for results report name
This commit is contained in:
parent
22868d6c65
commit
58cf0b188e
|
@ -4,6 +4,7 @@
|
|||
|
||||
from trytond.pool import Pool
|
||||
from . import configuration
|
||||
from . import party
|
||||
from . import results_report
|
||||
|
||||
|
||||
|
@ -17,6 +18,8 @@ def register():
|
|||
results_report.SendResultsReportStart,
|
||||
results_report.SendResultsReportSucceed,
|
||||
results_report.SendResultsReportFailed,
|
||||
results_report.ReportNameFormat,
|
||||
party.Party,
|
||||
module='lims_email', type_='model')
|
||||
Pool.register(
|
||||
results_report.ResultsReportAnnulation,
|
||||
|
|
|
@ -20,6 +20,8 @@ class Configuration(metaclass=PoolMeta):
|
|||
' results report',
|
||||
help='<SAMPLES> will be replaced by the list of sample\'s labels')
|
||||
mail_ack_report_hide_recipients = fields.Boolean('Hide recipients')
|
||||
result_report_format = fields.Many2One('lims.result_report.format',
|
||||
'Default Results Report Name Format')
|
||||
|
||||
@staticmethod
|
||||
def default_mail_ack_report_grouping():
|
||||
|
|
|
@ -18,6 +18,18 @@ msgctxt "field:lims.configuration,mail_ack_report_subject:"
|
|||
msgid "Email subject of Acknowledgment of results report"
|
||||
msgstr "Asunto del correo de Acuse de informe de resultados"
|
||||
|
||||
msgctxt "field:lims.configuration,result_report_format:"
|
||||
msgid "Default Results Report Name Format"
|
||||
msgstr "Formato de nombre para Informe de resultados"
|
||||
|
||||
msgctxt "field:lims.result_report.format,format_:"
|
||||
msgid "Format"
|
||||
msgstr "Formato"
|
||||
|
||||
msgctxt "field:lims.result_report.format,name:"
|
||||
msgid "Name"
|
||||
msgstr "Nombre"
|
||||
|
||||
msgctxt "field:lims.results_report,mailings:"
|
||||
msgid "Mailings"
|
||||
msgstr "Envíos"
|
||||
|
@ -54,6 +66,10 @@ msgctxt "field:lims_email.send_results_report.start,summary:"
|
|||
msgid "Summary"
|
||||
msgstr "Resumen"
|
||||
|
||||
msgctxt "field:party.party,result_report_format:"
|
||||
msgid "Results Report Name Format"
|
||||
msgstr "Formato de nombre para Informe de resultados"
|
||||
|
||||
msgctxt "help:lims.configuration,mail_ack_report_body:"
|
||||
msgid "<SAMPLES> will be replaced by the list of sample's labels"
|
||||
msgstr "<SAMPLES> será reemplazado por la lista de rótulos de las muestras"
|
||||
|
@ -62,18 +78,46 @@ msgctxt "help:lims.configuration,mail_ack_report_subject:"
|
|||
msgid "In the text will be added suffix with the results report number"
|
||||
msgstr "En el texto se añadirá sufijo con el número del informe de resultados"
|
||||
|
||||
msgctxt "help:lims.result_report.format,format_:"
|
||||
msgid ""
|
||||
"Available variables (also in upper case):\n"
|
||||
"- ${number}\n"
|
||||
"- ${sample_number}\n"
|
||||
"- ${party_name}"
|
||||
msgstr ""
|
||||
"Variables disponibles (también en mayúsculas):\n"
|
||||
"- ${number}\n"
|
||||
"- ${sample_number}\n"
|
||||
"- ${party_name}"
|
||||
|
||||
msgctxt "model:ir.action,name:act_results_report_format"
|
||||
msgid "Results Report Name Formats"
|
||||
msgstr "Formatos de nombre para Informe de resultados"
|
||||
|
||||
msgctxt "model:ir.action,name:wizard_send_results_report"
|
||||
msgid "Send Results Reports"
|
||||
msgstr "Enviar Informes de resultados"
|
||||
|
||||
msgctxt "model:ir.message,text:msg_invalid_report_name"
|
||||
msgid "Invalid format \"%(format)s\" with exception \"%(exception)s\"."
|
||||
msgstr "El formato \"%(format)s\" es inválido con la excepción \"%(exception)s\"."
|
||||
|
||||
msgctxt "model:ir.message,text:msg_polisample"
|
||||
msgid "Polisample"
|
||||
msgstr "Polimuestra"
|
||||
|
||||
msgctxt "model:ir.ui.menu,name:menu_results_report_format"
|
||||
msgid "Results Report Name Formats"
|
||||
msgstr "Formatos de nombre para Informe de resultados"
|
||||
|
||||
msgctxt "model:ir.ui.menu,name:menu_send_results_report"
|
||||
msgid "Send Results Reports"
|
||||
msgstr "Enviar Informes de resultados"
|
||||
|
||||
msgctxt "model:lims.result_report.format,name:"
|
||||
msgid "Results Report Name Format"
|
||||
msgstr "Formato de nombre para Informe de resultados"
|
||||
|
||||
msgctxt "model:lims.results_report.mailing,name:"
|
||||
msgid "Results Report Mailing"
|
||||
msgstr "Envío de Informe de resultados"
|
||||
|
|
|
@ -4,5 +4,8 @@
|
|||
<record model="ir.message" id="msg_polisample">
|
||||
<field name="text">Polisample</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_invalid_report_name">
|
||||
<field name="text">Invalid format "%(format)s" with exception "%(exception)s".</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
# This file is part of lims_email 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_report_format = fields.Many2One('lims.result_report.format',
|
||||
'Results Report Name Format')
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0"?>
|
||||
<tryton>
|
||||
<data>
|
||||
|
||||
<!-- Party -->
|
||||
|
||||
<record model="ir.ui.view" id="lims_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>
|
|
@ -8,6 +8,7 @@ from email.mime.base import MIMEBase
|
|||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.application import MIMEApplication
|
||||
from PyPDF2 import PdfFileMerger
|
||||
from string import Template
|
||||
|
||||
from trytond.model import ModelSQL, ModelView, fields
|
||||
from trytond.wizard import Wizard, StateView, StateTransition, Button
|
||||
|
@ -15,6 +16,7 @@ from trytond.pool import Pool, PoolMeta
|
|||
from trytond.transaction import Transaction
|
||||
from trytond.tools import get_smtp_server
|
||||
from trytond.config import config as tconfig
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.i18n import gettext
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -197,9 +199,37 @@ class ResultsReport(metaclass=PoolMeta):
|
|||
|
||||
def _get_attached_report_filename(self, english_report=False):
|
||||
suffix = 'eng' if english_report else 'esp'
|
||||
filename = str(self.number) + '-' + suffix
|
||||
#filename = str(self.number) + '-' + suffix
|
||||
filename = self.get_report_filename() + '-' + suffix
|
||||
return filename
|
||||
|
||||
def get_report_filename(self):
|
||||
pool = Pool()
|
||||
ReportNameFormat = pool.get('lims.result_report.format')
|
||||
report_name = Template(ReportNameFormat.get_format(self)).substitute(
|
||||
**self._get_name_substitutions())
|
||||
return report_name.strip()
|
||||
|
||||
def _get_name_substitutions(self):
|
||||
pool = Pool()
|
||||
ResultsSample = pool.get('lims.results_report.version.detail.sample')
|
||||
|
||||
samples = ResultsSample.search([
|
||||
('version_detail.report_version.results_report',
|
||||
'=', self.id),
|
||||
], order=[('id', 'ASC')], limit=1)
|
||||
sample = samples and samples[0] or None
|
||||
|
||||
substitutions = {
|
||||
'number': getattr(self, 'number', None) or '',
|
||||
'sample_number': (sample and
|
||||
sample.notebook.fraction.sample.number or ''),
|
||||
'party_name': sample and sample.party.rec_name or '',
|
||||
}
|
||||
for key, value in list(substitutions.items()):
|
||||
substitutions[key.upper()] = value.upper()
|
||||
return substitutions
|
||||
|
||||
|
||||
class ResultsReportMailing(ModelSQL, ModelView):
|
||||
'Results Report Mailing'
|
||||
|
@ -627,3 +657,50 @@ class SendResultsReport(Wizard):
|
|||
'reports_not_sent': [f.id for f in self.failed.reports_not_sent],
|
||||
}
|
||||
return default
|
||||
|
||||
|
||||
class ReportNameFormat(ModelSQL, ModelView):
|
||||
'Results Report Name Format'
|
||||
__name__ = 'lims.result_report.format'
|
||||
|
||||
name = fields.Char('Name')
|
||||
format_ = fields.Char('Format', required=True,
|
||||
help=("Available variables (also in upper case):"
|
||||
"\n- ${number}"
|
||||
"\n- ${sample_number}"
|
||||
"\n- ${party_name}"))
|
||||
|
||||
@classmethod
|
||||
def default_format_(cls):
|
||||
return '${number}'
|
||||
|
||||
@classmethod
|
||||
def validate(cls, formats):
|
||||
super().validate(formats)
|
||||
for format_ in formats:
|
||||
format_.check_format()
|
||||
|
||||
def check_format(self):
|
||||
pool = Pool()
|
||||
ResultsReport = pool.get('lims.results_report')
|
||||
report = ResultsReport()
|
||||
try:
|
||||
Template(self.format_).substitute(
|
||||
**report._get_name_substitutions())
|
||||
except Exception as exception:
|
||||
raise UserError(gettext('lims_email.msg_invalid_report_name',
|
||||
format=self.format_,
|
||||
exception=exception)) from exception
|
||||
|
||||
@classmethod
|
||||
def get_format(cls, results_report):
|
||||
Config = Pool().get('lims.configuration')
|
||||
|
||||
if results_report.party.result_report_format:
|
||||
return results_report.party.result_report_format.format_
|
||||
|
||||
config_ = Config(1)
|
||||
if config_.result_report_format:
|
||||
return config_.result_report_format.format_
|
||||
|
||||
return cls.default_format_()
|
||||
|
|
|
@ -91,5 +91,38 @@
|
|||
<field name="group" ref="group_lims_send_results_report"/>
|
||||
</record>
|
||||
|
||||
<!-- Results Report Name Format -->
|
||||
|
||||
<record model="ir.ui.view" id="results_report_format_view_list">
|
||||
<field name="model">lims.result_report.format</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="name">results_report_format_list</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="results_report_format_view_form">
|
||||
<field name="model">lims.result_report.format</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">results_report_format_form</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.act_window" id="act_results_report_format">
|
||||
<field name="name">Results Report Name Formats</field>
|
||||
<field name="res_model">lims.result_report.format</field>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view" id="act_results_report_format_view_form">
|
||||
<field name="sequence" eval="10"/>
|
||||
<field name="view" ref="results_report_format_view_list"/>
|
||||
<field name="act_window" ref="act_results_report_format"/>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view" id="act_results_report_format_view_list">
|
||||
<field name="sequence" eval="20"/>
|
||||
<field name="view" ref="results_report_format_view_form"/>
|
||||
<field name="act_window" ref="act_results_report_format"/>
|
||||
</record>
|
||||
|
||||
<menuitem action="act_results_report_format"
|
||||
id="menu_results_report_format"
|
||||
parent="lims.lims_config_report" sequence="30"/>
|
||||
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
|
@ -6,4 +6,5 @@ xml:
|
|||
user.xml
|
||||
configuration.xml
|
||||
results_report.xml
|
||||
party.xml
|
||||
message.xml
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
<data>
|
||||
<xpath expr="/form/notebook/page[@id='general']" position="after">
|
||||
<page string="Mail Acknowledgment Report" id="mail_ack_report">
|
||||
<label name="result_report_format"/>
|
||||
<field name="result_report_format"/>
|
||||
<label name="mail_ack_report_grouping"/>
|
||||
<field name="mail_ack_report_grouping"/>
|
||||
<label name="mail_ack_report_hide_recipients"/>
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0"?>
|
||||
<data>
|
||||
<xpath
|
||||
expr="/form/notebook/page[@id='lims']/field[@name='entry_zone']"
|
||||
position="after">
|
||||
<label name="result_report_format"/>
|
||||
<field name="result_report_format"/>
|
||||
</xpath>
|
||||
</data>
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0"?>
|
||||
<form>
|
||||
<label name="name"/>
|
||||
<field name="name"/>
|
||||
<separator name="format_" colspan="4"/>
|
||||
<field name="format_" colspan="4"/>
|
||||
</form>
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0"?>
|
||||
<tree>
|
||||
<field name="name"/>
|
||||
</tree>
|
Loading…
Reference in New Issue