fix(regional): set frappe.flags.company temporarily, where required

This commit is contained in:
Sagar Vora 2023-07-24 18:37:36 +05:30
parent 1436040d4c
commit 4205f564a0
4 changed files with 28 additions and 18 deletions

View File

@ -33,6 +33,7 @@ import erpnext
from erpnext import get_company_currency from erpnext import get_company_currency
from erpnext.accounts.utils import get_fiscal_year from erpnext.accounts.utils import get_fiscal_year
from erpnext.exceptions import InvalidAccountCurrency, PartyDisabled, PartyFrozen from erpnext.exceptions import InvalidAccountCurrency, PartyDisabled, PartyFrozen
from erpnext.utilities.regional import temporary_flag
PURCHASE_TRANSACTION_TYPES = {"Purchase Order", "Purchase Receipt", "Purchase Invoice"} PURCHASE_TRANSACTION_TYPES = {"Purchase Order", "Purchase Receipt", "Purchase Invoice"}
SALES_TRANSACTION_TYPES = { SALES_TRANSACTION_TYPES = {
@ -261,8 +262,7 @@ def set_address_details(
) )
if doctype in TRANSACTION_TYPES: if doctype in TRANSACTION_TYPES:
# required to set correct region with temporary_flag("company", company):
frappe.flags.company = company
get_regional_address_details(party_details, doctype, company) get_regional_address_details(party_details, doctype, company)
return party_address, shipping_address return party_address, shipping_address

View File

@ -56,6 +56,7 @@ from erpnext.stock.get_item_details import (
get_item_tax_map, get_item_tax_map,
get_item_warehouse, get_item_warehouse,
) )
from erpnext.utilities.regional import temporary_flag
from erpnext.utilities.transaction_base import TransactionBase from erpnext.utilities.transaction_base import TransactionBase
@ -760,7 +761,9 @@ class AccountsController(TransactionBase):
} }
) )
with temporary_flag("company", self.company):
update_gl_dict_with_regional_fields(self, gl_dict) update_gl_dict_with_regional_fields(self, gl_dict)
accounting_dimensions = get_accounting_dimensions() accounting_dimensions = get_accounting_dimensions()
dimension_dict = frappe._dict() dimension_dict = frappe._dict()

View File

@ -18,6 +18,7 @@ from erpnext.controllers.accounts_controller import (
validate_taxes_and_charges, validate_taxes_and_charges,
) )
from erpnext.stock.get_item_details import _get_item_tax_template from erpnext.stock.get_item_details import _get_item_tax_template
from erpnext.utilities.regional import temporary_flag
class calculate_taxes_and_totals(object): class calculate_taxes_and_totals(object):
@ -942,7 +943,6 @@ class calculate_taxes_and_totals(object):
def get_itemised_tax_breakup_html(doc): def get_itemised_tax_breakup_html(doc):
if not doc.taxes: if not doc.taxes:
return return
frappe.flags.company = doc.company
# get headers # get headers
tax_accounts = [] tax_accounts = []
@ -952,15 +952,11 @@ def get_itemised_tax_breakup_html(doc):
if tax.description not in tax_accounts: if tax.description not in tax_accounts:
tax_accounts.append(tax.description) tax_accounts.append(tax.description)
with temporary_flag("company", doc.company):
headers = get_itemised_tax_breakup_header(doc.doctype + " Item", tax_accounts) headers = get_itemised_tax_breakup_header(doc.doctype + " Item", tax_accounts)
# get tax breakup data
itemised_tax, itemised_taxable_amount = get_itemised_tax_breakup_data(doc) itemised_tax, itemised_taxable_amount = get_itemised_tax_breakup_data(doc)
get_rounded_tax_amount(itemised_tax, doc.precision("tax_amount", "taxes")) get_rounded_tax_amount(itemised_tax, doc.precision("tax_amount", "taxes"))
update_itemised_tax_data(doc) update_itemised_tax_data(doc)
frappe.flags.company = None
return frappe.render_template( return frappe.render_template(
"templates/includes/itemised_tax_breakup.html", "templates/includes/itemised_tax_breakup.html",
@ -977,10 +973,8 @@ def get_itemised_tax_breakup_html(doc):
@frappe.whitelist() @frappe.whitelist()
def get_round_off_applicable_accounts(company, account_list): def get_round_off_applicable_accounts(company, account_list):
# required to set correct region # required to set correct region
frappe.flags.company = company with temporary_flag("company", company):
account_list = get_regional_round_off_accounts(company, account_list) return get_regional_round_off_accounts(company, account_list)
return account_list
@erpnext.allow_regional @erpnext.allow_regional

View File

@ -0,0 +1,13 @@
from contextlib import contextmanager
import frappe
@contextmanager
def temporary_flag(flag_name, value):
flags = frappe.local.flags
flags[flag_name] = value
try:
yield
finally:
flags.pop(flag_name, None)