diff --git a/account.py b/account.py index 2f73f2c8ac..79f77b907a 100644 --- a/account.py +++ b/account.py @@ -280,6 +280,11 @@ class Reconciliation(metaclass=PoolMeta): class RenewFiscalYear(metaclass=PoolMeta): __name__ = 'account.fiscalyear.renew' + def fiscalyear_defaults(self): + defaults = super(RenewFiscalYear, self).fiscalyear_defaults() + defaults['invoice_sequences'] = None + return defaults + @property def invoice_sequence_fields(self): return ['out_invoice_sequence', 'out_credit_note_sequence', @@ -290,6 +295,24 @@ class RenewFiscalYear(metaclass=PoolMeta): Sequence = pool.get('ir.sequence.strict') InvoiceSequence = pool.get('account.fiscalyear.invoice_sequence') fiscalyear = super(RenewFiscalYear, self).create_fiscalyear() + + def standard_period(period): + return period.type == 'standard' + + period_mapping = {} + for previous, new in zip( + filter( + standard_period, self.start.previous_fiscalyear.periods), + filter(standard_period, fiscalyear.periods)): + period_mapping[previous] = new.id + + InvoiceSequence.copy( + self.start.previous_fiscalyear.invoice_sequences, + default={ + 'fiscalyear': fiscalyear.id, + 'period': lambda data: period_mapping.get(data['period']), + }) + if not self.start.reset_sequences: return fiscalyear sequences = OrderedDict() diff --git a/tests/scenario_renew_fiscalyear.rst b/tests/scenario_renew_fiscalyear.rst new file mode 100644 index 0000000000..9c47a89e8e --- /dev/null +++ b/tests/scenario_renew_fiscalyear.rst @@ -0,0 +1,87 @@ +========================= +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 + >>> from trytond.modules.account_invoice.tests.tools \ + ... import set_fiscalyear_invoice_sequences + >>> today = datetime.date.today() + >>> end_year = today + relativedelta(month=12, day=31) + +Install account:: + + >>> config = activate_modules('account_invoice') + +Create company:: + + >>> _ = create_company() + >>> company = get_company() + +Create fiscal year:: + + >>> InvoiceSequence = Model.get('account.fiscalyear.invoice_sequence') + >>> fiscalyear = create_fiscalyear(company) + >>> fiscalyear = set_fiscalyear_invoice_sequences(fiscalyear) + >>> fiscalyear.click('create_period') + >>> inv_seq, = fiscalyear.invoice_sequences + >>> seq = inv_seq.out_invoice_sequence + >>> for period in fiscalyear.periods: + ... seq, = seq.duplicate() + ... _ = inv_seq.duplicate(default={ + ... 'period': period.id, + ... 'out_invoice_sequence': seq.id, + ... 'in_invoice_sequence': seq.id, + ... 'out_credit_note_sequence': seq.id, + ... 'in_credit_note_sequence': seq.id, + ... }) + >>> 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() + + >>> for i, seq in enumerate(fiscalyear.invoice_sequences): + ... seq.out_invoice_sequence.number_next = i + ... seq.out_invoice_sequence.save() + +Renew fiscal year 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 + >>> int(new_fiscalyear.post_move_sequence.number_next) + 10 + >>> [int(seq.out_invoice_sequence.number_next) + ... for seq in fiscalyear.invoice_sequences] + [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] + +Renew fiscal year resetting sequences:: + + >>> renew_fiscalyear = Wizard('account.fiscalyear.renew') + >>> renew_fiscalyear.form.reset_sequences = True + >>> renew_fiscalyear.execute('create_') + >>> new_fiscalyear, = renew_fiscalyear.actions[0] + >>> int(new_fiscalyear.post_move_sequence.number_next) + 1 + >>> [int(seq.out_invoice_sequence.number_next) + ... for seq in new_fiscalyear.invoice_sequences] + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] diff --git a/tests/test_account_invoice.py b/tests/test_account_invoice.py index 2ee4106168..0cde7e3c34 100644 --- a/tests/test_account_invoice.py +++ b/tests/test_account_invoice.py @@ -225,4 +225,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