From 9484769e222d368a081fee1046f9f01e21dfd792 Mon Sep 17 00:00:00 2001 From: Denis Roussel Date: Thu, 23 Sep 2021 15:23:50 +0200 Subject: [PATCH] [14.0][IMP] sale_automatic_workflow: Use with_company instead of user.company_id --- .../models/automatic_workflow_job.py | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/sale_automatic_workflow/models/automatic_workflow_job.py b/sale_automatic_workflow/models/automatic_workflow_job.py index ab7d2b541eb..ded915a845e 100644 --- a/sale_automatic_workflow/models/automatic_workflow_job.py +++ b/sale_automatic_workflow/models/automatic_workflow_job.py @@ -60,8 +60,10 @@ def _validate_sale_orders(self, order_filter): sales = sale_obj.search(order_filter) _logger.debug("Sale Orders to validate: %s", sales.ids) for sale in sales: - with savepoint(self.env.cr), force_company(self.env, sale.company_id): - self._do_validate_sale_order(sale, order_filter) + with savepoint(self.env.cr): + self._do_validate_sale_order( + sale.with_company(sale.company_id), order_filter + ) def _do_create_invoice(self, sale, domain_filter): """Create an invoice for a sales order, filter ensure no duplication""" @@ -79,8 +81,10 @@ def _create_invoices(self, create_filter): sales = sale_obj.search(create_filter) _logger.debug("Sale Orders to create Invoice: %s", sales.ids) for sale in sales: - with savepoint(self.env.cr), force_company(self.env, sale.company_id): - self._do_create_invoice(sale, create_filter) + with savepoint(self.env.cr): + self._do_create_invoice( + sale.with_company(sale.company_id), create_filter + ) def _do_validate_invoice(self, invoice, domain_filter): """Validate an invoice, filter ensure no duplication""" @@ -99,8 +103,10 @@ def _validate_invoices(self, validate_invoice_filter): invoices = move_obj.search(validate_invoice_filter) _logger.debug("Invoices to validate: %s", invoices.ids) for invoice in invoices: - with savepoint(self.env.cr), force_company(self.env, invoice.company_id): - self._do_validate_invoice(invoice, validate_invoice_filter) + with savepoint(self.env.cr): + self._do_validate_invoice( + invoice.with_company(invoice.company_id), validate_invoice_filter + ) def _do_validate_picking(self, picking, domain_filter): """Validate a stock.picking, filter ensure no duplication""" @@ -137,8 +143,8 @@ def _sale_done(self, sale_done_filter): sales = sale_obj.search(sale_done_filter) _logger.debug("Sale Orders to done: %s", sales.ids) for sale in sales: - with savepoint(self.env.cr), force_company(self.env, sale.company_id): - self._do_sale_done(sale, sale_done_filter) + with savepoint(self.env.cr): + self._do_sale_done(sale.with_company(sale.company_id), sale_done_filter) @api.model def run_with_workflow(self, sale_workflow):