mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[IMP] printing_auto_base: log or raise
Select on printing.auto to log or raise errors
This commit is contained in:
committed by
Jacques-Etienne Baudoux
parent
9dc8e3ad02
commit
fb24e652fe
@@ -53,6 +53,12 @@ class PrintingAuto(models.Model):
|
||||
printer_id = fields.Many2one("printing.printer", "Printer")
|
||||
printer_tray_id = fields.Many2one("printing.tray", "Tray")
|
||||
nbr_of_copies = fields.Integer("Number of Copies", default=1)
|
||||
action_on_error = fields.Selection(
|
||||
[("log", "Record an error"), ("raise", "Raise an Exception")],
|
||||
"Action on error",
|
||||
default="log",
|
||||
required=True,
|
||||
)
|
||||
|
||||
@api.constrains("data_source", "report_id", "attachment_domain")
|
||||
def _check_data_source(self):
|
||||
|
||||
@@ -37,14 +37,21 @@ class PrintingAutoMixin(models.AbstractModel):
|
||||
def _get_printing_auto(self):
|
||||
return self.auto_printing_ids
|
||||
|
||||
def _handle_print_auto(self, printing_auto):
|
||||
def _do_print_auto(self, printing_auto):
|
||||
self.ensure_one()
|
||||
printing_auto.ensure_one()
|
||||
try:
|
||||
with self.env.cr.savepoint():
|
||||
printer, count = printing_auto.do_print(self)
|
||||
if count:
|
||||
self._on_printing_auto_done(printing_auto, printer, count)
|
||||
|
||||
def _handle_print_auto(self, printing_auto):
|
||||
printing_auto.ensure_one()
|
||||
if printing_auto.action_on_error == "raise":
|
||||
self._do_print_auto(printing_auto)
|
||||
return
|
||||
try:
|
||||
with self.env.cr.savepoint():
|
||||
self._do_print_auto(printing_auto)
|
||||
except Exception as e:
|
||||
_logger.exception(
|
||||
"An error occurred while printing '%s' for record %s.",
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
domain="[('printer_id', '=', printer_id)]"
|
||||
/>
|
||||
<field name="nbr_of_copies" />
|
||||
<field name="action_on_error" />
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
@@ -44,6 +45,7 @@
|
||||
<field name="printer_id" />
|
||||
<field name="printer_tray_id" />
|
||||
<field name="nbr_of_copies" />
|
||||
<field name="action_on_error" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user