Add wizard to ease creation of fiscalyear

issue6283
review33891002
This commit is contained in:
Sergi Almacellas Abellana
2017-09-28 11:37:00 +02:00
parent aa71a1e6f5
commit 8a2727d7d4
8 changed files with 219 additions and 1 deletions
+1
View File
@@ -1,3 +1,4 @@
* Ease creation of new fiscalyear
* Drop required on party payable and receivable accounts
* Make tax description translatable
* Add searcher on General Ledger
+2
View File
@@ -78,6 +78,7 @@ def register():
CreateMoveKeywords,
Party,
PartyAccount,
RenewFiscalYearStart,
module='account', type_='model')
Pool.register(
BalanceNonDeferral,
@@ -96,6 +97,7 @@ def register():
OpenTaxCode,
TestTax,
PartyReplace,
RenewFiscalYear,
module='account', type_='wizard')
Pool.register(
GeneralLedger,
+113 -1
View File
@@ -1,5 +1,7 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from __future__ import division
from dateutil.relativedelta import relativedelta
from trytond.model import ModelView, ModelSQL, Workflow, fields
from trytond.wizard import Wizard, StateView, StateAction, Button
@@ -9,7 +11,8 @@ from trytond.transaction import Transaction
from trytond.pool import Pool
__all__ = ['FiscalYear', 'FiscalYearLine',
'BalanceNonDeferralStart', 'BalanceNonDeferral']
'BalanceNonDeferralStart', 'BalanceNonDeferral',
'RenewFiscalYearStart', 'RenewFiscalYear']
STATES = {
'readonly': Eval('state') != 'open',
@@ -478,3 +481,112 @@ class BalanceNonDeferral(Wizard):
('origin', '=', str(self.start.fiscalyear)),
])
return action, {}
def month_delta(d1, d2):
return (d1.year - d2.year) * 12 + d1.month - d2.month
class RenewFiscalYearStart(ModelView):
"Renew Fiscal Year Start"
__name__ = 'account.fiscalyear.renew.start'
name = fields.Char("Name", required=True)
company = fields.Many2One('company.company', "Company", required=True)
previous_fiscalyear = fields.Many2One(
'account.fiscalyear', "Previous Fiscalyear", required=True,
domain=[
('company', '=', Eval('company')),
],
depends=['company'],
help="Used as reference for fiscalyear configuration.")
start_date = fields.Date("Start Date", required=True)
end_date = fields.Date("End Date", required=True)
reset_sequences = fields.Boolean("Reset Sequences",
help="If checked, new sequences will be created.")
@classmethod
def default_company(cls):
return Transaction().context.get('company')
@classmethod
def default_previous_fiscalyear(cls):
pool = Pool()
FiscalYear = pool.get('account.fiscalyear')
fiscalyears = FiscalYear.search([
('company', '=', cls.default_company() or -1),
],
order=[('end_date', 'DESC')], limit=1)
if fiscalyears:
fiscalyear, = fiscalyears
return fiscalyear.id
@classmethod
def default_reset_sequences(cls):
return True
@fields.depends('previous_fiscalyear')
def on_change_previous_fiscalyear(self):
if self.previous_fiscalyear:
fiscalyear = self.previous_fiscalyear
months = month_delta(
fiscalyear.end_date, fiscalyear.start_date) + 1
self.start_date = fiscalyear.start_date + relativedelta(
months=months, day=fiscalyear.start_date.day)
self.end_date = fiscalyear.end_date + relativedelta(
months=months, day=fiscalyear.end_date.day)
self.name = fiscalyear.name.replace(
str(fiscalyear.end_date.year),
str(self.end_date.year)).replace(
str(fiscalyear.start_date.year),
str(self.start_date.year))
class RenewFiscalYear(Wizard):
"Renew Fiscal Year"
__name__ = 'account.fiscalyear.renew'
start = StateView('account.fiscalyear.renew.start',
'account.fiscalyear_renew_start_view_form', [
Button("Cancel", 'end', 'tryton-cancel'),
Button("Create", 'create_', 'tryton-ok', default=True),
])
create_ = StateAction('account.act_fiscalyear_form')
def fiscalyear_defaults(self):
pool = Pool()
Sequence = pool.get('ir.sequence')
defaults = {
'name': self.start.name,
'start_date': self.start.start_date,
'end_date': self.start.end_date,
'periods': [],
}
previous_sequence = self.start.previous_fiscalyear.post_move_sequence
sequence, = Sequence.copy([previous_sequence])
if self.start.reset_sequences:
sequence.number_next = 1
else:
sequence.number_next = previous_sequence.number_next
sequence.save()
defaults['post_move_sequence'] = sequence.id
return defaults
def create_fiscalyear(self):
pool = Pool()
FiscalYear = pool.get('account.fiscalyear')
fiscalyear, = FiscalYear.copy(
[self.start.previous_fiscalyear],
default=self.fiscalyear_defaults())
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])
return fiscalyear
def do_create_(self, action):
fiscalyear = self.create_fiscalyear()
action['res_id'] = [fiscalyear.id]
action['views'].reverse()
return action, {}
+18
View File
@@ -98,5 +98,23 @@ this repository contains the full copyright notices and license terms. -->
<menuitem parent="menu_processing" sequence="10"
action="act_balance_non_deferral"
id="menu_balance_non_deferral"/>
<record model="ir.ui.view" id="fiscalyear_renew_start_view_form">
<field name="model">account.fiscalyear.renew.start</field>
<field name="type">form</field>
<field name="name">renew_fiscalyear_start_form</field>
</record>
<record model="ir.action.wizard" id="act_renew_fiscalyear">
<field name="name">Renew Fiscal Year</field>
<field name="wiz_name">account.fiscalyear.renew</field>
</record>
<record model="ir.action-res.group"
id="act_renew_fiscalyear_group_admin">
<field name="action" ref="act_renew_fiscalyear"/>
<field name="group" ref="group_account_admin"/>
</record>
<menuitem parent="menu_fiscalyear_configuration" sequence="20"
action="act_renew_fiscalyear" id="menu_renew_fiscalyear"/>
</data>
</tryton>
+1
View File
@@ -128,5 +128,6 @@ setup(name=name,
'tests/scenario_move_cancel.rst',
'tests/scenario_move_template.rst',
'tests/scenario_reports.rst',
'tests/scenario_renew_fiscalyear.rst',
],
)
+62
View File
@@ -0,0 +1,62 @@
=================================
Account Renew Fiscalyear Scenario
=================================
Imports::
>>> import datetime
>>> from dateutil.relativedelta import relativedelta
>>> from decimal import Decimal
>>> from proteus import Model, Wizard, Report
>>> from trytond.tests.tools import activate_modules
>>> from trytond.modules.company.tests.tools import create_company, \
... get_company
>>> from trytond.modules.account.tests.tools import create_fiscalyear
>>> today = datetime.date.today()
>>> end_year = today + relativedelta(month=12, day=31)
Install account::
>>> config = activate_modules('account')
Create company::
>>> _ = create_company()
>>> company = get_company()
Create fiscal year::
>>> fiscalyear = create_fiscalyear(company)
>>> fiscalyear.click('create_period')
>>> period = fiscalyear.periods.new()
>>> period.name = 'Adjustment'
>>> period.start_date = end_year
>>> period.end_date = end_year
>>> period.type = 'adjustment'
>>> fiscalyear.save()
Set the sequence number::
>>> sequence = fiscalyear.post_move_sequence
>>> sequence.number_next = 10
>>> sequence.save()
Renew fiscalyear using the wizard::
>>> renew_fiscalyear = Wizard('account.fiscalyear.renew')
>>> renew_fiscalyear.form.reset_sequences = False
>>> renew_fiscalyear.execute('create_')
>>> new_fiscalyear, = renew_fiscalyear.actions[0]
>>> len(new_fiscalyear.periods)
12
>>> new_fiscalyear.post_move_sequence.number_next
10
Renew fiscalyear resetting sequences::
>>> renew_fiscalyear = Wizard('account.fiscalyear.renew')
>>> renew_fiscalyear.form.reset_sequences = True
>>> renew_fiscalyear.execute('create_')
>>> new_fiscalyear, = renew_fiscalyear.actions[0]
>>> new_fiscalyear.post_move_sequence.number_next
1
+5
View File
@@ -1046,4 +1046,9 @@ def suite():
tearDown=doctest_teardown, encoding='utf-8',
checker=doctest_checker,
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
suite.addTests(doctest.DocFileSuite(
'scenario_renew_fiscalyear.rst',
tearDown=doctest_teardown, encoding='utf-8',
checker=doctest_checker,
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
return suite
+17
View File
@@ -0,0 +1,17 @@
<?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>
<label name="previous_fiscalyear"/>
<field name="previous_fiscalyear"/>
<label name="company"/>
<field name="company"/>
<label name="name"/>
<field name="name" colspan="3"/>
<label name="start_date"/>
<field name="start_date"/>
<label name="end_date"/>
<field name="end_date"/>
<label name="reset_sequences"/>
<field name="reset_sequences"/>
</form>