Added UserError to check if parameters are in domain or python expression of filter.
This commit is contained in:
parent
0c4968af65
commit
fafd1b06b8
51
babi.py
51
babi.py
|
@ -669,6 +669,8 @@ class Report(ModelSQL, ModelView):
|
|||
'invisible': Bool(~Eval('email')),
|
||||
'required': Bool(Eval('email')),
|
||||
}, depends=['email'])
|
||||
babi_raise_user_error = fields.Boolean('Raise User Error',
|
||||
help='Will raise a UserError in case of error in report.')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
|
@ -1294,7 +1296,14 @@ class ReportExecution(ModelSQL, ModelView):
|
|||
if not value or filter_name not in expression:
|
||||
continue
|
||||
values[filter_name] = value
|
||||
expression = expression.format(**values)
|
||||
try:
|
||||
expression = expression.format(**values)
|
||||
except KeyError as message:
|
||||
if self.report.babi_raise_user_error:
|
||||
raise UserError(
|
||||
gettext('babi.invalid_parameters',
|
||||
key=str(message)))
|
||||
raise
|
||||
return expression
|
||||
|
||||
def get_python_filter(self):
|
||||
|
@ -1403,7 +1412,16 @@ class ReportExecution(ModelSQL, ModelView):
|
|||
return str(x)
|
||||
|
||||
with transaction.set_context(_datetime=None):
|
||||
records = Model.search(domain, offset=index * offset, limit=offset)
|
||||
try:
|
||||
records = Model.search(domain, offset=index * offset,
|
||||
limit=offset)
|
||||
except Exception as message:
|
||||
if self.report.babi_raise_user_error:
|
||||
raise UserError(gettext(
|
||||
'babi.create_data_exception',
|
||||
error=repr(message)))
|
||||
raise
|
||||
|
||||
while records:
|
||||
checker.check()
|
||||
logger.info('Calculated %s, %s records in %s seconds'
|
||||
|
@ -1419,10 +1437,31 @@ class ReportExecution(ModelSQL, ModelView):
|
|||
convert_none=False):
|
||||
continue
|
||||
vals = ['now()', str(uid)]
|
||||
vals += [sanitanize(babi_eval(x[0], record, convert_none=x[1]))
|
||||
for x in dimension_expressions]
|
||||
vals += [sanitanize(babi_eval(x, record, convert_none='zero'))
|
||||
for x in measure_expressions]
|
||||
for x in dimension_expressions:
|
||||
try:
|
||||
vals.append(sanitanize(babi_eval(x[0], record,
|
||||
convert_none=x[1])))
|
||||
except Exception as message:
|
||||
if self.report.babi_raise_user_error:
|
||||
raise UserError(gettext(
|
||||
'babi.create_data_exception_dimension',
|
||||
expression=x[0],
|
||||
record=record.id,
|
||||
error=repr(message)))
|
||||
raise
|
||||
for x in measure_expressions:
|
||||
try:
|
||||
vals.append(sanitanize(babi_eval(x, record,
|
||||
convert_none='zero')))
|
||||
except Exception as message:
|
||||
if self.report.babi_raise_user_error:
|
||||
raise UserError(gettext(
|
||||
'babi.create_data_exception_measures',
|
||||
expression=x,
|
||||
record=record.id,
|
||||
error=repr(message)))
|
||||
raise
|
||||
|
||||
record = '|'.join(vals).replace('\n', ' ')
|
||||
record.replace('\\', '')
|
||||
record += '\n'
|
||||
|
|
36
locale/ca.po
36
locale/ca.po
|
@ -278,6 +278,10 @@ msgctxt "field:babi.report,actions:"
|
|||
msgid "Actions"
|
||||
msgstr "Accions"
|
||||
|
||||
msgctxt "field:babi.report,babi_raise_user_error:"
|
||||
msgid "Raise User Error"
|
||||
msgstr "Mostrar l'error a l'usuari"
|
||||
|
||||
msgctxt "field:babi.report,columns:"
|
||||
msgid "Dimensions on Columns"
|
||||
msgstr "Dimensions en columnes"
|
||||
|
@ -544,6 +548,10 @@ msgctxt "help:babi.measure,width:"
|
|||
msgid "Width report columns (%)"
|
||||
msgstr "Amplada de les columnes de l'informe (%)"
|
||||
|
||||
msgctxt "help:babi.report,babi_raise_user_error:"
|
||||
msgid "Will raise a UserError in case of error in report."
|
||||
msgstr "Es generarà un error a l'usuari en cas d'error a l'informe."
|
||||
|
||||
msgctxt "help:babi.report,email:"
|
||||
msgid "Mark to see the options to send an email when executing the cron"
|
||||
msgstr ""
|
||||
|
@ -754,6 +762,26 @@ msgctxt "model:ir.message,text:cannot_remove_order_entry"
|
|||
msgid "Order entries are deleted automatically"
|
||||
msgstr "L'ordre d'entrades es crea automàticament."
|
||||
|
||||
msgctxt "model:ir.message,text:create_data_exception"
|
||||
msgid "An Exception Occurred: %(error)s"
|
||||
msgstr "S'ha produït una excepció: %(error)s"
|
||||
|
||||
msgctxt "model:ir.message,text:create_data_exception_dimension"
|
||||
msgid ""
|
||||
"An Exception Occurred: On dimensions, with expression %(expression)s on "
|
||||
"record %(record)s.\\nException: %(error)s"
|
||||
msgstr ""
|
||||
"S'ha produït una excepció: a les dimensions, amb l'expressió %(expression)s "
|
||||
"al registre %(record)s.\\nExcepció: %(error)s"
|
||||
|
||||
msgctxt "model:ir.message,text:create_data_exception_measures"
|
||||
msgid ""
|
||||
"An Exception Occurred: On measures, with expression %(expression)s on record "
|
||||
"%(record)s.\\nException: %(error)s"
|
||||
msgstr ""
|
||||
"S'ha produït una excepció: a les mesures, amb l'expressió %(expression)s al "
|
||||
"registre %(record)s.\\nExcepció: %(error)s"
|
||||
|
||||
msgctxt "model:ir.message,text:false"
|
||||
msgid "False"
|
||||
msgstr "Fals"
|
||||
|
@ -766,6 +794,14 @@ msgstr ""
|
|||
"L'execució \"%(execution)s\" té paràmetres de filtre i vostè no va "
|
||||
"proporcionar cap d'ells. Si us plau executa-ho des del menú."
|
||||
|
||||
msgctxt "model:ir.message,text:invalid_parameters"
|
||||
msgid ""
|
||||
"Key \"%(key)s\" in domain or in python expression is not in the parameters "
|
||||
"from filter of report."
|
||||
msgstr ""
|
||||
"La clau \"%(key)s\" al domini o a l'expressió de python no es troba als "
|
||||
"paràmetres del filtre de l'informe."
|
||||
|
||||
msgctxt "model:ir.message,text:no_dimensions"
|
||||
msgid "Report \"%(report)s\" has no dimensions. At least one is needed."
|
||||
msgstr "L'informe \"%(report)s\" no té dimensions. Al menys un és necessari."
|
||||
|
|
36
locale/es.po
36
locale/es.po
|
@ -278,6 +278,10 @@ msgctxt "field:babi.report,actions:"
|
|||
msgid "Actions"
|
||||
msgstr "Acciones"
|
||||
|
||||
msgctxt "field:babi.report,babi_raise_user_error:"
|
||||
msgid "Raise User Error"
|
||||
msgstr "Mostrar el error al usuario"
|
||||
|
||||
msgctxt "field:babi.report,columns:"
|
||||
msgid "Dimensions on Columns"
|
||||
msgstr "Dimensiones en columnas"
|
||||
|
@ -544,6 +548,10 @@ msgctxt "help:babi.measure,width:"
|
|||
msgid "Width report columns (%)"
|
||||
msgstr "Ancho de las columnas del informe (%)"
|
||||
|
||||
msgctxt "help:babi.report,babi_raise_user_error:"
|
||||
msgid "Will raise a UserError in case of error in report."
|
||||
msgstr "Generará un error al usuario en caso de error en el informe."
|
||||
|
||||
msgctxt "help:babi.report,email:"
|
||||
msgid "Mark to see the options to send an email when executing the cron"
|
||||
msgstr ""
|
||||
|
@ -754,6 +762,26 @@ msgctxt "model:ir.message,text:cannot_remove_order_entry"
|
|||
msgid "Order entries are deleted automatically"
|
||||
msgstr "El orden de entradas se crea automáticamente."
|
||||
|
||||
msgctxt "model:ir.message,text:create_data_exception"
|
||||
msgid "An Exception Occurred: %(error)s"
|
||||
msgstr "Se ha producido una excepción: %(error)s"
|
||||
|
||||
msgctxt "model:ir.message,text:create_data_exception_dimension"
|
||||
msgid ""
|
||||
"An Exception Occurred: On dimensions, with expression %(expression)s on "
|
||||
"record %(record)s.\\nException: %(error)s"
|
||||
msgstr ""
|
||||
"Se ha producido una excepción: en las dimensiones, con la expresión "
|
||||
"%(expression)s en el registro %(record)s.\\nExcepción: %(error)s"
|
||||
|
||||
msgctxt "model:ir.message,text:create_data_exception_measures"
|
||||
msgid ""
|
||||
"An Exception Occurred: On measures, with expression %(expression)s on record "
|
||||
"%(record)s.\\nException: %(error)s"
|
||||
msgstr ""
|
||||
"Se ha producido una excepción: en las medidas, con la expresión "
|
||||
"%(expression)s en el registro %(record)s.\\nExcepción: %(error)s"
|
||||
|
||||
msgctxt "model:ir.message,text:false"
|
||||
msgid "False"
|
||||
msgstr "Falso"
|
||||
|
@ -766,6 +794,14 @@ msgstr ""
|
|||
"La ejecución \"%(execution)s\" tiene parámetros de filtro y usted no "
|
||||
"proporcionó ninguno de ellos. Por favor ejecutalo desde el menu."
|
||||
|
||||
msgctxt "model:ir.message,text:invalid_parameters"
|
||||
msgid ""
|
||||
"Key \"%(key)s\" in domain or in python expression is not in the parameters "
|
||||
"from filter of report."
|
||||
msgstr ""
|
||||
"La clave \"%(key)s\" en el dominio o en la expresión de python no se "
|
||||
"encuentra en los parámetros del filtro del informe."
|
||||
|
||||
msgctxt "model:ir.message,text:no_dimensions"
|
||||
msgid "Report \"%(report)s\" has no dimensions. At least one is needed."
|
||||
msgstr "El informe \"%(report)s\" no tiene dimensiones. Al menos se necesita uno."
|
||||
|
|
14
messages.xml
14
messages.xml
|
@ -48,5 +48,19 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<record model="ir.message" id="false">
|
||||
<field name="text">False</field>
|
||||
</record>
|
||||
<record model="ir.message" id="create_data_exception">
|
||||
<field name="text">An Exception Occurred: %(error)s</field>
|
||||
</record>
|
||||
<record model="ir.message" id="create_data_exception_measures">
|
||||
<field name="text">An Exception Occurred: On measures, with expression %(expression)s on record %(record)s.
|
||||
Exception: %(error)s</field>
|
||||
</record>
|
||||
<record model="ir.message" id="create_data_exception_dimension">
|
||||
<field name="text">An Exception Occurred: On dimensions, with expression %(expression)s on record %(record)s.
|
||||
Exception: %(error)s</field>
|
||||
</record>
|
||||
<record model="ir.message" id="invalid_parameters">
|
||||
<field name="text">Key "%(key)s" in domain or in python expression is not in the parameters from filter of report.</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
|
@ -10,6 +10,8 @@ contains the full copyright notices and license terms. -->
|
|||
<field name="parent_menu" colspan="3"/>
|
||||
<label name="filter"/>
|
||||
<field name="filter" colspan="3"/>
|
||||
<label name="babi_raise_user_error"/>
|
||||
<field name="babi_raise_user_error"/>
|
||||
<notebook>
|
||||
<page id="general" string="General">
|
||||
<group col="1" colspan="2" id="dimensions" yfill="1" yexpand="1">
|
||||
|
|
Loading…
Reference in New Issue