Always raise exception when fiscal year or period are not found

Since 641cb7c9a4
Task #048598
This commit is contained in:
Juanjo Garcia 2023-03-16 16:11:59 +01:00
parent 065216f549
commit fc3ca7cd96
2 changed files with 18 additions and 6 deletions

View File

@ -13,6 +13,7 @@ from trytond.tools import grouped_slice
from trytond.modules.html_report.html_report import HTMLReport
from babel.dates import format_datetime
from trytond.rpc import RPC
from trytond.modules.account.exceptions import FiscalYearNotFoundError
_ZERO = Decimal(0)
@ -57,9 +58,14 @@ class PrintGeneralLedgerStart(ModelView):
@staticmethod
def default_fiscalyear():
FiscalYear = Pool().get('account.fiscalyear')
return FiscalYear.find(
Transaction().context.get('company'), exception=False)
pool = Pool()
FiscalYear = pool.get('account.fiscalyear')
try:
fiscalyear = FiscalYear.find(
Transaction().context.get('company'), test_state=False)
except FiscalYearNotFoundError:
return None
return fiscalyear.id
@staticmethod
def default_all_accounts():

View File

@ -12,6 +12,7 @@ from trytond.rpc import RPC
from trytond.modules.html_report.html_report import HTMLReport
from trytond.modules.html_report.engine import DualRecord
from babel.dates import format_datetime
from trytond.modules.account.exceptions import FiscalYearNotFoundError
_ZERO = Decimal(0)
@ -106,9 +107,14 @@ class PrintTaxesByInvoiceAndPeriodStart(ModelView):
@staticmethod
def default_fiscalyear():
FiscalYear = Pool().get('account.fiscalyear')
return FiscalYear.find(
Transaction().context.get('company'), exception=False)
pool = Pool()
FiscalYear = pool.get('account.fiscalyear')
try:
fiscalyear = FiscalYear.find(
Transaction().context.get('company'), test_state=False)
except FiscalYearNotFoundError:
return None
return fiscalyear.id
@staticmethod
def default_company():