From 442c19b78fe2c9dc255e6f57eb0ef30f8fe4c7ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 3 Jul 2008 20:42:00 +0200 Subject: [PATCH] Add company on fiscalyear and change find functions to use company_id --- account.py | 18 ++++++++++++------ fiscalyear.py | 17 +++++++++++++++-- fiscalyear.xml | 4 +++- move.py | 13 ++++++++++--- period.py | 7 +++++-- 5 files changed, 45 insertions(+), 14 deletions(-) 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 @@