1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.hr_expense.tests.common import TestExpenseCommon
from odoo.tests import tagged
from odoo.exceptions import UserError
@tagged('post_install', '-at_install')
class TestExpenseMultiCompany(TestExpenseCommon):
def test_expense_sheet_multi_company_approve(self):
self.expense_employee.company_id = self.company_data_2['company']
# The expense employee is able to a create an expense sheet for company_2.
expense_sheet = self.env['hr.expense.sheet']\
.with_user(self.expense_user_employee)\
.with_context(allowed_company_ids=self.company_data_2['company'].ids)\
.create({
'name': 'First Expense for employee',
'employee_id': self.expense_employee.id,
'journal_id': self.company_data_2['default_journal_purchase'].id,
'accounting_date': '2017-01-01',
'expense_line_ids': [
(0, 0, {
# Expense without foreign currency but analytic account.
'name': 'expense_1',
'date': '2016-01-01',
'product_id': self.product_a.id,
'unit_amount': 1000.0,
'employee_id': self.expense_employee.id,
}),
],
})
self.assertRecordValues(expense_sheet, [{'company_id': self.company_data_2['company'].id}])
# The expense employee is able to submit the expense sheet.
expense_sheet.with_user(self.expense_user_employee).action_submit_sheet()
# An expense manager is not able to approve without access to company_2.
with self.assertRaises(UserError):
expense_sheet\
.with_user(self.expense_user_manager)\
.with_context(allowed_company_ids=self.company_data['company'].ids)\
.approve_expense_sheets()
# An expense manager is able to approve with access to company_2.
expense_sheet\
.with_user(self.expense_user_manager)\
.with_context(allowed_company_ids=self.company_data_2['company'].ids)\
.approve_expense_sheets()
# An expense manager having accounting access rights is not able to create the journal entry without access
# to company_2.
with self.assertRaises(UserError):
expense_sheet\
.with_user(self.env.user)\
.with_context(allowed_company_ids=self.company_data['company'].ids)\
.action_sheet_move_create()
# An expense manager having accounting access rights is able to create the journal entry with access to
# company_2.
expense_sheet\
.with_user(self.env.user)\
.with_context(allowed_company_ids=self.company_data_2['company'].ids)\
.action_sheet_move_create()
def test_expense_sheet_multi_company_refuse(self):
self.expense_employee.company_id = self.company_data_2['company']
# The expense employee is able to a create an expense sheet for company_2.
expense_sheet = self.env['hr.expense.sheet']\
.with_user(self.expense_user_employee)\
.with_context(allowed_company_ids=self.company_data_2['company'].ids)\
.create({
'name': 'First Expense for employee',
'employee_id': self.expense_employee.id,
'journal_id': self.company_data_2['default_journal_purchase'].id,
'accounting_date': '2017-01-01',
'expense_line_ids': [
(0, 0, {
# Expense without foreign currency but analytic account.
'name': 'expense_1',
'date': '2016-01-01',
'product_id': self.product_a.id,
'unit_amount': 1000.0,
'employee_id': self.expense_employee.id,
}),
],
})
self.assertRecordValues(expense_sheet, [{'company_id': self.company_data_2['company'].id}])
# The expense employee is able to submit the expense sheet.
expense_sheet.with_user(self.expense_user_employee).action_submit_sheet()
# An expense manager is not able to approve without access to company_2.
with self.assertRaises(UserError):
expense_sheet\
.with_user(self.expense_user_manager)\
.with_context(allowed_company_ids=self.company_data['company'].ids)\
.refuse_sheet('')
# An expense manager is able to approve with access to company_2.
expense_sheet\
.with_user(self.expense_user_manager)\
.with_context(allowed_company_ids=self.company_data_2['company'].ids)\
.refuse_sheet('')
|