diff --git a/CHANGELOG b/CHANGELOG
index 811a308dcc..07bae0b0a1 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,5 @@
+* Allow periods to end on any day of the month
+* Use a wizard to select parameters when creating periods
* Modularize code in GroupLines wizard
Version 5.4.0 - 2019-11-04
diff --git a/__init__.py b/__init__.py
index eb5da34651..bc964a884c 100644
--- a/__init__.py
+++ b/__init__.py
@@ -2,62 +2,62 @@
# this repository contains the full copyright notices and license terms.
from trytond.pool import Pool
-from .fiscalyear import *
-from .account import *
+from . import account
from . import configuration
-from .period import *
-from .journal import *
-from .move import *
-from .move_template import *
-from . import tax
+from . import fiscalyear
+from . import journal
+from . import move
+from . import move_template
from . import party
+from . import period
+from . import tax
def register():
Pool.register(
- FiscalYear,
- BalanceNonDeferralStart,
- TypeTemplate,
- Type,
- AccountTemplate,
- AccountTemplateTaxTemplate,
- Account,
- AccountDeferral,
- AccountTax,
- OpenChartAccountStart,
- GeneralLedgerAccount,
- GeneralLedgerAccountContext,
- GeneralLedgerLine,
- GeneralLedgerLineContext,
- BalanceSheetContext,
- BalanceSheetComparisionContext,
- IncomeStatementContext,
- CreateChartStart,
- CreateChartAccount,
- CreateChartProperties,
- UpdateChartStart,
- UpdateChartSucceed,
- AgedBalanceContext,
- AgedBalance,
+ fiscalyear.FiscalYear,
+ fiscalyear.BalanceNonDeferralStart,
+ account.TypeTemplate,
+ account.Type,
+ account.AccountTemplate,
+ account.AccountTemplateTaxTemplate,
+ account.Account,
+ account.AccountDeferral,
+ account.AccountTax,
+ account.OpenChartAccountStart,
+ account.GeneralLedgerAccount,
+ account.GeneralLedgerAccountContext,
+ account.GeneralLedgerLine,
+ account.GeneralLedgerLineContext,
+ account.BalanceSheetContext,
+ account.BalanceSheetComparisionContext,
+ account.IncomeStatementContext,
+ account.CreateChartStart,
+ account.CreateChartAccount,
+ account.CreateChartProperties,
+ account.UpdateChartStart,
+ account.UpdateChartSucceed,
+ account.AgedBalanceContext,
+ account.AgedBalance,
configuration.Configuration,
configuration.ConfigurationDefaultAccount,
configuration.DefaultTaxRule,
- Period,
- Journal,
- JournalSequence,
- JournalCashContext,
- JournalPeriod,
- Move,
- Reconciliation,
+ period.Period,
+ journal.Journal,
+ journal.JournalSequence,
+ journal.JournalCashContext,
+ journal.JournalPeriod,
+ move.Move,
+ move.Reconciliation,
configuration.ConfigurationTaxRounding,
- Line,
- WriteOff,
- OpenJournalAsk,
- ReconcileLinesWriteOff,
- ReconcileShow,
- CancelMovesDefault,
- GroupLinesStart,
- PrintGeneralJournalStart,
+ move.Line,
+ move.WriteOff,
+ move.OpenJournalAsk,
+ move.ReconcileLinesWriteOff,
+ move.ReconcileShow,
+ move.CancelMovesDefault,
+ move.GroupLinesStart,
+ move.PrintGeneralJournalStart,
tax.TaxGroup,
tax.TaxCodeTemplate,
tax.TaxCode,
@@ -73,41 +73,43 @@ def register():
tax.TaxRuleLine,
tax.TestTaxView,
tax.TestTaxViewResult,
- MoveTemplate,
- MoveTemplateKeyword,
- MoveLineTemplate,
- TaxLineTemplate,
- CreateMoveTemplate,
- CreateMoveKeywords,
+ move_template.MoveTemplate,
+ move_template.MoveTemplateKeyword,
+ move_template.MoveLineTemplate,
+ move_template.TaxLineTemplate,
+ move_template.CreateMoveTemplate,
+ move_template.CreateMoveKeywords,
party.Party,
party.PartyAccount,
- RenewFiscalYearStart,
+ fiscalyear.CreatePeriodsStart,
+ fiscalyear.RenewFiscalYearStart,
module='account', type_='model')
Pool.register(
- OpenType,
- BalanceNonDeferral,
- OpenChartAccount,
- CreateChart,
- UpdateChart,
- OpenJournal,
- OpenAccount,
- ReconcileLines,
- UnreconcileLines,
- Reconcile,
- CancelMoves,
- GroupLines,
- PrintGeneralJournal,
- CreateMove,
+ account.OpenType,
+ fiscalyear.BalanceNonDeferral,
+ account.OpenChartAccount,
+ account.CreateChart,
+ account.UpdateChart,
+ move.OpenJournal,
+ move.OpenAccount,
+ move.ReconcileLines,
+ move.UnreconcileLines,
+ move.Reconcile,
+ move.CancelMoves,
+ move.GroupLines,
+ move.PrintGeneralJournal,
+ move_template.CreateMove,
tax.OpenChartTaxCode,
tax.OpenTaxCode,
tax.TestTax,
party.PartyReplace,
party.PartyErase,
- RenewFiscalYear,
+ fiscalyear.CreatePeriods,
+ fiscalyear.RenewFiscalYear,
module='account', type_='wizard')
Pool.register(
- GeneralLedger,
- TrialBalance,
- AgedBalanceReport,
- GeneralJournal,
+ account.GeneralLedger,
+ account.TrialBalance,
+ account.AgedBalanceReport,
+ move.GeneralJournal,
module='account', type_='report')
diff --git a/fiscalyear.py b/fiscalyear.py
index 7d0594d743..69b11043f5 100644
--- a/fiscalyear.py
+++ b/fiscalyear.py
@@ -6,18 +6,16 @@ from dateutil.relativedelta import relativedelta
from trytond.i18n import gettext
from trytond.model import ModelView, ModelSQL, Workflow, fields
from trytond.model.exceptions import AccessError
-from trytond.wizard import Wizard, StateView, StateAction, Button
-from trytond.pyson import Eval, If, PYSONEncoder
-from trytond.transaction import Transaction
from trytond.pool import Pool
+from trytond.pyson import Eval, If, PYSONEncoder
+from trytond.rpc import RPC
+from trytond.transaction import Transaction
+from trytond.wizard import (
+ Wizard, StateView, StateTransition, StateAction, Button)
from .exceptions import (FiscalYearNotFoundError, FiscalYearDatesError,
FiscalYearSequenceError, FiscalYearCloseError, FiscalYearReOpenError)
-__all__ = ['FiscalYear',
- 'BalanceNonDeferralStart', 'BalanceNonDeferral',
- 'RenewFiscalYearStart', 'RenewFiscalYear']
-
STATES = {
'readonly': Eval('state') != 'open',
}
@@ -73,12 +71,7 @@ class FiscalYear(Workflow, ModelSQL, ModelView):
('close', 'open'),
))
cls._buttons.update({
- 'create_period': {
- 'invisible': ((Eval('state') != 'open')
- | Eval('periods', [0])),
- 'depends': ['state'],
- },
- 'create_period_3': {
+ 'create_periods': {
'invisible': ((Eval('state') != 'open')
| Eval('periods', [0])),
'depends': ['state'],
@@ -96,6 +89,9 @@ class FiscalYear(Workflow, ModelSQL, ModelView):
'depends': ['state'],
},
})
+ cls.__rpc__.update({
+ 'create_period': RPC(readonly=False, instantiate=0),
+ })
@staticmethod
def default_state():
@@ -181,8 +177,7 @@ class FiscalYear(Workflow, ModelSQL, ModelView):
super(FiscalYear, cls).delete(fiscalyears)
@classmethod
- @ModelView.button
- def create_period(cls, fiscalyears, interval=1):
+ def create_period(cls, fiscalyears, interval=1, end_day=31):
'''
Create periods for the fiscal years with month interval
'''
@@ -191,9 +186,10 @@ class FiscalYear(Workflow, ModelSQL, ModelView):
for fiscalyear in fiscalyears:
period_start_date = fiscalyear.start_date
while period_start_date < fiscalyear.end_date:
- period_end_date = period_start_date + \
- relativedelta(months=interval - 1) + \
- relativedelta(day=31)
+ month_offset = 1 if period_start_date.day < end_day else 0
+ period_end_date = (period_start_date
+ + relativedelta(months=interval - month_offset)
+ + relativedelta(day=end_day))
if period_end_date > fiscalyear.end_date:
period_end_date = fiscalyear.end_date
name = period_start_date.strftime('%Y-%m')
@@ -211,12 +207,9 @@ class FiscalYear(Workflow, ModelSQL, ModelView):
Period.create(to_create)
@classmethod
- @ModelView.button
- def create_period_3(cls, fiscalyears):
- '''
- Create periods for the fiscal years with 3 months interval
- '''
- cls.create_period(fiscalyears, interval=3)
+ @ModelView.button_action('account.act_create_periods')
+ def create_periods(cls, fiscalyears):
+ pass
@classmethod
def find(cls, company_id, date=None, exception=True):
@@ -476,8 +469,67 @@ class BalanceNonDeferral(Wizard):
return action, {}
+class CreatePeriodsStart(ModelView):
+ "Create Periods Start"
+ __name__ = 'account.fiscalyear.create_periods.start'
+ frequency = fields.Selection([
+ ('monthly', "Monthly"),
+ ('quarterly', "Quarterly"),
+ ('other', "Other"),
+ ], "Frequency", sort=False, required=True)
+ interval = fields.Integer("Interval", required=True,
+ states={
+ 'invisible': Eval('frequency') != 'other',
+ },
+ depends=['frequency'],
+ help="The length of each period, in months.")
+ end_day = fields.Integer("End Day", required=True,
+ help="The day of the month on which periods end.\n"
+ "Months with fewer days will end on the last day.")
+
+ @classmethod
+ def default_frequency(cls):
+ return 'monthly'
+
+ @classmethod
+ def default_end_day(cls):
+ return 31
+
+ @classmethod
+ def frequency_intervals(cls):
+ return {
+ 'monthly': 1,
+ 'quarterly': 3,
+ 'other': None,
+ }
+
+ @fields.depends('frequency', 'interval')
+ def on_change_frequency(self):
+ if self.frequency:
+ self.interval = self.frequency_intervals()[self.frequency]
+
+
+class CreatePeriods(Wizard):
+ "Create Periods"
+ __name__ = 'account.fiscalyear.create_periods'
+ start = StateView('account.fiscalyear.create_periods.start',
+ 'account.fiscalyear_create_periods_start_view_form', [
+ Button("Cancel", 'end', 'tryton-cancel'),
+ Button("Create", 'create_periods', 'tryton-ok', default=True),
+ ])
+ create_periods = StateTransition()
+
+ def transition_create_periods(self):
+ FiscalYear = Pool().get('account.fiscalyear')
+ fiscalyear = FiscalYear(Transaction().context['active_id'])
+ FiscalYear.create_period(
+ [fiscalyear], self.start.interval, self.start.end_day)
+ return 'end'
+
+
def month_delta(d1, d2):
- return (d1.year - d2.year) * 12 + d1.month - d2.month
+ month_offset = 1 if d1.day < d2.day else 0
+ return (d1.year - d2.year) * 12 + d1.month - d2.month - month_offset
class RenewFiscalYearStart(ModelView):
@@ -577,10 +629,12 @@ class RenewFiscalYear(Wizard):
periods = [p for p in self.start.previous_fiscalyear.periods
if p.type == 'standard']
months = month_delta(fiscalyear.end_date, fiscalyear.start_date) + 1
- if len(periods) == months:
- FiscalYear.create_period([fiscalyear])
- elif len(periods) == months / 3:
- FiscalYear.create_period_3([fiscalyear])
+ interval = months / len(periods)
+ end_day = max(p.end_date.day
+ for p in self.start.previous_fiscalyear.periods
+ if p.type == 'standard')
+ if interval.is_integer():
+ FiscalYear.create_period([fiscalyear], interval, end_day)
return fiscalyear
def do_create_(self, action):
diff --git a/fiscalyear.xml b/fiscalyear.xml
index 861e158006..a034d1f455 100644
--- a/fiscalyear.xml
+++ b/fiscalyear.xml
@@ -54,16 +54,9 @@ this repository contains the full copyright notices and license terms. -->
-
- create_period
- Create Monthly Periods
-
-
-
-
- create_period_3
- Create 3 Monthly Periods
+
+ create_periods
+ Create Periods
@@ -114,6 +107,16 @@ this repository contains the full copyright notices and license terms. -->
+
+ account.fiscalyear.create_periods.start
+ form
+ fiscalyear_create_periods_start_form
+
+
+ Create Periods
+ account.fiscalyear.create_periods
+
+
+
+
diff --git a/view/fiscalyear_form.xml b/view/fiscalyear_form.xml
index 5c79e64279..2238979b75 100644
--- a/view/fiscalyear_form.xml
+++ b/view/fiscalyear_form.xml
@@ -14,8 +14,7 @@ this repository contains the full copyright notices and license terms. -->
-
-
+