From 7ac256466816d3e6fc0e8b8bcb469e17b4aa7876 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 17 Nov 2014 15:26:10 +0100 Subject: [PATCH] Move the 'skip_update' right in the browse, it prevents a loop See https://github.com/odoo/odoo/issues/3644 Also, it helps to have the value set/read in context close to each other. --- base_report_to_printer/printing.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/base_report_to_printer/printing.py b/base_report_to_printer/printing.py index 179ea57..c48e7f5 100644 --- a/base_report_to_printer/printing.py +++ b/base_report_to_printer/printing.py @@ -148,7 +148,6 @@ class PrintingPrinterPolling(models.Model): try: self.env = api.Environment(cr, uid, context) printer_obj = self.env['printing.printer'] - printer_obj = printer_obj.with_context(skip_update=True) with self.start_update() as locked: if not locked: return # could not obtain lock @@ -264,27 +263,25 @@ class PrintingPrinter(models.Model): @api.model def update(self): """Update printer status if current status is more than 10s old.""" - # We won't acquire locks - we're only assigning from immutable data - if not self.env.context or 'skip_update' in self.env.context: - return True polling_obj = self.env['printing.printer.polling'] - if polling_obj.need_update(): self.start_printer_update() - return True @api.v7 def browse(self, cr, uid, arg=None, context=None): - # https://github.com/odoo/odoo/issues/3644 - # self.update(cr, uid, context=context) _super = super(PrintingPrinter, self) - return _super.browse(cr, uid, arg=arg, context=context) + recs = _super.browse(cr, uid, arg=arg, context=context) + if not recs._context.get('skip_update'): + recs.with_context(skip_update=True).update() + return recs @api.v8 def browse(self, arg=None): - self.update() - return super(PrintingPrinter, self).browse(arg=arg) + recs = super(PrintingPrinter, self).browse(arg=arg) + if not recs._context.get('skip_update'): + recs.with_context(skip_update=True).update() + return recs @api.multi def set_default(self):