Add company on fiscalyear and change find functions to use company_id

This commit is contained in:
Cédric Krier
2008-07-03 20:42:00 +02:00
parent 4acb71ff6d
commit 442c19b78f
5 changed files with 45 additions and 14 deletions
+12 -6
View File
@@ -586,8 +586,10 @@ class PrintGeneralLegderInit(WizardOSV):
def default_fiscalyear(self, cursor, user, context=None):
fiscalyear_obj = self.pool.get('account.fiscalyear')
fiscalyear_id = fiscalyear_obj.find(cursor, user, exception=False,
context=context)
if context is None:
context = {}
fiscalyear_id = fiscalyear_obj.find(cursor, user,
context.get('company', False), exception=False, context=context)
if fiscalyear_id:
return fiscalyear_obj.name_get(cursor, user, fiscalyear_id,
context=context)[0]
@@ -776,8 +778,10 @@ class PrintTrialBalanceInit(WizardOSV):
def default_fiscalyear(self, cursor, user, context=None):
fiscalyear_obj = self.pool.get('account.fiscalyear')
fiscalyear_id = fiscalyear_obj.find(cursor, user, exception=False,
context=context)
if context is None:
context = {}
fiscalyear_id = fiscalyear_obj.find(cursor, user,
context.get('company', False), exception=False, context=context)
if fiscalyear_id:
return fiscalyear_obj.name_get(cursor, user, fiscalyear_id,
context=context)[0]
@@ -1008,8 +1012,10 @@ class OpenIncomeStatementInit(WizardOSV):
def default_fiscalyear(self, cursor, user, context=None):
fiscalyear_obj = self.pool.get('account.fiscalyear')
fiscalyear_id = fiscalyear_obj.find(cursor, user, exception=False,
context=context)
if context is None:
context = {}
fiscalyear_id = fiscalyear_obj.find(cursor, user,
context.get('company', False), exception=False, context=context)
if fiscalyear_id:
return fiscalyear_obj.name_get(cursor, user, fiscalyear_id,
context=context)[0]
+15 -2
View File
@@ -29,6 +29,7 @@ class FiscalYear(OSV):
], 'State', readonly=True, required=True)
post_move_sequence = fields.Many2One('ir.sequence', 'Post Move Sequence',
required=True, domain="[('code', '=', 'account.move')]")
company = fields.Many2One('company.company', 'Company', required=True)
def __init__(self):
super(FiscalYear, self).__init__()
@@ -49,6 +50,15 @@ class FiscalYear(OSV):
def default_state(self, cursor, user, context=None):
return 'open'
def default_company(self, cursor, user, context=None):
company_obj = self.pool.get('company.company')
if context is None:
context = {}
if context.get('company'):
return company_obj.name_get(cursor, user, context['company'],
context=context)[0]
return False
def check_dates(self, cursor, user, ids):
for fiscalyear in self.browse(cursor, user, ids):
cursor.execute('SELECT id ' \
@@ -123,9 +133,11 @@ class FiscalYear(OSV):
return self.create_period(cursor, user, ids, context=context,
interval=3)
def find(self, cursor, user, date=None, exception=True, context=None):
def find(self, cursor, user, company_id, date=None, exception=True,
context=None):
'''
Return the fiscal year for the date or the current date.
Return the fiscal year for the company_id
at the date or the current date.
If exception is set the function will raise an exception
if any fiscal year is found.
'''
@@ -134,6 +146,7 @@ class FiscalYear(OSV):
ids = self.search(cursor, user, [
('start_date', '<=', date),
('end_date', '>=', date),
('company', '=', company_id),
], order=[('start_date', 'DESC')], limit=1, context=context)
if not ids:
if exception:
+3 -1
View File
@@ -18,8 +18,10 @@
<field name="start_date"/>
<label name="end_date"/>
<field name="end_date"/>
<label name="company"/>
<field name="company"/>
<label name="state"/>
<field name="state" colspan="3"/>
<field name="state"/>
<notebook colspan="4">
<page string="Periods">
<field name="periods" colspan="4"/>
+10 -3
View File
@@ -67,7 +67,10 @@ class Move(OSV):
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)
if context is None:
context = {}
return period_obj.find(cursor, user, context.get('company', False),
exception=False, context=context)
def default_state(self, cursor, user, context=None):
return 'draft'
@@ -1100,7 +1103,8 @@ class Line(OSV):
if not account:
account = line.account
amount = currency_obj.round(cursor, user, account.currency, amount)
period_id = period_obj.find(cursor, user, date=date, context=context)
period_id = period_obj.find(cursor, user, account.company.id,
date=date, context=context)
move_id = move_obj.create(cursor, user, {
'journal': journal_id,
'period': period_id,
@@ -1154,7 +1158,10 @@ class OpenJournalAsk(WizardOSV):
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)
if context is None:
context = {}
return period_obj.find(cursor, user, context.get('company', False),
exception=False, context=context)
OpenJournalAsk()
+5 -2
View File
@@ -68,9 +68,11 @@ class Period(OSV):
return False
return True
def find(self, cursor, user, date=None, exception=True, context=None):
def find(self, cursor, user, company_id, date=None, exception=True,
context=None):
'''
Return the period for the date or the current date.
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.
'''
@@ -79,6 +81,7 @@ class Period(OSV):
ids = self.search(cursor, user, [
('start_date', '<=', date),
('end_date', '>=', date),
('fiscalyear.company', '=', company_id),
], order=[('start_date', 'DESC')], limit=1, context=context)
if not ids:
if exception: