Put post move sequence on fiscal years/periods and use it for reference of

posted move.
Use the journal sequence for default move name
Add constraint on modification of post move sequence
This commit is contained in:
Cédric Krier
2008-04-01 10:38:15 +02:00
parent 6e5529af28
commit 41fad50b01
6 changed files with 75 additions and 9 deletions
+27
View File
@@ -27,6 +27,8 @@ class FiscalYear(OSV):
('open', 'Open'),
('close', 'Close'),
], 'State', readonly=True, required=True)
post_move_sequence = fields.Many2One('ir.sequence', 'Post Move Sequence',
required=True, domain="[('code', '=', 'account.move')]")
def __init__(self):
super(FiscalYear, self).__init__()
@@ -38,6 +40,9 @@ class FiscalYear(OSV):
('check_dates',
'Error! You can not have 2 fiscal years that overlaps!',
['start_date', 'end_date']),
('check_post_move_sequence',
'Error! You must have different post move sequence ' \
'per fiscal year!', ['post_move_sequence']),
]
def default_state(self, cursor, user, context=None):
@@ -59,6 +64,27 @@ class FiscalYear(OSV):
return False
return True
def check_post_move_sequence(self, cursor, user, ids):
for fiscalyear in self.browse(cursor, user, ids):
if self.search(cursor, user, [
('post_move_sequence', '=', fiscalyear.post_move_sequence.id),
('id', '!=', fiscalyear.id),
]):
return False
return True
def write(self, cursor, user, ids, vals, context=None):
move_obj = self.pool.get('account.move')
if vals.get('post_move_sequence'):
for fiscalyear in self.browse(cursor, user, ids, context=context):
if fiscalyear.post_move_sequence and \
fiscalyear.post_move_sequence.id != \
vals['post_move_sequence']:
raise ExceptORM('UserError', 'You can not change ' \
'the post move sequence')
return super(FiscalYear, self).write(cursor, user, ids, vals,
context=context)
def create_period(self, cursor, user, ids, context=None, interval=1):
'''
Create periods for the fiscal years with month interval
@@ -83,6 +109,7 @@ class FiscalYear(OSV):
'start_date': period_start_date.strftime('%Y-%m-%d'),
'end_date': period_end_date.strftime('%Y-%m-%d'),
'fiscalyear': fiscalyear.id,
'post_move_sequence': fiscalyear.post_move_sequence.id,
}, context=context)
period_start_date = period_end_date + \
mx.DateTime.RelativeDateTime(days=1)
+2
View File
@@ -15,6 +15,8 @@
<field name="start_date"/>
<label name="end_date"/>
<field name="end_date"/>
<label name="post_move_sequence"/>
<field name="post_move_sequence"/>
<field name="periods" colspan="4"/>
<group col="2" colspan="4">
<button name="create_period" string="Create Monthly Periods"
+14 -5
View File
@@ -63,10 +63,6 @@ class Move(OSV):
cursor.execute('CREATE INDEX account_move_journal_period_index ' \
'ON account_move (period, journal)')
def default_name(self, cursor, user, context=None):
sequence_obj = self.pool.get('ir.sequence')
return sequence_obj.get(cursor, user, 'account.move')
def default_period(self, cursor, user, context=None):
period_obj = self.pool.get('account.period')
return period_obj.find(cursor, user, exception=False, context=context)
@@ -128,6 +124,18 @@ class Move(OSV):
def create(self, cursor, user, vals, context=None):
move_line_obj = self.pool.get('account.move.line')
sequence_obj = self.pool.get('ir.sequence')
journal_obj = self.pool.get('account.journal')
if context is None:
context = {}
if not vals.get('name'):
vals = vals.copy()
journal = journal_obj.browse(cursor, user,
vals.get('journal', context.get('journal')),
context=context)
vals['name'] = sequence_obj.get_id(cursor, user, journal.sequence.id)
res = super(Move, self).create(cursor, user, vals, context=context)
move = self.browse(cursor, user, res, context=context)
@@ -227,7 +235,8 @@ class Move(OSV):
raise ExceptORM('UserError',
'You can not post a unbalanced move!')
for move in moves:
reference = sequence_obj.get_id(cursor, user, move.journal.sequence.id)
reference = sequence_obj.get_id(cursor, user,
move.period.post_move_sequence.id)
self.write(cursor, user, move.id, {
'reference': reference,
'state': 'posted',
-4
View File
@@ -93,10 +93,6 @@
<field name="name">Account Move</field>
<field name="code">account.move</field>
</record>
<record model="ir.sequence" id="sequence_account_move">
<field name="name">Default Account Move</field>
<field name="code">account.move</field>
</record>
<record model="ir.ui.view" id="move_reconciliation_view_form">
<field name="model">account.move.reconciliation</field>
+29
View File
@@ -25,6 +25,8 @@ class Period(OSV):
('open', 'Open'),
('close', 'Close'),
], 'State', readonly=True, required=True)
post_move_sequence =fields.Many2One('ir.sequence', 'Post Move Sequence',
required=True, domain="[('code', '=', 'account.move')]")
def __init__(self):
super(Period, self).__init__()
@@ -32,6 +34,9 @@ class Period(OSV):
('check_dates',
'Error! You can not have 2 periods that overlaps!',
['start_date', 'end_date']),
('check_post_move_sequence',
'Error! You must have different post move sequence ' \
'per fiscal year!', ['post_move_sequence']),
]
def default_state(self, cursor, user, context=None):
@@ -53,6 +58,15 @@ class Period(OSV):
return False
return True
def check_post_move_sequence(self, cursor, user, ids):
for period in self.browse(cursor, user, ids):
if self.search(cursor, user, [
('post_move_sequence', '=', period.post_move_sequence.id),
('fiscalyear', '!=', period.fiscalyear.id),
]):
return False
return True
def find(self, cursor, user, date=None, exception=True, context=None):
'''
Return the period for the date or the current date.
@@ -108,9 +122,12 @@ class Period(OSV):
if fiscalyear.state == 'close':
raise ExceptORM('UserError', 'You can not create ' \
'a period on a closed fiscal year!')
if not vals.get('post_move_sequence'):
vals['post_move_sequence'] = fiscalyear.post_move_sequence.id
return super(Period, self).create(cursor, user, vals, context=context)
def write(self, cursor, user, ids, vals, context=None):
move_obj = self.pool.get('account.move')
if vals != {'state': 'close'} \
and vals != {'state': 'open'}:
self._check(cursor, user, ids, context=context)
@@ -120,6 +137,18 @@ class Period(OSV):
if period.fiscalyear.state == 'close':
raise ExceptORM('UserError', 'You can not open ' \
'a period from a closed fiscal year!')
if vals.get('post_move_sequence'):
for period in self.browse(cursor, user, ids, context=context):
if period.post_move_sequence and \
period.post_move_sequence.id != \
vals['post_move_sequence']:
if move_obj.search(cursor, user, [
('period', '=', period.id),
('state', '=', 'posted'),
], context=context):
raise ExceptORM('UserError', 'You can not change ' \
'the post move sequence \n' \
'if there is already posted move in the period')
return super(Period, self).write(cursor, user, ids, vals,
context=context)
+3
View File
@@ -18,6 +18,9 @@
<label name="fiscalyear"/>
<field name="fiscalyear"/>
<newline/>
<label name="post_move_sequence"/>
<field name="post_move_sequence" required="0"/>
<newline/>
<label name="state"/>
<field name="state" colspan="3"/>
</form>