From 853fb6d6332fee85eaa098a0c73c72a90f616e4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 27 Jun 2017 12:45:00 +0200 Subject: [PATCH] Use not grouped invoice to search grouped invoice And use class from instance instead of Pool. issue6580 review35461002 --- sale.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sale.py b/sale.py index 82c84d9025..971bacdddc 100644 --- a/sale.py +++ b/sale.py @@ -1,7 +1,8 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond.pool import Pool, PoolMeta +from trytond.pool import PoolMeta +from trytond.transaction import Transaction __all__ = ['Sale'] @@ -25,7 +26,7 @@ class Sale: def _get_grouped_invoice_domain(self, invoice): "Returns a domain that will find invoices that should be grouped" - Invoice = Pool().get('account.invoice') + Invoice = invoice.__class__ invoice_domain = [ ('lines.origin', 'like', 'sale.line,%'), ] @@ -38,9 +39,14 @@ class Sale: return invoice_domain def _get_invoice_sale(self): - Invoice = Pool().get('account.invoice') + transaction = Transaction() + context = transaction.context invoice = super(Sale, self)._get_invoice_sale() - if self.invoice_grouping_method: + if (not context.get('skip_grouping', False) + and self.invoice_grouping_method): + with transaction.set_context(skip_grouping=True): + invoice = self._get_invoice_sale() + Invoice = invoice.__class__ domain = self._get_grouped_invoice_domain(invoice) order = self._get_grouped_invoice_order() grouped_invoices = Invoice.search(domain, order=order, limit=1)