← Back to team overview

openerp-chinese-team team mailing list archive

lp:~openerp-chinese-team/openobject-addons/fix_admin_not_able_to_post_journal_vourcher_in_multicompany_senario into lp:openobject-addons

 

digitalsatori has proposed merging lp:~openerp-chinese-team/openobject-addons/fix_admin_not_able_to_post_journal_vourcher_in_multicompany_senario into lp:openobject-addons.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-chinese-team/openobject-addons/fix_admin_not_able_to_post_journal_vourcher_in_multicompany_senario/+merge/73172

root user may not be able to post journal voucher in multi company scenario.
root user(admin) is not restricted by the record rule setting for multi-company, and thus when try to get the specific account period for the current company(in user preference), openerp retrieve a list of account period and sliced the first one in list, which may not respect to the current company.

The fix provided works around for the said problem. But the problem may suggest some fundamental problem for root users' system behavior in multi-company environment. 

I also observed that the root user may not be able to retrieve default current company by calling res_company._company_default_get method. However, I didn't test this on trunk and thus don't know whether this is an known/fixed issue.

-- 
https://code.launchpad.net/~openerp-chinese-team/openobject-addons/fix_admin_not_able_to_post_journal_vourcher_in_multicompany_senario/+merge/73172
Your team Open ERP Chinese is subscribed to branch lp:~openerp-chinese-team/openobject-addons/fix_admin_not_able_to_post_journal_vourcher_in_multicompany_senario.
=== modified file 'account/account.py'
--- account/account.py	2011-08-19 15:19:15 +0000
+++ account/account.py	2011-08-28 10:07:26 +0000
@@ -839,12 +839,12 @@
     def find(self, cr, uid, dt=None, exception=True, context=None):
         if not dt:
             dt = time.strftime('%Y-%m-%d')
-        ids = self.search(cr, uid, [('date_start', '<=', dt), ('date_stop', '>=', dt)])
+        # since admin is not restricted by the record rule setting in multi company senario
+        # We has to put a company specific domain here to return fical year for the current company
+        user = self.pool.get('res.users').browse(cr,uid,uid)
+        ids = self.search(cr, uid, [('date_start', '<=', dt), ('date_stop', '>=', dt), ('company_id', '=', user.company_id.id)])
         if not ids:
-            if exception:
-                raise osv.except_osv(_('Error !'), _('No fiscal year defined for this date !\nPlease create one.'))
-            else:
-                return False
+            raise osv.except_osv(_('Error !'), _('No fiscal year defined for this date !\nPlease create one.'))
         return ids[0]
 
     def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=80):
@@ -918,8 +918,11 @@
     def find(self, cr, uid, dt=None, context=None):
         if not dt:
             dt = time.strftime('%Y-%m-%d')
+        # since admin is not restricted by the record rule setting in multi company senario
+        # We has to put a company specific domain here to return account period for the current company
 #CHECKME: shouldn't we check the state of the period?
-        ids = self.search(cr, uid, [('date_start','<=',dt),('date_stop','>=',dt)])
+        user = self.pool.get('res.users').browse(cr, uid, uid)
+        ids = self.search(cr, uid, [('date_start', '<=', dt), ('date_stop', '>=', dt), ('company_id', '=', user.company_id.id)])
         if not ids:
             raise osv.except_osv(_('Error !'), _('No period defined for this date: %s !\nPlease create one.')%dt)
         return ids


Follow ups