Add balance non-deferral wizard
review627002
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
******
|
||||
|
||||
+118
-3
@@ -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'
|
||||
|
||||
+20
-2
@@ -57,6 +57,24 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="rule_group" ref="rule_group_fiscalyear"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view"
|
||||
id="fiscalyear_balance_non_deferral_start_view_form">
|
||||
<field
|
||||
name="model">account.fiscalyear.balance_non_deferral.start</field>
|
||||
<field name="type">form</field>
|
||||
<field
|
||||
name="name">fiscalyear_balance_non_deferral_start_form</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.wizard" id="act_balance_non_deferral">
|
||||
<field name="name">Balance Non-Deferral</field>
|
||||
<field
|
||||
name="wiz_name">account.fiscalyear.balance_non_deferral</field>
|
||||
</record>
|
||||
<menuitem parent="menu_processing" sequence="10"
|
||||
action="act_balance_non_deferral"
|
||||
id="menu_balance_non_deferral"/>
|
||||
|
||||
<record model="ir.ui.view" id="fiscalyear_close_start_view_form">
|
||||
<field name="model">account.fiscalyear.close.start</field>
|
||||
<field name="type">form</field>
|
||||
@@ -67,7 +85,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="name">Close Fiscal Year</field>
|
||||
<field name="wiz_name">account.fiscalyear.close</field>
|
||||
</record>
|
||||
<menuitem parent="menu_processing" action="act_close_fiscalyear"
|
||||
id="menu_close_fiscalyear"/>
|
||||
<menuitem parent="menu_processing" sequence="20"
|
||||
action="act_close_fiscalyear" id="menu_close_fiscalyear"/>
|
||||
</data>
|
||||
</tryton>
|
||||
|
||||
@@ -156,7 +156,7 @@ class Move(ModelSQL, ModelView):
|
||||
@classmethod
|
||||
def _get_origin(cls):
|
||||
'Return list of Model names for origin Reference'
|
||||
return []
|
||||
return ['account.fiscalyear']
|
||||
|
||||
@classmethod
|
||||
def get_origin(cls):
|
||||
|
||||
+25
-18
@@ -40,6 +40,9 @@ class AccountTestCase(unittest.TestCase):
|
||||
self.move = POOL.get('account.move')
|
||||
self.journal = POOL.get('account.journal')
|
||||
self.account_type = POOL.get('account.account.type')
|
||||
self.period = POOL.get('account.period')
|
||||
self.balance_non_deferral = POOL.get(
|
||||
'account.fiscalyear.balance_non_deferral', type='wizard')
|
||||
|
||||
def test0005views(self):
|
||||
'''
|
||||
@@ -233,7 +236,7 @@ class AccountTestCase(unittest.TestCase):
|
||||
(Decimal(0), Decimal(100)))
|
||||
self.assertEqual(revenue.balance, Decimal(-100))
|
||||
|
||||
# Close fiscalyear
|
||||
# Balance non-deferral
|
||||
journal_sequence, = self.sequence.search([
|
||||
('code', '=', 'account.journal'),
|
||||
])
|
||||
@@ -243,6 +246,13 @@ class AccountTestCase(unittest.TestCase):
|
||||
'type': 'situation',
|
||||
'sequence': journal_sequence.id,
|
||||
}])
|
||||
period_closing, = self.period.create([{
|
||||
'name': 'Closing',
|
||||
'start_date': fiscalyear.end_date,
|
||||
'end_date': fiscalyear.end_date,
|
||||
'fiscalyear': fiscalyear.id,
|
||||
'type': 'adjustment',
|
||||
}])
|
||||
type_equity, = self.account_type.search([
|
||||
('name', '=', 'Equity'),
|
||||
])
|
||||
@@ -253,28 +263,25 @@ class AccountTestCase(unittest.TestCase):
|
||||
'parent': revenue.parent.id,
|
||||
'kind': 'other',
|
||||
}])
|
||||
self.move.create([{
|
||||
'period': fiscalyear.periods[-1].id,
|
||||
'journal': journal_closing.id,
|
||||
'date': fiscalyear.periods[-1].end_date,
|
||||
'lines': [
|
||||
('create', [{
|
||||
'account': revenue.id,
|
||||
'debit': Decimal(100),
|
||||
}, {
|
||||
'account': expense.id,
|
||||
'credit': Decimal(30),
|
||||
}, {
|
||||
'account': account_pl.id,
|
||||
'credit': Decimal('70'),
|
||||
}]),
|
||||
],
|
||||
}])
|
||||
|
||||
session_id = self.balance_non_deferral.create()[0]
|
||||
balance_non_deferral = self.balance_non_deferral(session_id)
|
||||
|
||||
balance_non_deferral.start.fiscalyear = fiscalyear
|
||||
balance_non_deferral.start.journal = journal_closing
|
||||
balance_non_deferral.start.period = period_closing
|
||||
balance_non_deferral.start.credit_account = account_pl
|
||||
balance_non_deferral.start.debit_account = account_pl
|
||||
|
||||
balance_non_deferral._execute('balance')
|
||||
|
||||
moves = self.move.search([
|
||||
('state', '=', 'draft'),
|
||||
('period.fiscalyear', '=', fiscalyear.id),
|
||||
])
|
||||
self.move.post(moves)
|
||||
|
||||
# Close fiscalyear
|
||||
self.fiscalyear.close([fiscalyear])
|
||||
|
||||
# Check deferral
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<form string="Balance Non-Deferral">
|
||||
<label name="fiscalyear"/>
|
||||
<field name="fiscalyear"/>
|
||||
<newline/>
|
||||
<label name="journal"/>
|
||||
<field name="journal"/>
|
||||
<label name="period"/>
|
||||
<field name="period"/>
|
||||
<label name="credit_account"/>
|
||||
<field name="credit_account"/>
|
||||
<label name="debit_account"/>
|
||||
<field name="debit_account"/>
|
||||
</form>
|
||||
Reference in New Issue
Block a user