Rename close state to closed

This commit is contained in:
Cédric Krier
2023-06-20 10:13:56 +02:00
parent 96fa0a1900
commit e16444665f
10 changed files with 61 additions and 33 deletions
+1
View File
@@ -1,3 +1,4 @@
* Rename close state to closed
* Ask for date when creating move from template
* Add receivable/payable to company
+1 -1
View File
@@ -1159,7 +1159,7 @@ class Account(
if not fiscalyear:
return values
if fiscalyear.state == 'close' and deferral:
if fiscalyear.state == 'closed' and deferral:
Deferral = pool.get(deferral)
id2deferral = {}
ids = [a.id for a in accounts]
+18 -9
View File
@@ -39,7 +39,7 @@ class FiscalYear(Workflow, ModelSQL, ModelView):
order=[('start_date', 'ASC'), ('id', 'ASC')])
state = fields.Selection([
('open', 'Open'),
('close', 'Close'),
('closed', 'Closed'),
('locked', 'Locked'),
], 'State', readonly=True, required=True, sort=False)
post_move_sequence = fields.Many2One(
@@ -59,9 +59,9 @@ class FiscalYear(Workflow, ModelSQL, ModelView):
super(FiscalYear, cls).__setup__()
cls._order.insert(0, ('start_date', 'DESC'))
cls._transitions |= set((
('open', 'close'),
('close', 'locked'),
('close', 'open'),
('open', 'closed'),
('closed', 'locked'),
('closed', 'open'),
))
cls._buttons.update({
'create_periods': {
@@ -74,11 +74,11 @@ class FiscalYear(Workflow, ModelSQL, ModelView):
'depends': ['state'],
},
'reopen': {
'invisible': Eval('state') != 'close',
'invisible': Eval('state') != 'closed',
'depends': ['state'],
},
'lock_': {
'invisible': Eval('state') != 'close',
'invisible': Eval('state') != 'closed',
'depends': ['state'],
},
})
@@ -86,6 +86,15 @@ class FiscalYear(Workflow, ModelSQL, ModelView):
'create_period': RPC(readonly=False, instantiate=0),
})
@classmethod
def __register__(cls, module):
cursor = Transaction().connection.cursor()
t = cls.__table__()
super().__register__(module)
# Migration from 6.8: rename state close to closed
cursor.execute(
*t.update([t.state], ['closed'], where=t.state == 'close'))
@staticmethod
def default_state():
return 'open'
@@ -97,7 +106,7 @@ class FiscalYear(Workflow, ModelSQL, ModelView):
def get_icon(self, name):
return {
'open': 'tryton-account-open',
'close': 'tryton-account-close',
'closed': 'tryton-account-close',
'locked': 'tryton-account-block',
}.get(self.state)
@@ -137,7 +146,7 @@ class FiscalYear(Workflow, ModelSQL, ModelView):
if year.state == 'open':
fiscalyears = cls.search([
('start_date', '>=', year.end_date),
('state', 'in', ['close', 'locked']),
('state', 'in', ['closed', 'locked']),
('company', '=', year.company.id),
],
limit=1,
@@ -313,7 +322,7 @@ class FiscalYear(Workflow, ModelSQL, ModelView):
@classmethod
@ModelView.button
@Workflow.transition('close')
@Workflow.transition('closed')
def close(cls, fiscalyears):
'''
Close a fiscal year
+17 -8
View File
@@ -19,7 +19,7 @@ from trytond.tools import (
from trytond.transaction import Transaction
STATES = {
'readonly': Eval('state') == 'close',
'readonly': Eval('state') == 'closed',
}
@@ -231,7 +231,7 @@ class JournalPeriod(
icon = fields.Function(fields.Char('Icon'), 'get_icon')
state = fields.Selection([
('open', 'Open'),
('close', 'Close'),
('closed', 'Closed'),
], 'State', readonly=True, required=True, sort=False)
@classmethod
@@ -243,8 +243,8 @@ class JournalPeriod(
'account.msg_journal_period_unique'),
]
cls._transitions |= set((
('open', 'close'),
('close', 'open'),
('open', 'closed'),
('closed', 'open'),
))
cls._buttons.update({
'close': {
@@ -252,12 +252,21 @@ class JournalPeriod(
'depends': ['state'],
},
'reopen': {
'invisible': Eval('state') != 'close',
'invisible': Eval('state') != 'closed',
'depends': ['state'],
},
})
cls.active.states = STATES
@classmethod
def __register__(cls, module):
cursor = Transaction().connection.cursor()
t = cls.__table__()
super().__register__(module)
# Migration from 6.8: rename state close to closed
cursor.execute(
*t.update([t.state], ['closed'], where=t.state == 'close'))
@staticmethod
def default_state():
return 'open'
@@ -279,7 +288,7 @@ class JournalPeriod(
def get_icon(self, name):
return {
'open': 'tryton-account-open',
'close': 'tryton-account-close',
'closed': 'tryton-account-close',
}.get(self.state)
@classmethod
@@ -312,7 +321,7 @@ class JournalPeriod(
def write(cls, *args):
actions = iter(args)
for journal_periods, values in zip(actions, actions):
if (values != {'state': 'close'}
if (values != {'state': 'closed'}
and values != {'state': 'open'}):
cls._check(journal_periods)
if values.get('state') == 'open':
@@ -332,7 +341,7 @@ class JournalPeriod(
@classmethod
@ModelView.button
@Workflow.transition('close')
@Workflow.transition('closed')
def close(cls, periods):
'''
Close journal - period
+3 -3
View File
@@ -358,7 +358,7 @@ class Move(ModelSQL, ModelView):
default = {
'origin': str(self),
}
if self.period.state == 'close':
if self.period.state == 'closed':
key = '%s.cancel' % self
if Warning.check(key):
raise CancelWarning(key,
@@ -1300,7 +1300,7 @@ class Line(MoveLineMixin, ModelSQL, ModelView):
], limit=1)
if journal_periods:
journal_period, = journal_periods
if journal_period.state == 'close':
if journal_period.state == 'closed':
raise AccessError(
gettext('account.msg_modify_line_closed_journal_period',
journal_period=journal_period.rec_name))
@@ -1748,7 +1748,7 @@ class OpenJournalAsk(ModelView):
journal = fields.Many2One('account.journal', 'Journal', required=True)
period = fields.Many2One('account.period', 'Period', required=True,
domain=[
('state', '!=', 'close'),
('state', '!=', 'closed'),
])
@classmethod
+1 -1
View File
@@ -403,7 +403,7 @@ class CreateMoveTemplate(ModelView):
date = fields.Date('Effective Date', required=True)
period = fields.Many2One('account.period', 'Period', required=True,
domain=[
('state', '!=', 'close'),
('state', '!=', 'closed'),
('fiscalyear.company.id', '=',
Eval('context', {}).get('company', 0)),
])
+17 -8
View File
@@ -31,7 +31,7 @@ class Period(Workflow, ModelSQL, ModelView):
'account.fiscalyear', "Fiscal Year", required=True, states=_STATES)
state = fields.Selection([
('open', 'Open'),
('close', 'Close'),
('closed', 'Closed'),
('locked', 'Locked'),
], 'State', readonly=True, required=True, sort=False)
post_move_sequence = fields.Many2One('ir.sequence', 'Post Move Sequence',
@@ -66,9 +66,9 @@ class Period(Workflow, ModelSQL, ModelView):
order='DESC'))
cls._order.insert(0, ('start_date', 'DESC'))
cls._transitions |= set((
('open', 'close'),
('close', 'locked'),
('close', 'open'),
('open', 'closed'),
('closed', 'locked'),
('closed', 'open'),
))
cls._buttons.update({
'close': {
@@ -76,15 +76,24 @@ class Period(Workflow, ModelSQL, ModelView):
'depends': ['state'],
},
'reopen': {
'invisible': Eval('state') != 'close',
'invisible': Eval('state') != 'closed',
'depends': ['state'],
},
'lock_': {
'invisible': Eval('state') != 'close',
'invisible': Eval('state') != 'closed',
'depends': ['state'],
},
})
@classmethod
def __register__(cls, module):
cursor = Transaction().connection.cursor()
t = cls.__table__()
super().__register__(module)
# Migration from 6.8: rename state close to closed
cursor.execute(
*t.update([t.state], ['closed'], where=t.state == 'close'))
@staticmethod
def default_state():
return 'open'
@@ -104,7 +113,7 @@ class Period(Workflow, ModelSQL, ModelView):
def get_icon(self, name):
return {
'open': 'tryton-account-open',
'close': 'tryton-account-close',
'closed': 'tryton-account-close',
'locked': 'tryton-account-block',
}.get(self.state)
@@ -338,7 +347,7 @@ class Period(Workflow, ModelSQL, ModelView):
@classmethod
@ModelView.button
@Workflow.transition('close')
@Workflow.transition('closed')
def close(cls, periods):
pool = Pool()
JournalPeriod = pool.get('account.journal.period')
@@ -142,7 +142,7 @@ Close fiscalyear::
>>> fiscalyear.click('close')
>>> fiscalyear.state
'close'
'closed'
Check receivable amounts after closing fiscalyear::
+1 -1
View File
@@ -60,7 +60,7 @@ class Period(metaclass=PoolMeta):
@classmethod
@ModelView.button
@Workflow.transition('close')
@Workflow.transition('closed')
def close(cls, periods):
pool = Pool()
Invoice = pool.get('account.invoice')
+1 -1
View File
@@ -47,7 +47,7 @@ class Period(metaclass=PoolMeta):
@classmethod
@ModelView.button
@Workflow.transition('close')
@Workflow.transition('closed')
def close(cls, periods):
pool = Pool()
MoveLine = pool.get('account.move.line')