changeset bfeac28a3c0b in modules/sale_gift_card:default
details: 
https://hg.tryton.org/modules/sale_gift_card?cmd=changeset&node=bfeac28a3c0b
description:
        Restore instance context when getting account used

        The account_used is set on property so it is executed under the 
transaction
        context but we expect to have the account from the company set in the 
instance
        context.

        issue10557
        review355371002
diffstat:

 product.py |  11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diffs (35 lines):

diff -r 2562ce5c33c5 -r bfeac28a3c0b product.py
--- a/product.py        Sun Jul 04 17:54:48 2021 +0200
+++ b/product.py        Wed Jul 21 23:54:13 2021 +0200
@@ -4,6 +4,7 @@
 from trytond.model import fields
 from trytond.pool import PoolMeta, Pool
 from trytond.pyson import Eval
+from trytond.transaction import Transaction
 
 from .exceptions import GiftCardValidationError
 
@@ -44,7 +45,10 @@
         pool = Pool()
         Config = pool.get('account.configuration')
         if self.gift_card:
-            config = Config(1)
+            transaction = Transaction()
+            with transaction.reset_context(), \
+                    transaction.set_context(self._context):
+                config = Config(1)
             return config.gift_card_account_expense
         return super().account_expense_used
 
@@ -53,7 +57,10 @@
         pool = Pool()
         Config = pool.get('account.configuration')
         if self.gift_card:
-            config = Config(1)
+            transaction = Transaction()
+            with transaction.reset_context(), \
+                    transaction.set_context(self._context):
+                config = Config(1)
             return config.gift_card_account_revenue
         return super().account_revenue_used
 

Reply via email to