Update for new Transaction

This commit is contained in:
Cédric Krier
2010-08-19 22:02:00 +02:00
parent d2bdf21175
commit 7e4d193ddc
8 changed files with 1227 additions and 1636 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ Installing trytond_account
Prerequisites
-------------
* Python 2.4 or later (http://www.python.org/)
* Python 2.5 or later (http://www.python.org/)
* python-dateutil (http://labix.org/python-dateutil)
* trytond (http://www.tryton.org/)
* trytond_company (http://www.tryton.org/)
+502 -664
View File
File diff suppressed because it is too large Load Diff
+69 -95
View File
@@ -1,13 +1,13 @@
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
'Fiscal Year'
import datetime
import time
from dateutil.relativedelta import relativedelta
from trytond.model import ModelView, ModelSQL, fields
from trytond.wizard import Wizard
from trytond.tools import datetime_strftime
from trytond.pyson import Equal, Eval, If, In, Get
import datetime
import time
from dateutil.relativedelta import relativedelta
from trytond.transaction import Transaction
STATES = {
'readonly': Equal(Eval('state'), 'close'),
@@ -78,18 +78,15 @@ class FiscalYear(ModelSQL, ModelView):
'there is more recent fiscal year closed!',
})
def default_state(self, cursor, user, context=None):
def default_state(self):
return 'open'
def default_company(self, cursor, user, context=None):
if context is None:
context = {}
if context.get('company'):
return context['company']
return False
def default_company(self):
return Transaction().context.get('company') or False
def check_dates(self, cursor, user, ids):
for fiscalyear in self.browse(cursor, user, ids):
def check_dates(self, ids):
cursor = Transaction().cursor
for fiscalyear in self.browse(ids):
cursor.execute('SELECT id ' \
'FROM ' + self._table + ' ' \
'WHERE ((start_date <= %s AND end_date >= %s) ' \
@@ -105,49 +102,46 @@ class FiscalYear(ModelSQL, ModelView):
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, [
def check_post_move_sequence(self, ids):
for fiscalyear in self.browse(ids):
if self.search([
('post_move_sequence', '=', fiscalyear.post_move_sequence.id),
('id', '!=', fiscalyear.id),
]):
return False
return True
def write(self, cursor, user, ids, vals, context=None):
def write(self, ids, vals):
move_obj = self.pool.get('account.move')
if vals.get('post_move_sequence'):
for fiscalyear in self.browse(cursor, user, ids, context=context):
for fiscalyear in self.browse(ids):
if fiscalyear.post_move_sequence and \
fiscalyear.post_move_sequence.id != \
vals['post_move_sequence']:
self.raise_user_error(cursor, 'change_post_move_sequence',
context=context)
self.raise_user_error('change_post_move_sequence')
vals = vals.copy()
if 'periods' in vals:
operator = ['delete', 'unlink_all', 'unlink', 'create', 'write',
'add', 'set']
vals['periods'].sort(
lambda x, y: cmp(operator.index(x[0]), operator.index(y[0])))
return super(FiscalYear, self).write(cursor, user, ids, vals,
context=context)
return super(FiscalYear, self).write(ids, vals)
def delete(self, cursor, user, ids, context=None):
def delete(self, ids):
period_obj = self.pool.get('account.period')
period_ids = []
for fiscalyear in self.browse(cursor, user, ids, context=context):
for fiscalyear in self.browse(ids):
period_ids.extend([x.id for x in fiscalyear.periods])
period_obj.delete(cursor, user, period_ids, context=context)
return super(FiscalYear, self).delete(cursor, user, ids,
context=context)
period_obj.delete(period_ids)
return super(FiscalYear, self).delete(ids)
def create_period(self, cursor, user, ids, context=None, interval=1):
def create_period(self, ids, interval=1):
'''
Create periods for the fiscal years with month interval
'''
period_obj = self.pool.get('account.period')
for fiscalyear in self.browse(cursor, user, ids, context=context):
for fiscalyear in self.browse(ids):
period_start_date = fiscalyear.start_date
while period_start_date < fiscalyear.end_date:
period_end_date = period_start_date + \
@@ -158,26 +152,24 @@ class FiscalYear(ModelSQL, ModelView):
name = datetime_strftime(period_start_date, '%Y-%m')
if name != datetime_strftime(period_end_date, '%Y-%m'):
name += ' - ' + datetime_strftime(period_end_date, '%Y-%m')
period_obj.create(cursor, user, {
period_obj.create({
'name': name,
'start_date': period_start_date,
'end_date': period_end_date,
'fiscalyear': fiscalyear.id,
'post_move_sequence': fiscalyear.post_move_sequence.id,
'type': 'standard',
}, context=context)
})
period_start_date = period_end_date + relativedelta(days=1)
return True
def create_period_3(self, cursor, user, ids, context=None):
def create_period_3(self, ids):
'''
Create periods for the fiscal years with 3 months interval
'''
return self.create_period(cursor, user, ids, context=context,
interval=3)
return self.create_period(ids, interval=3)
def find(self, cursor, user, company_id, date=None, exception=True,
context=None):
def find(self, company_id, date=None, exception=True):
'''
Return the fiscal year for the company_id
at the date or the current date.
@@ -187,29 +179,25 @@ class FiscalYear(ModelSQL, ModelView):
date_obj = self.pool.get('ir.date')
if not date:
date = date_obj.today(cursor, user, context=context)
ids = self.search(cursor, user, [
date = date_obj.today()
ids = self.search([
('start_date', '<=', date),
('end_date', '>=', date),
('company', '=', company_id),
], order=[('start_date', 'DESC')], limit=1, context=context)
], order=[('start_date', 'DESC')], limit=1)
if not ids:
if exception:
self.raise_user_error(cursor, 'no_fiscalyear_date',
context=context)
self.raise_user_error('no_fiscalyear_date')
else:
return False
return ids[0]
def _process_account(self, cursor, user, account, fiscalyear, context=None):
def _process_account(self, account, fiscalyear):
'''
Process account for a fiscal year closed
:param cursor: the database cursor
:param user: the user id
:param account: a BrowseRecord of the account
:param fiscalyear: a BrowseRecord of the fiscal year closed
:param context: the context
'''
currency_obj = self.pool.get('currency.currency')
deferral_obj = self.pool.get('account.account.deferral')
@@ -217,99 +205,86 @@ class FiscalYear(ModelSQL, ModelView):
if account.kind == 'view':
return
if not account.deferral:
if not currency_obj.is_zero(cursor, user,
fiscalyear.company.currency, account.balance):
self.raise_user_error(cursor, 'account_balance_not_zero',
error_args=(account.rec_name,), context=context)
if not currency_obj.is_zero(fiscalyear.company.currency,
account.balance):
self.raise_user_error('account_balance_not_zero',
error_args=(account.rec_name,))
else:
deferral_obj.create(cursor, user, {
deferral_obj.create({
'account': account.id,
'fiscalyear': fiscalyear.id,
'debit': account.debit,
'credit': account.credit,
}, context=context)
})
def close(self, cursor, user, fiscalyear_id, context=None):
def close(self, fiscalyear_id):
'''
Close a fiscal year
:param cursor: the database cursor
:param user: the user id
:param fiscalyear_id: the fiscal year id
:param context: the context
'''
period_obj = self.pool.get('account.period')
account_obj = self.pool.get('account.account')
if context is None:
context = {}
if isinstance(fiscalyear_id, list):
fiscalyear_id = fiscalyear_id[0]
fiscalyear = self.browse(cursor, user, fiscalyear_id, context=context)
fiscalyear = self.browse(fiscalyear_id)
if self.search(cursor, user, [
if self.search([
('end_date', '<=', fiscalyear.start_date),
('state', '=', 'open'),
('company', '=', fiscalyear.company.id),
], context=context):
self.raise_user_error(cursor, 'close_error', context=context)
]):
self.raise_user_error('close_error')
#First close the fiscalyear to be sure
#it will not have new period created between.
self.write(cursor, user, fiscalyear_id, {
self.write(fiscalyear_id, {
'state': 'close',
}, context=context)
period_ids = period_obj.search(cursor, user, [
})
period_ids = period_obj.search([
('fiscalyear', '=', fiscalyear_id),
], context=context)
period_obj.close(cursor, user, period_ids, context=context)
])
period_obj.close(period_ids)
ctx = context.copy()
ctx['fiscalyear'] = fiscalyear_id
if 'date' in context:
del context['date']
with Transaction().set_context(fiscalyear=fiscalyear_id,
date=False):
account_ids = account_obj.search([
('company', '=', fiscalyear.company.id),
])
accounts = account_obj.browse(account_ids)
for account in accounts:
self._process_account(account, fiscalyear)
account_ids = account_obj.search(cursor, user, [
('company', '=', fiscalyear.company.id),
], context=ctx)
for account in account_obj.browse(cursor, user, account_ids,
context=ctx):
self._process_account(cursor, user, account, fiscalyear,
context=context)
def reopen(self, cursor, user, fiscalyear_id, context=None):
def reopen(self, fiscalyear_id):
'''
Re-open a fiscal year
:param cursor: the database cursor
:param user: the user id
:param fiscalyear_id: the fiscal year id
:param context: the context
'''
deferral_obj = self.pool.get('account.account.deferral')
if isinstance(fiscalyear_id, list):
fiscalyear_id = fiscalyear_id[0]
fiscalyear = self.browse(cursor, user, fiscalyear_id, context=context)
fiscalyear = self.browse(fiscalyear_id)
if self.search(cursor, user, [
if self.search([
('start_date', '>=', fiscalyear.end_date),
('state', '=', 'close'),
('company', '=', fiscalyear.company.id),
], context=context):
self.raise_user_error(cursor, 'reopen_error', context=context)
]):
self.raise_user_error('reopen_error')
deferral_ids = deferral_obj.search(cursor, user, [
deferral_ids = deferral_obj.search([
('fiscalyear', '=', fiscalyear_id),
], context=context)
deferral_obj.delete(cursor, user, deferral_ids, context=context)
])
deferral_obj.delete(deferral_ids)
self.write(cursor, user, fiscalyear_id, {
self.write(fiscalyear_id, {
'state': 'open',
}, context=context)
})
FiscalYear()
@@ -348,11 +323,10 @@ class CloseFiscalYear(Wizard):
},
}
def _close(self, cursor, user, data, context=None):
def _close(self, data):
fiscalyear_obj = self.pool.get('account.fiscalyear')
fiscalyear_obj.close(cursor, user, data['form']['close_fiscalyear'],
context=context)
fiscalyear_obj.close(data['form']['close_fiscalyear'])
return {}
CloseFiscalYear()
+50 -57
View File
@@ -1,10 +1,11 @@
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
"Journal"
from __future__ import with_statement
from trytond.model import ModelView, ModelSQL, fields
from trytond.wizard import Wizard
from trytond.backend import TableHandler
from trytond.pyson import Equal, Eval, Not, Get, Or, And, Bool
from trytond.transaction import Transaction
STATES = {
'readonly': Equal(Eval('state'), 'close'),
@@ -64,10 +65,10 @@ class Column(ModelSQL, ModelView):
super(Column, self).__init__()
self._order.insert(0, ('sequence', 'ASC'))
def default_required(self, cursor, user, context=None):
def default_required(self):
return False
def default_readonly(self, cursor, user, context=None):
def default_readonly(self):
return False
Column()
@@ -118,42 +119,44 @@ class Journal(ModelSQL, ModelView):
super(Journal, self).__init__()
self._order.insert(0, ('name', 'ASC'))
def init(self, cursor, module_name):
super(Journal, self).init(cursor, module_name)
def init(self, module_name):
super(Journal, self).init(module_name)
cursor = Transaction().cursor
table = TableHandler(cursor, self, module_name)
# Migration from 1.0 sequence Many2One change into Property
if table.column_exist('sequence'):
property_obj = self.pool.get('ir.property')
cursor.execute('SELECT id, sequence FROM "' + self._table +'"')
for journal_id, sequence_id in cursor.fetchall():
property_obj.set(cursor, 0, 'sequence', self._name,
journal_id, (sequence_id and \
with Transaction().set_user(0):
for journal_id, sequence_id in cursor.fetchall():
property_obj.set('sequence', self._name,
journal_id, (sequence_id and
'ir.sequence,' + str(sequence_id) or False))
table.drop_column('sequence', exception=True)
def default_active(self, cursor, user, context=None):
def default_active(self):
return True
def default_centralised(self, cursor, user, context=None):
def default_centralised(self):
return False
def default_update_posted(self, cursor, user, context=None):
def default_update_posted(self):
return False
def default_sequence(self, cursor, user, context=None):
def default_sequence(self):
return False
def get_types(self, cursor, user, context=None):
def get_types(self):
type_obj = self.pool.get('account.journal.type')
type_ids = type_obj.search(cursor, user, [], context=context)
types = type_obj.browse(cursor, user, type_ids, context=context)
type_ids = type_obj.search([])
types = type_obj.browse(type_ids)
return [(x.code, x.name) for x in types]
def search_rec_name(self, cursor, user, name, clause, context=None):
ids = self.search(cursor, user, [
def search_rec_name(self, name, clause):
ids = self.search([
('code',) + clause[1:],
], limit=1, order=[], context=context)
], limit=1, order=[])
if ids:
return [('code',) + clause[1:]]
return [(self._rec_name,) + clause[1:]]
@@ -194,69 +197,60 @@ class Period(ModelSQL, ModelView):
'a journal - period from a closed period!',
})
def default_active(self, cursor, user, context=None):
def default_active(self):
return True
def default_state(self, cursor, user, context=None):
def default_state(self):
return 'open'
def get_icon(self, cursor, user, ids, name, context=None):
def get_icon(self, ids, name):
res = {}
for period in self.browse(cursor, user, ids, context=context):
for period in self.browse(ids):
res[period.id] = _ICONS.get(period.state, '')
return res
def _check(self, cursor, user, ids, context=None):
def _check(self, ids):
move_obj = self.pool.get('account.move')
for period in self.browse(cursor, user, ids, context=context):
move_ids = move_obj.search(cursor, user, [
for period in self.browse(ids):
move_ids = move_obj.search([
('journal', '=', period.journal.id),
('period', '=', period.period.id),
], limit=1, context=context)
], limit=1)
if move_ids:
self.raise_user_error(cursor, 'modify_del_journal_period',
context=context)
self.raise_user_error('modify_del_journal_period')
return
def create(self, cursor, user, vals, context=None):
def create(self, vals):
period_obj = self.pool.get('account.period')
if vals.get('period'):
period = period_obj.browse(cursor, user, vals['period'],
context=context)
period = period_obj.browse(vals['period'])
if period.state == 'close':
self.raise_user_error(cursor, 'create_journal_period',
context=context)
return super(Period, self).create(cursor, user, vals, context=context)
self.raise_user_error('create_journal_period')
return super(Period, self).create(vals)
def write(self, cursor, user, ids, vals, context=None):
def write(self, ids, vals):
if vals != {'state': 'close'} \
and vals != {'state': 'open'}:
self._check(cursor, user, ids, context=context)
self._check(ids)
if vals.get('state') == 'open':
for journal_period in self.browse(cursor, user, ids,
context=context):
for journal_period in self.browse(ids):
if journal_period.period.state == 'close':
self.raise_user_error(cursor, 'open_journal_period',
context=context)
return super(Period, self).write(cursor, user, ids, vals,
context=context)
self.raise_user_error('open_journal_period')
return super(Period, self).write(ids, vals)
def delete(self, cursor, user, ids, context=None):
self._check(cursor, user, ids, context=context)
return super(Period, self).delete(cursor, user, ids, context=context)
def delete(self, ids):
self._check(ids)
return super(Period, self).delete(ids)
def close(self, cursor, user, ids, context=None):
def close(self, ids):
'''
Close journal - period
:param cursor: the database cursor
:param user: the user id
:param ids: the journal - period ids
:param context: the context
'''
self.write(cursor, user, ids, {
self.write(ids, {
'state': 'close',
}, context=context)
})
Period()
@@ -274,10 +268,9 @@ class ClosePeriod(Wizard):
},
}
def _close(self, cursor, user, data, context=None):
def _close(self, data):
journal_period_obj = self.pool.get('account.journal.period')
journal_period_obj.close(cursor, user, data['ids'],
context=context)
journal_period_obj.close(data['ids'])
return {}
ClosePeriod()
@@ -296,11 +289,11 @@ class ReOpenPeriod(Wizard):
},
}
def _reopen(self, cursor, user, data, context=None):
def _reopen(self, data):
journal_period_obj = self.pool.get('account.journal.period')
journal_period_obj.write(cursor, user, data['ids'], {
journal_period_obj.write(data['ids'], {
'state': 'open',
}, context=context)
})
return {}
ReOpenPeriod()
+357 -450
View File
File diff suppressed because it is too large Load Diff
+22 -31
View File
@@ -1,8 +1,9 @@
#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 decimal import Decimal
from trytond.model import ModelView, ModelSQL, fields
from trytond.pyson import Get, Eval, And, Bool, Not, Or
from decimal import Decimal
from trytond.transaction import Transaction
class Party(ModelSQL, ModelView):
@@ -44,17 +45,12 @@ class Party(ModelSQL, ModelView):
payable_today = fields.Function(fields.Numeric('Payable Today'),
'get_receivable_payable', searcher='search_receivable_payable')
def get_receivable_payable(self, cursor, user_id, ids, names,
context=None):
def get_receivable_payable(self, ids, names):
'''
Function to compute receivable, payable (today or not) for party ids.
:param cursor: the database cursor
:param user: the user id
:param ids: the ids of the party
:param names: the list of field name to compute
:param arg: optional argument
:param context: the context
:return: a dictionary with all field names as key and
a dictionary as value with id as key
'''
@@ -63,9 +59,7 @@ class Party(ModelSQL, ModelView):
company_obj = self.pool.get('company.company')
user_obj = self.pool.get('res.user')
date_obj = self.pool.get('ir.date')
if context is None:
context = {}
cursor = Transaction().cursor
for name in names:
if name not in ('receivable', 'payable',
@@ -77,13 +71,13 @@ class Party(ModelSQL, ModelView):
return {}
company_id = None
user = user_obj.browse(cursor, user_id, user_id, context=context)
if context.get('company'):
child_company_ids = company_obj.search(cursor, user_id, [
user = user_obj.browse(Transaction().user)
if Transaction().context.get('company'):
child_company_ids = company_obj.search([
('parent', 'child_of', [user.main_company.id]),
], order=[], context=context)
if context['company'] in child_company_ids:
company_id = context['company']
], order=[])
if Transaction().context['company'] in child_company_ids:
company_id = Transaction().context['company']
if not company_id:
company_id = user.company.id or user.main_company.id
@@ -91,7 +85,7 @@ class Party(ModelSQL, ModelView):
if not company_id:
return res
line_query, _ = move_line_obj.query_get(cursor, user_id, context=context)
line_query, _ = move_line_obj.query_get()
for name in names:
code = name
@@ -101,7 +95,7 @@ class Party(ModelSQL, ModelView):
code = name[:-6]
today_query = 'AND (l.maturity_date <= %s ' \
'OR l.maturity_date IS NULL) '
today_value = [date_obj.today(cursor, user, context=context)]
today_value = [date_obj.today()]
cursor.execute('SELECT l.party, ' \
'SUM((COALESCE(l.debit, 0) - COALESCE(l.credit, 0))) ' \
@@ -125,28 +119,25 @@ class Party(ModelSQL, ModelView):
res[name][party_id] = sum
return res
def search_receivable_payable(self, cursor, user_id, name, clause,
context=None):
def search_receivable_payable(self, name, clause):
move_line_obj = self.pool.get('account.move.line')
company_obj = self.pool.get('company.company')
user_obj = self.pool.get('res.user')
date_obj = self.pool.get('ir.date')
if context is None:
context = {}
cursor = Transaction().cursor
if name not in ('receivable', 'payable',
'receivable_today', 'payable_today'):
raise Exception('Bad argument')
company_id = None
user = user_obj.browse(cursor, user_id, user_id, context=context)
if context.get('company'):
child_company_ids = company_obj.search(cursor, user_id, [
user = user_obj.browse(Transaction().user)
if Transaction().context.get('company'):
child_company_ids = company_obj.search([
('parent', 'child_of', [user.main_company.id]),
], context=context)
if context['company'] in child_company_ids:
company_id = context['company']
])
if Transaction().context['company'] in child_company_ids:
company_id = Transaction().context['company']
if not company_id:
company_id = user.company.id or user.main_company.id
@@ -161,9 +152,9 @@ class Party(ModelSQL, ModelView):
code = name[:-6]
today_query = 'AND (l.maturity_date <= %s ' \
'OR l.maturity_date IS NULL) '
today_value = [date_obj.today(cursor, user, context=context)]
today_value = [date_obj.today()]
line_query, _ = move_line_obj.query_get(cursor, user_id, context=context)
line_query, _ = move_line_obj.query_get()
cursor.execute('SELECT l.party '
'FROM account_move_line AS l, '
+54 -72
View File
@@ -1,9 +1,9 @@
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
'Period'
from trytond.model import ModelView, ModelSQL, fields, OPERATORS
from trytond.wizard import Wizard
from trytond.pyson import Equal, Eval
from trytond.transaction import Transaction
_STATES = {
'readonly': Equal(Eval('state'), 'close'),
@@ -66,14 +66,15 @@ class Period(ModelSQL, ModelView):
'the fiscal year dates',
})
def default_state(self, cursor, user, context=None):
def default_state(self):
return 'open'
def default_type(self, cursor, user, context=None):
def default_type(self):
return 'standard'
def check_dates(self, cursor, user, ids):
for period in self.browse(cursor, user, ids):
def check_dates(self, ids):
cursor = Transaction().cursor
for period in self.browse(ids):
if period.type != 'standard':
continue
cursor.execute('SELECT id ' \
@@ -92,16 +93,16 @@ class Period(ModelSQL, ModelView):
return False
return True
def check_fiscalyear_dates(self, cursor, user, ids):
for period in self.browse(cursor, user, ids):
def check_fiscalyear_dates(self, ids):
for period in self.browse(ids):
if period.start_date < period.fiscalyear.start_date \
or period.end_date > period.fiscalyear.end_date:
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, [
def check_post_move_sequence(self, ids):
for period in self.browse(ids):
if self.search([
('post_move_sequence', '=', period.post_move_sequence.id),
('fiscalyear', '!=', period.fiscalyear.id),
]):
@@ -112,27 +113,23 @@ class Period(ModelSQL, ModelView):
return False
return True
def find(self, cursor, user, company_id, date=None, exception=True,
test_state=True, context=None):
def find(self, company_id, date=None, exception=True, test_state=True):
'''
Return the period for the company_id
at the date or the current date.
If exception is set the function will raise an exception
if any period is found.
:param cursor: the database cursor
:param user: the user id
:param company_id: the company id
:param date: the date searched
:param exception: a boolean to raise or not an exception
:param test_state: a boolean if true will search on non-closed periods
:param context: the context
:return: the period id found or False
'''
date_obj = self.pool.get('ir.date')
if not date:
date = date_obj.today(cursor, user, context=context)
date = date_obj.today()
clause = [
('start_date', '<=', date),
('end_date', '>=', date),
@@ -141,30 +138,27 @@ class Period(ModelSQL, ModelView):
]
if test_state:
clause.append(('state', '!=', 'close'))
ids = self.search(cursor, user, clause, order=[('start_date', 'DESC')],
limit=1, context=context)
ids = self.search(clause, order=[('start_date', 'DESC')], limit=1)
if not ids:
if exception:
self.raise_user_error(cursor, 'no_period_date',
context=context)
self.raise_user_error('no_period_date')
else:
return False
return ids[0]
def _check(self, cursor, user, ids, context=None):
def _check(self, ids):
move_obj = self.pool.get('account.move')
if isinstance(ids, (int, long)):
ids = [ids]
move_ids = move_obj.search(cursor, user, [
move_ids = move_obj.search([
('period', 'in', ids),
], limit=1, context=context)
], limit=1)
if move_ids:
self.raise_user_error(cursor, 'modify_del_period_moves',
context=context)
self.raise_user_error('modify_del_period_moves')
return
def search(self, cursor, user, args, offset=0, limit=None, order=None,
context=None, count=False, query_string=False):
def search(self, args, offset=0, limit=None, order=None, count=False,
query_string=False):
args = args[:]
def process_args(args):
i = 0
@@ -178,85 +172,73 @@ class Period(ModelSQL, ModelView):
if not args[i][2][0]:
args[i] = ('id', '!=', '0')
else:
period = self.browse(cursor, user, args[i][2][0],
context=context)
period = self.browse(args[i][2][0])
args[i] = (args[i][0], args[i][1], period[args[i][2][1]])
elif isinstance(args[i], list):
process_args(args[i])
i += 1
process_args(args)
return super(Period, self).search(cursor, user, args, offset=offset,
limit=limit, order=order, context=context, count=count,
query_string=query_string)
return super(Period, self).search(args, offset=offset, limit=limit,
order=order, count=count, query_string=query_string)
def create(self, cursor, user, vals, context=None):
def create(self, vals):
fiscalyear_obj = self.pool.get('account.fiscalyear')
vals = vals.copy()
if vals.get('fiscalyear'):
fiscalyear = fiscalyear_obj.browse(cursor, user, vals['fiscalyear'],
context=context)
fiscalyear = fiscalyear_obj.browse(vals['fiscalyear'])
if fiscalyear.state == 'close':
self.raise_user_error(cursor,
'create_period_closed_fiscalyear', context=context)
self.raise_user_error('create_period_closed_fiscalyear')
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)
return super(Period, self).create(vals)
def write(self, cursor, user, ids, vals, context=None):
def write(self, ids, vals):
move_obj = self.pool.get('account.move')
for key in vals.keys():
if key in ('start_date', 'end_date', 'fiscalyear'):
self._check(cursor, user, ids, context=context)
self._check(ids)
break
if vals.get('state') == 'open':
for period in self.browse(cursor, user, ids,
context=context):
for period in self.browse(ids):
if period.fiscalyear.state == 'close':
self.raise_user_error(cursor,
'open_period_closed_fiscalyear', context=context)
self.raise_user_error('open_period_closed_fiscalyear')
if vals.get('post_move_sequence'):
for period in self.browse(cursor, user, ids, context=context):
for period in self.browse(ids):
if period.post_move_sequence and \
period.post_move_sequence.id != \
vals['post_move_sequence']:
if move_obj.search(cursor, user, [
if move_obj.search([
('period', '=', period.id),
('state', '=', 'posted'),
], context=context):
self.raise_user_error(cursor,
'change_post_move_sequence', context=context)
return super(Period, self).write(cursor, user, ids, vals,
context=context)
]):
self.raise_user_error('change_post_move_sequence')
return super(Period, self).write(ids, vals)
def delete(self, cursor, user, ids, context=None):
self._check(cursor, user, ids, context=context)
return super(Period, self).delete(cursor, user, ids,
context=context)
def delete(self, ids):
self._check(ids)
return super(Period, self).delete(ids)
def close(self, cursor, user, ids, context=None):
def close(self, ids):
journal_period_obj = self.pool.get('account.journal.period')
move_obj = self.pool.get('account.move')
if isinstance(ids, (int, long)):
ids = [ids]
if move_obj.search(cursor, user, [
if move_obj.search([
('period', 'in', ids),
('state', '!=', 'posted'),
], context=context):
self.raise_user_error(cursor, 'close_period_non_posted_move',
context=context)
]):
self.raise_user_error('close_period_non_posted_move')
#First close the period to be sure
#it will not have new journal.period created between.
self.write(cursor, user, ids, {
self.write(ids, {
'state': 'close',
}, context=context)
journal_period_ids = journal_period_obj.search(cursor, user, [
})
journal_period_ids = journal_period_obj.search([
('period', 'in', ids),
], context=context)
journal_period_obj.close(cursor, user, journal_period_ids,
context=context)
return
])
journal_period_obj.close(journal_period_ids)
Period()
@@ -274,9 +256,9 @@ class ClosePeriod(Wizard):
},
}
def _close(self, cursor, user, data, context=None):
def _close(self, data):
period_obj = self.pool.get('account.period')
period_obj.close(cursor, user, data['ids'], context=context)
period_obj.close(data['ids'])
return {}
ClosePeriod()
@@ -295,11 +277,11 @@ class ReOpenPeriod(Wizard):
},
}
def _reopen(self, cursor, user, data, context=None):
def _reopen(self, data):
period_obj = self.pool.get('account.period')
period_obj.write(cursor, user, data['ids'], {
period_obj.write(data['ids'], {
'state': 'open',
}, context=context)
})
return {}
ReOpenPeriod()
+172 -266
View File
File diff suppressed because it is too large Load Diff