[MERGE] forward port of branch 8.0 up to 8848af7
This commit is contained in:
@@ -813,7 +813,7 @@ class account_invoice(models.Model):
|
||||
inv.check_tax_lines(compute_taxes)
|
||||
|
||||
# I disabled the check_total feature
|
||||
if self.env['res.users'].has_group('account.group_supplier_inv_check_total'):
|
||||
if self.env.user.has_group('account.group_supplier_inv_check_total'):
|
||||
if inv.type in ('in_invoice', 'in_refund') and abs(inv.check_total - inv.amount_total) >= (inv.currency_id.rounding / 2.0):
|
||||
raise UserError(_('Please verify the price of the invoice!\nThe encoded total does not match the computed total.'))
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import openerp
|
||||
from openerp import SUPERUSER_ID, models
|
||||
from openerp import tools
|
||||
import openerp.exceptions
|
||||
from openerp import api
|
||||
from openerp.osv import fields, osv, expression
|
||||
from openerp.service.security import check_super
|
||||
from openerp.tools.translate import _
|
||||
@@ -548,8 +549,19 @@ class res_users(osv.osv):
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
@tools.ormcache(skiparg=2)
|
||||
@api.v7
|
||||
def has_group(self, cr, uid, group_ext_id):
|
||||
return self._has_group(cr, uid, group_ext_id)
|
||||
@api.v8
|
||||
def has_group(self, group_ext_id):
|
||||
# use singleton's id if called on a non-empty recordset, otherwise
|
||||
# context uid
|
||||
uid = self.id or self.env.uid
|
||||
return self._has_group(self.env.cr, uid, group_ext_id)
|
||||
|
||||
@api.noguess
|
||||
@tools.ormcache(skiparg=2)
|
||||
def _has_group(self, cr, uid, group_ext_id):
|
||||
"""Checks whether user belongs to given group.
|
||||
|
||||
:param str group_ext_id: external ID (XML ID) of the group.
|
||||
@@ -564,6 +576,8 @@ class res_users(osv.osv):
|
||||
(SELECT res_id FROM ir_model_data WHERE module=%s AND name=%s)""",
|
||||
(uid, module, ext_id))
|
||||
return bool(cr.fetchone())
|
||||
# for a few places explicitly clearing the has_group cache
|
||||
has_group.clear_cache = _has_group.clear_cache
|
||||
|
||||
def get_company_currency_id(self, cr, uid, context=None):
|
||||
return self.browse(cr, uid, uid, context=context).company_id.currency_id.id
|
||||
|
||||
@@ -21,6 +21,7 @@ import test_res_lang
|
||||
import test_search
|
||||
import test_translate
|
||||
#import test_uninstall
|
||||
import test_user_has_group
|
||||
import test_view_validation
|
||||
import test_views
|
||||
import test_xmlrpc
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import openerp.tests
|
||||
|
||||
class TestHasGroup(openerp.tests.TransactionCase):
|
||||
def setUp(self):
|
||||
super(TestHasGroup, self).setUp()
|
||||
|
||||
group0 = self.env['ir.model.data']._update(
|
||||
'res.groups', 'test_user_has_group',
|
||||
{'name': 'group0'},
|
||||
xml_id='group0'
|
||||
)
|
||||
self.group0 = 'test_user_has_group.group0'
|
||||
self.env['ir.model.data']._update(
|
||||
'res.groups', 'test_user_has_group',
|
||||
{'name': 'group1'},
|
||||
xml_id='group1'
|
||||
)
|
||||
self.group1 = 'test_user_has_group.group1'
|
||||
|
||||
self.test_user = self.env['res.users'].create({
|
||||
'login': 'testuser',
|
||||
'partner_id': self.env['res.partner'].create({
|
||||
'name': "Strawman Test User"
|
||||
}).id,
|
||||
'groups_id': [(4, group0, 0)]
|
||||
})
|
||||
|
||||
def test_old_api(self):
|
||||
Users = self.registry['res.users']
|
||||
|
||||
self.assertTrue(
|
||||
Users.has_group(self.cr, self.test_user.id, self.group0),
|
||||
"the test user should belong to group0"
|
||||
)
|
||||
self.assertFalse(
|
||||
Users.has_group(self.cr, self.test_user.id, self.group1),
|
||||
"the test user should *not* belong to group1"
|
||||
)
|
||||
|
||||
def test_new_api(self):
|
||||
self.assertTrue(
|
||||
self.test_user.has_group(self.group0),
|
||||
"the test user should belong to group0",
|
||||
)
|
||||
self.assertFalse(
|
||||
self.test_user.has_group(self.group1),
|
||||
"the test user shoudl not belong to group1"
|
||||
)
|
||||
Reference in New Issue
Block a user