diff --git a/account.py b/account.py
index 7d785c8b25..150d79f70a 100644
--- a/account.py
+++ b/account.py
@@ -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]
diff --git a/fiscalyear.py b/fiscalyear.py
index 8adbbd3262..e3932af00b 100644
--- a/fiscalyear.py
+++ b/fiscalyear.py
@@ -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:
diff --git a/fiscalyear.xml b/fiscalyear.xml
index a0711e414f..9b1bf8aa42 100644
--- a/fiscalyear.xml
+++ b/fiscalyear.xml
@@ -18,8 +18,10 @@
+
+
-
+
diff --git a/move.py b/move.py
index 57702ad946..3e0e883413 100644
--- a/move.py
+++ b/move.py
@@ -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()
diff --git a/period.py b/period.py
index 8b8a52c7b0..052a458bab 100644
--- a/period.py
+++ b/period.py
@@ -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: