From f9cf118e9dc25bc3e48677ce003cf4008accd4e2 Mon Sep 17 00:00:00 2001 From: Albert Cervera i Areny Date: Tue, 22 Jan 2013 16:14:24 +0100 Subject: [PATCH] Make period's post_move_sequence optional review605004 issue2916 --- CHANGELOG | 1 + fiscalyear.py | 1 - move.py | 2 +- period.py | 23 +++++++++++++++++++---- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index fe81d2aad6..920d1d5e38 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Make period's post_move_sequence optional and use fiscal year's one if empty * Add sale, purchase or other kind on Tax Rule and Tax Group Version 2.6.0 - 2012-10-22 diff --git a/fiscalyear.py b/fiscalyear.py index 868be0a097..2c82c47861 100644 --- a/fiscalyear.py +++ b/fiscalyear.py @@ -167,7 +167,6 @@ class FiscalYear(ModelSQL, ModelView): 'start_date': period_start_date, 'end_date': period_end_date, 'fiscalyear': fiscalyear.id, - 'post_move_sequence': fiscalyear.post_move_sequence.id, 'type': 'standard', }) period_start_date = period_end_date + relativedelta(days=1) diff --git a/move.py b/move.py index 57e85d3cb7..8aad8414e0 100644 --- a/move.py +++ b/move.py @@ -364,7 +364,7 @@ class Move(ModelSQL, ModelView): if not move.post_number: values['post_date'] = Date.today() values['post_number'] = Sequence.get_id( - move.period.post_move_sequence.id) + move.period.post_move_sequence_used.id) cls.write([move], values) @classmethod diff --git a/period.py b/period.py index 0a95460977..a0bd3b0185 100644 --- a/period.py +++ b/period.py @@ -6,6 +6,7 @@ from trytond.pyson import Eval from trytond.transaction import Transaction from trytond.pool import Pool from trytond.const import OPERATORS +from trytond.backend import TableHandler __all__ = ['Period', 'ClosePeriod', 'ReOpenPeriod'] @@ -31,10 +32,8 @@ class Period(ModelSQL, ModelView): ('close', 'Close'), ], 'State', readonly=True, required=True) post_move_sequence = fields.Many2One('ir.sequence', 'Post Move Sequence', - required=True, domain=[('code', '=', 'account.move')], - context={'code': 'account.move'}, states={ - 'required': False, - }) + domain=[('code', '=', 'account.move')], + context={'code': 'account.move'}) type = fields.Selection([ ('standard', 'Standard'), ('adjustment', 'Adjustment'), @@ -43,6 +42,16 @@ class Period(ModelSQL, ModelView): company = fields.Function(fields.Many2One('company.company', 'Company',), 'get_company', searcher='search_company') + @classmethod + def __register__(cls, module_name): + cursor = Transaction().cursor + + super(Period, cls).__register__(module_name) + + table = TableHandler(cursor, cls, module_name) + # Migration from 2.6: post_move_sequence is no longer required + table.not_null_action('post_move_sequence', 'remove') + @classmethod def __setup__(cls): super(Period, cls).__setup__() @@ -111,6 +120,8 @@ class Period(ModelSQL, ModelView): or self.end_date > self.fiscalyear.end_date) def check_post_move_sequence(self): + if not self.post_move_sequence: + return True if self.search([ ('post_move_sequence', '=', self.post_move_sequence.id), ('fiscalyear', '!=', self.fiscalyear.id), @@ -257,6 +268,10 @@ class Period(ModelSQL, ModelView): 'state': 'open', }) + @property + def post_move_sequence_used(self): + return self.post_move_sequence or self.fiscalyear.post_move_sequence + class ClosePeriod(Wizard): 'Close Period'