~unifield-team/unifield-wm/us-826

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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
-
  In order to test the budget import,
  we need a lot.
  I create, in order, a account type, ...
-
  !record {model: account.account.type, id: account_account_type_expense0}:
    close_method: none
    code: expense
    name: Expense
    sign: 1
-
  ...a destination, ...
-
  !record {model: account.analytic.account, id: test_destination}:
    name: "Test Destination"
    code: "DESTINATION"
    category: DEST
-
  ...an "chart of accounts" account, ...
-
  !record {model: account.account, id: test_chart_of_accounts}:
    name: "MSF Chart of Accounts"
    code: "MSF"
    user_type: account_account_type_expense0
    type: view
-
  ...an account, ...
-
  !record {model: account.account, id: test_expense}:
    name: "Test Expense"
    code: "TEST"
    user_type: account_account_type_expense0
    type: payable
    parent_id: test_chart_of_accounts
-
  ...a destination link, ...
-
  !record {model: account.destination.link, id: test_destination_link}:
    account_id: test_expense
    destination_id: test_destination
-
 ...a cost center...
-
  !record {model: account.analytic.account, id: analytic_account_OC1}:
    name: "OC1"
    code: "OC1"
    category: OC
-
 ...a cost center...
-
  !record {model: account.analytic.account, id: analytic_account_OC2}:
    name: "OC2"
    code: "OC2"
    category: OC
-
 ...a funding pool...
-
  !record {model: account.analytic.account, id: analytic_account_FP1}:
    name: "FP1"
    code: "FP1"
    category: FUNDING
    cost_center_ids:
      - analytic_account_OC2
    tuple_destination_account_ids:
      - test_destination_link
-
 ...a funding pool...
-
  !record {model: account.analytic.account, id: analytic_account_FP2}:
    name: "FP2"
    code: "FP2"
    category: FUNDING
    cost_center_ids:
      - analytic_account_OC1
      - analytic_account_OC2
    tuple_destination_account_ids:
      - test_destination_link
-
  I set the company currency's rate to 1 for the move
-
  !record {model: res.currency.rate, id: currency_rate_test_3}:
    name: !eval "'%s-01-01' %(datetime.now().year+1)"
    rate: 1.00
    currency_id: base.CHF
-
  I set another currency's rate to 100 for the move
-
  !record {model: res.currency.rate, id: currency_rate_test_4}:
    name: !eval "'%s-01-01' %(datetime.now().year+1)"
    rate: 100.00
    currency_id: base.EUR
-
  ...an analytical journal, ...
-
  !record {model: account.analytic.journal, id: analytic_journal_1}:
    code: CANJ
    name: Cash Analytic Journal
    type: general
-
  I create a cash account type
-
  !record {model: account.account.type, id: account_account_type_cash_0}:
    close_method: balance
    code: cash
    name: Cash
    sign: 1
    report_type: asset

-
  I create a X11003 Cash Account.
-
  !record {model: account.account, id: account_account_cash0}:
    code: 'X11003-test'
    company_id: base.main_company
    currency_mode: current
    name: Cash (test)
    type: liquidity
    reconcile: False
    user_type : account_account_type_cash_0
    activation_date: !eval time.strftime('%Y-01-01')
-
  ...a journal, ...
-
  !record {model: account.journal, id: account_journal_1}:
    name: Cash Journal
    code: CTST
    currency: base.EUR
    type: cash
    analytic_journal_id: analytic_journal_1
    default_debit_account_id: account_account_cash0
    default_credit_account_id: account_account_cash0
-
  ...a fiscal year, ...
-
  !record {model: account.fiscalyear, id: account_fiscalyear_fiscalyear0}:
    code: !eval "'FY%s'% (datetime.now().year+1)"
    company_id: base.main_company
    date_start: !eval "'%s-01-01' %(datetime.now().year+1)"
    date_stop: !eval "'%s-12-31' %(datetime.now().year+1)"
    name: !eval "'Fiscal Year %s' %(datetime.now().year+1)"
-
  ... and a period.
-
  !record {model: account.period, id: account_period_mar0}:
    company_id: base.main_company
    date_start: !eval "'%s-03-01' %(datetime.now().year+1)"
    date_stop: !eval "'%s-03-31' %(datetime.now().year+1)"
    fiscalyear_id: account_fiscalyear_fiscalyear0
    name: !eval "'Mar %s' %(datetime.now().year+1)"
    special: 1
    state: draft
-
  ... and a distribution.
-
  !record {model: analytic.distribution, id: distribution_test}:
    funding_pool_lines:
    - analytic_id: analytic_distribution.analytic_account_msf_private_funds
      cost_center_id: analytic_account_OC1
      destination_id: test_destination
      percentage: 50
      currency_id: base.CHF
      date: !eval "'%s-03-12' %(datetime.now().year+1)"
    - analytic_id: analytic_account_FP1
      cost_center_id: analytic_account_OC2
      destination_id: test_destination
      percentage: 50
      currency_id: base.CHF
      date: !eval "'%s-03-12' %(datetime.now().year+1)"
-
  ... and another distribution.
-
  !record {model: analytic.distribution, id: distribution_test_2}:
    funding_pool_lines:
    - analytic_id: analytic_account_FP1
      cost_center_id: analytic_account_OC2
      destination_id: test_destination
      percentage: 40
      currency_id: base.CHF
      date: !eval "'%s-03-12' %(datetime.now().year+1)"
    - analytic_id: analytic_account_FP2
      cost_center_id: analytic_account_OC2
      destination_id: test_destination
      percentage: 40
      currency_id: base.CHF
      date: !eval "'%s-03-12' %(datetime.now().year+1)"
    - analytic_id: analytic_account_FP2
      cost_center_id: analytic_account_OC1
      destination_id: test_destination
      percentage: 20
      currency_id: base.CHF
      date: !eval "'%s-03-12' %(datetime.now().year+1)"
-
  I overwrite periods to have the right number and open them
-
  !python {model: account.period}: |
    import datetime
    period_ids = [ref('account_period_mar0')]
    for p in self.browse(cr, uid, period_ids):
      self.write(cr, uid, [p.id], {'number': int(datetime.datetime.strptime(p.date_start, '%Y-%m-%d').strftime('%m'))})
    self.action_set_state(cr, uid, period_ids, {'state': 'draft'})
-
  I create an account move line with all of this.
-
  !record {model: account.move.line, id: move_line_test}:
    name: testline
    journal_id: account_journal_1
    period_id: account_period_mar0
    account_id: test_expense
    currency_id: base.CHF
    date: !eval "'%s-03-12' %(datetime.now().year+1)"
    debit_currency: 4242.0
    analytic_distribution_id: distribution_test
-
  I create an account move line with all of this.
-
  !record {model: account.move.line, id: move_line_test_2}:
    name: testline2
    journal_id: account_journal_1
    period_id: account_period_mar0
    account_id: test_expense
    currency_id: base.CHF
    date: !eval "'%s-03-12' %(datetime.now().year+1)"
    debit_currency: 12500.0
    analytic_distribution_id: distribution_test_2
      
-
  Analytic lines are created from it
-
  !python {model: account.move.line}: |
    self.create_analytic_lines(cr, uid, [ref("move_line_test"), ref("move_line_test_2")], context={})
    
-
  I create a decision moment
-
  !record {model: msf.budget.decision.moment, id: decision1}:
    name: Decision moment 1
    order: 100
-
  I create an instance
-
  !record {model: msf.instance, id: test_instance}:
    code: TSTINSTANCE
    name: Test Instance
    level: section
    target_cost_center_ids:
      - cost_center_id: analytic_account_OC1
        is_target: True
        is_top_cost_center: True
        is_po_fo_cost_center: True
    move_prefix: TIN
    reconcile_prefix: T3
-
  I add the instance to the default company
-
  !python {model: res.company}: |
    user = self.pool.get('res.users').browse(cr, uid, uid)
    if not user.company_id.instance_id:
        self.write(cr, uid, [uid], {'instance_id': ref("test_instance")})
-
  Now that lines are here, time for the budget
-
  !record {model: msf.budget, id: budget_test}:
    name: Test Budget
    code: BUTEST
    fiscalyear_id: account_fiscalyear_fiscalyear0
    state: 'draft'
    cost_center_id: analytic_account_OC1
    decision_moment_id: decision1
    version: 1
    currency_id: base.EUR
      
-
  and its line
-
  !record {model: msf.budget.line, id: budget_line_test}:
    budget_id: budget_test
    account_id: test_expense
    destination_id: test_destination
    budget_values: '[3323232,455,2221,55542,21,555,2113,345,2212,766,33356,222]'
    line_type: 'destination'
      
-
  Check budget, actual, percentage, balance for the line
-
  !python {model: msf.budget.line}: |
     budget_line = self.browse(cr, uid, ref("budget_line_test"), context={})
     #assert budget_line.budget_amount == 3421040, ("Not the correct budget amount!")
     #assert budget_line.actual_amount == 462100.0, ("Not the correct actual amount! %s!=462100.0"%(budget_line.actual_amount,))
     #assert budget_line.balance == 2958940.0, ("Not the correct balance!")
     #assert budget_line.percentage == 14.0, ("Not the correct percentage!")