3
3
# Copyright 2017 Lorenzo Battistini - Agile Business Group
4
4
# Copyright 2017 Marco Calcagni - Dinamiche Aziendali srl
5
5
# Copyright 2023 Simone Rubino - TAKOBI
6
+ # Copyright 2024 Nextev Srl
6
7
7
8
from odoo import api , fields , models
8
9
from odoo .exceptions import UserError
@@ -180,16 +181,17 @@ def compute_rc_amount_tax_main_currency(self):
180
181
The result is converted and rounded based on Company Currency
181
182
because this value is used for credit/debit.
182
183
"""
183
- rc_tax_amount = self .get_tax_amount_added_for_rc ()
184
+ rc_tax_amount_ic = self .get_tax_amount_added_for_rc ()
185
+ rc_tax_amount_cc = rc_tax_amount_ic
184
186
185
187
invoice_currency = self .currency_id
186
188
company_currency = self .company_currency_id
187
189
if invoice_currency != company_currency :
188
- rc_tax_amount = invoice_currency ._convert (
189
- rc_tax_amount , company_currency , self .company_id , self .invoice_date
190
+ rc_tax_amount_cc = invoice_currency ._convert (
191
+ rc_tax_amount_ic , company_currency , self .company_id , self .invoice_date
190
192
)
191
193
192
- return rc_tax_amount
194
+ return rc_tax_amount_ic , rc_tax_amount_cc
193
195
194
196
def rc_payment_vals (self , rc_type ):
195
197
"""Values for the RC Payment Move."""
@@ -199,15 +201,20 @@ def rc_payment_vals(self, rc_type):
199
201
"date" : self .date ,
200
202
}
201
203
202
- def _rc_line_values (self , account , credit , debit ):
204
+ def _rc_line_values (self , account , credit , debit , amount_currency ):
203
205
"""Base Values for the RC Payment Move lines."""
204
- return {
206
+ values = {
205
207
"name" : self .name ,
206
208
"credit" : credit ,
207
209
"debit" : debit ,
208
210
"account_id" : account .id ,
209
211
"currency_id" : self .currency_id .id ,
210
212
}
213
+ if amount_currency :
214
+ sign = 1 if debit else - 1
215
+ amount_currency = abs (amount_currency ) * sign
216
+ values ["amount_currency" ] = amount_currency
217
+ return values
211
218
212
219
def _rc_credit_line_amounts (self , amount ):
213
220
if self .is_inbound ():
@@ -230,7 +237,9 @@ def rc_payment_credit_line_vals(self, line_to_reconcile):
230
237
)
231
238
account = line_to_reconcile .account_id
232
239
233
- line_values = self ._rc_line_values (account , credit , debit )
240
+ line_values = self ._rc_line_values (
241
+ account , credit , debit , line_to_reconcile .amount_currency
242
+ )
234
243
line_values .update (
235
244
{
236
245
"partner_id" : self .partner_id .id ,
@@ -244,16 +253,18 @@ def rc_payment_debit_line_vals(self, line_to_reconcile, account):
244
253
abs (line_to_reconcile .balance ),
245
254
)
246
255
247
- line_values = self ._rc_line_values (account , credit , debit )
256
+ line_values = self ._rc_line_values (
257
+ account , credit , debit , line_to_reconcile .amount_currency
258
+ )
248
259
return line_values
249
260
250
- def rc_credit_line_vals (self , account , amount ):
251
- credit , debit = self ._rc_credit_line_amounts (amount )
252
- return self ._rc_line_values (account , credit , debit )
261
+ def rc_credit_line_vals (self , account , amount_ic , amount_cc ):
262
+ credit , debit = self ._rc_credit_line_amounts (amount_cc )
263
+ return self ._rc_line_values (account , credit , debit , amount_ic )
253
264
254
- def rc_debit_line_vals (self , account , amount ):
255
- credit , debit = self ._rc_debit_line_amounts (amount )
256
- line_values = self ._rc_line_values (account , credit , debit )
265
+ def rc_debit_line_vals (self , account , amount_ic , amount_cc ):
266
+ credit , debit = self ._rc_debit_line_amounts (amount_cc )
267
+ line_values = self ._rc_line_values (account , credit , debit , amount_ic )
257
268
line_values .update (
258
269
{
259
270
"partner_id" : self .partner_id .id ,
@@ -277,6 +288,7 @@ def _prepare_rc_supplier_invoice_payment(self, rc_invoice, rc_type):
277
288
line_to_reconcile = self ._rc_get_move_line_to_reconcile ()
278
289
payment_debit_line_data = self .rc_debit_line_vals (
279
290
line_to_reconcile .account_id ,
291
+ payment_credit_line_data ["amount_currency" ],
280
292
payment_credit_line_data ["credit" ],
281
293
)
282
294
rc_payment_data ["line_ids" ] = [
@@ -318,15 +330,17 @@ def _prepare_rc_invoice_payment(self, rc_invoice, rc_type):
318
330
)
319
331
320
332
# Lines to be reconciled with the original supplier Invoice (self)
321
- rc_tax_amount = self .compute_rc_amount_tax_main_currency ()
333
+ rc_tax_amount_ic , rc_tax_amount_cc = self .compute_rc_amount_tax_main_currency ()
322
334
payment_credit_line_data = self .rc_credit_line_vals (
323
335
rc_type .transitory_account_id ,
324
- rc_tax_amount ,
336
+ rc_tax_amount_ic ,
337
+ rc_tax_amount_cc ,
325
338
)
326
339
line_to_reconcile = self ._rc_get_move_line_to_reconcile ()
327
340
payment_debit_line_data = self .rc_debit_line_vals (
328
341
line_to_reconcile .account_id ,
329
- rc_tax_amount ,
342
+ rc_tax_amount_ic ,
343
+ rc_tax_amount_cc ,
330
344
)
331
345
332
346
rc_payment_data ["line_ids" ] = [
0 commit comments