diff --git a/CHANGELOG b/CHANGELOG
index 4a630eb76e..86b1407084 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,4 @@
+* Add balance non-deferral wizard
* Display write-off amount in reconciliation
* Enforce same company for a chart of account
* Change tax percentage into rate
diff --git a/__init__.py b/__init__.py
index 21f9eefe94..b6169992fc 100644
--- a/__init__.py
+++ b/__init__.py
@@ -15,6 +15,7 @@ from .party import *
def register():
Pool.register(
FiscalYear,
+ BalanceNonDeferralStart,
CloseFiscalYearStart,
TypeTemplate,
Type,
@@ -69,6 +70,7 @@ def register():
module='account', type_='model')
Pool.register(
OpenType,
+ BalanceNonDeferral,
CloseFiscalYear,
OpenChartAccount,
PrintGeneralLedger,
diff --git a/doc/index.rst b/doc/index.rst
index 6a1d161c94..b7195bd848 100644
--- a/doc/index.rst
+++ b/doc/index.rst
@@ -21,6 +21,10 @@ year will close all the corresponding periods.
- Post Move Sequence: The sequence to use for numbering moves in this
fiscal year.
+The *Balance Non-Deferral* wizard allow to create a move that will debit/credit
+each non-deferral account in such way to have a balance equals to zero for the
+fiscal year and debit/credit a counter part account.
+
Period
******
diff --git a/fiscalyear.py b/fiscalyear.py
index e7a9e8c37a..dd9cfc2eff 100644
--- a/fiscalyear.py
+++ b/fiscalyear.py
@@ -2,13 +2,16 @@
#this repository contains the full copyright notices and license terms.
from dateutil.relativedelta import relativedelta
from trytond.model import ModelView, ModelSQL, fields
-from trytond.wizard import Wizard, StateView, StateTransition, Button
+from trytond.wizard import Wizard, StateView, StateTransition, StateAction, \
+ Button
from trytond.tools import datetime_strftime
-from trytond.pyson import Eval, If
+from trytond.pyson import Eval, If, PYSONEncoder
from trytond.transaction import Transaction
from trytond.pool import Pool
-__all__ = ['FiscalYear', 'CloseFiscalYearStart', 'CloseFiscalYear']
+__all__ = ['FiscalYear',
+ 'BalanceNonDeferralStart', 'BalanceNonDeferral',
+ 'CloseFiscalYearStart', 'CloseFiscalYear']
STATES = {
'readonly': Eval('state') == 'close',
@@ -306,6 +309,118 @@ class FiscalYear(ModelSQL, ModelView):
})
+class BalanceNonDeferralStart(ModelView):
+ 'Balance Non-Deferral'
+ __name__ = 'account.fiscalyear.balance_non_deferral.start'
+ fiscalyear = fields.Many2One('account.fiscalyear', 'Fiscal Year',
+ required=True, domain=[('state', '=', 'open')])
+ journal = fields.Many2One('account.journal', 'Journal', required=True,
+ domain=[
+ ('type', '=', 'situation'),
+ ])
+ period = fields.Many2One('account.period', 'Period', required=True,
+ domain=[
+ ('fiscalyear', '=', Eval('fiscalyear')),
+ ('type', '=', 'adjustment'),
+ ],
+ depends=['fiscalyear'])
+ credit_account = fields.Many2One('account.account', 'Credit Account',
+ required=True,
+ domain=[
+ ('kind', '!=', 'view'),
+ ('company', '=', Eval('context', {}).get('company', 0)),
+ ('deferral', '=', True),
+ ])
+ debit_account = fields.Many2One('account.account', 'Debit Account',
+ required=True,
+ domain=[
+ ('kind', '!=', 'view'),
+ ('company', '=', Eval('context', {}).get('company', 0)),
+ ('deferral', '=', True),
+ ])
+
+
+class BalanceNonDeferral(Wizard):
+ 'Balance Non-Deferral'
+ __name__ = 'account.fiscalyear.balance_non_deferral'
+ start = StateView('account.fiscalyear.balance_non_deferral.start',
+ 'account.fiscalyear_balance_non_deferral_start_view_form', [
+ Button('Cancel', 'end', 'tryton-cancel'),
+ Button('Ok', 'balance', 'tryton-ok', default=True),
+ ])
+ balance = StateAction('account.act_move_line_form')
+
+ def get_move_line(self, account):
+ pool = Pool()
+ Line = pool.get('account.move.line')
+ if account.company.currency.is_zero(account.balance):
+ return
+ line = Line()
+ line.account = account
+ if account.balance >= 0:
+ line.credit = abs(account.balance)
+ line.debit = 0
+ else:
+ line.credit = 0
+ line.debit = abs(account.balance)
+ return line
+
+ def get_counterpart_line(self, amount):
+ pool = Pool()
+ Line = pool.get('account.move.line')
+ if self.start.fiscalyear.company.currency.is_zero(amount):
+ return
+ line = Line()
+ if amount >= 0:
+ line.credit = abs(amount)
+ line.debit = 0
+ line.account = self.start.credit_account
+ else:
+ line.credit = 0
+ line.debit = abs(amount)
+ line.account = self.start.debit_account
+ return line
+
+ def create_move(self):
+ pool = Pool()
+ Account = pool.get('account.account')
+ Move = pool.get('account.move')
+
+ with Transaction().set_context(fiscalyear=self.start.fiscalyear.id,
+ date=None, cumulate=False):
+ accounts = Account.search([
+ ('company', '=', self.start.fiscalyear.company.id),
+ ('deferral', '=', False),
+ ])
+ lines = []
+ for account in accounts:
+ line = self.get_move_line(account)
+ if line:
+ lines.append(line)
+ if not lines:
+ return
+ amount = sum(l.debit - l.credit for l in lines)
+ counter_part_line = self.get_counterpart_line(amount)
+ if counter_part_line:
+ lines.append(counter_part_line)
+
+ move = Move()
+ move.period = self.start.period
+ move.journal = self.start.journal
+ move.date = self.start.period.start_date
+ move.origin = self.start.fiscalyear
+ move.lines = lines
+ move.save()
+ return move
+
+ def do_balance(self, action):
+ self.create_move()
+ action['pyson_domain'] = PYSONEncoder().encode([
+ ('origin', '=', str(self.start.fiscalyear)),
+ ])
+ return action, {}
+
+
class CloseFiscalYearStart(ModelView):
'Close Fiscal Year'
__name__ = 'account.fiscalyear.close.start'
diff --git a/fiscalyear.xml b/fiscalyear.xml
index 1f175796aa..9ad5f0395a 100644
--- a/fiscalyear.xml
+++ b/fiscalyear.xml
@@ -57,6 +57,24 @@ this repository contains the full copyright notices and license terms. -->