Use specific error message for open period or fiscal year not found
Closes #9335
This commit is contained in:
@@ -245,6 +245,7 @@ class FiscalYear(Workflow, ModelSQL, ModelView):
|
||||
pool = Pool()
|
||||
Lang = pool.get('ir.lang')
|
||||
Date = pool.get('ir.date')
|
||||
Company = pool.get('company.company')
|
||||
|
||||
company_id = int(company) if company is not None else None
|
||||
if not date:
|
||||
@@ -258,8 +259,6 @@ class FiscalYear(Workflow, ModelSQL, ModelView):
|
||||
('end_date', '>=', date),
|
||||
('company', '=', company_id),
|
||||
]
|
||||
if test_state:
|
||||
clause.append(('state', '=', 'open'))
|
||||
fiscalyears = cls.search(
|
||||
clause, order=[('start_date', 'DESC')], limit=1)
|
||||
if fiscalyears:
|
||||
@@ -269,12 +268,25 @@ class FiscalYear(Workflow, ModelSQL, ModelView):
|
||||
cls._find_cache.set(key, int(fiscalyear) if fiscalyear else None)
|
||||
elif fiscalyear is not None:
|
||||
fiscalyear = cls(fiscalyear)
|
||||
if not fiscalyear and exception:
|
||||
lang = Lang.get()
|
||||
raise FiscalYearNotFoundError(
|
||||
gettext('account.msg_no_fiscalyear_date',
|
||||
date=lang.strftime(date)))
|
||||
return fiscalyear
|
||||
found = fiscalyear and (not test_state or fiscalyear.state == 'open')
|
||||
if not found:
|
||||
if exception:
|
||||
lang = Lang.get()
|
||||
if company is not None and not isinstance(company, Company):
|
||||
company = Company(company)
|
||||
if not fiscalyear:
|
||||
raise FiscalYearNotFoundError(
|
||||
gettext('account.msg_no_fiscalyear_date',
|
||||
date=lang.strftime(date),
|
||||
company=company.rec_name if company else ''))
|
||||
else:
|
||||
raise FiscalYearNotFoundError(
|
||||
gettext('account.msg_no_open_fiscalyear_date',
|
||||
date=lang.strftime(date),
|
||||
fiscalyear=fiscalyear.rec_name,
|
||||
company=company.rec_name if company else ''))
|
||||
else:
|
||||
return fiscalyear
|
||||
|
||||
def get_deferral(self, account):
|
||||
'Computes deferrals for accounts'
|
||||
|
||||
@@ -4,7 +4,10 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data grouped="1">
|
||||
<record model="ir.message" id="msg_no_period_date">
|
||||
<field name="text">To continue, you must create a period for the date "%(date)s".</field>
|
||||
<field name="text">To continue, you must create a period for the date "%(date)s" and company "%(company)s".</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_no_open_period_date">
|
||||
<field name="text">To continue, you must reopen the period "%(period)s" of company "%(company)s" for the date "%(date)s".</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_modify_delete_period_moves">
|
||||
<field name="text">You cannot modify or delete period "%(period)s" because it contains moves.</field>
|
||||
@@ -55,7 +58,10 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="text">You cannot change the post move sequence on fiscal year "%(fiscalyear)s" because it contains posted moves.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_no_fiscalyear_date">
|
||||
<field name="text">To continue, you must create a fiscal year for the date "%(date)s".</field>
|
||||
<field name="text">To continue, you must create a fiscal year for the date "%(date)s" and company "%(company)s".</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_no_open_fiscalyear_date">
|
||||
<field name="text">To continue, you must reopen the fiscal year "%(fiscalyear)s" of company "%(company)s"for the date "%(date)s".</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_fiscalyear_overlap">
|
||||
<field name="text">The fiscal years "%(first)s" and "%(second)s" overlap, you must use different dates.</field>
|
||||
|
||||
@@ -191,6 +191,7 @@ class Period(Workflow, ModelSQL, ModelView):
|
||||
pool = Pool()
|
||||
Date = pool.get('ir.date')
|
||||
Lang = pool.get('ir.lang')
|
||||
Company = pool.get('company.company')
|
||||
|
||||
company_id = int(company) if company is not None else None
|
||||
if not date:
|
||||
@@ -205,8 +206,6 @@ class Period(Workflow, ModelSQL, ModelView):
|
||||
('fiscalyear.company', '=', company_id),
|
||||
('type', '=', 'standard'),
|
||||
]
|
||||
if test_state:
|
||||
clause.append(('state', '=', 'open'))
|
||||
periods = cls.search(
|
||||
clause, order=[('start_date', 'DESC')], limit=1)
|
||||
if periods:
|
||||
@@ -216,12 +215,25 @@ class Period(Workflow, ModelSQL, ModelView):
|
||||
cls._find_cache.set(key, int(period) if period else None)
|
||||
elif period is not None:
|
||||
period = cls(period)
|
||||
if not period and exception:
|
||||
lang = Lang.get()
|
||||
raise PeriodNotFoundError(
|
||||
gettext('account.msg_no_period_date',
|
||||
date=lang.strftime(date)))
|
||||
return period
|
||||
found = period and (not test_state or period.state == 'open')
|
||||
if not found:
|
||||
if exception:
|
||||
lang = Lang.get()
|
||||
if company is not None and not isinstance(company, Company):
|
||||
company = Company(company)
|
||||
if not period:
|
||||
raise PeriodNotFoundError(
|
||||
gettext('account.msg_no_period_date',
|
||||
date=lang.strftime(date),
|
||||
company=company.rec_name if company else ''))
|
||||
else:
|
||||
raise PeriodNotFoundError(
|
||||
gettext('account.msg_no_open_period_date',
|
||||
date=lang.strftime(date),
|
||||
period=period.rec_name,
|
||||
company=company.rec_name if company else ''))
|
||||
else:
|
||||
return period
|
||||
|
||||
@classmethod
|
||||
def _check(cls, periods):
|
||||
|
||||
Reference in New Issue
Block a user