@@ -249,18 +249,41 @@ def _check_move_amount(self):
249249 long_term_moves = self .move_ids .mapped ("line_ids" ).filtered (
250250 lambda r : r .account_id == self .loan_id .long_term_loan_account_id
251251 )
252- self . interests_amount = sum (interests_moves .mapped ("debit" )) - sum (
252+ interests_in_company_currency = sum (interests_moves .mapped ("debit" )) - sum (
253253 interests_moves .mapped ("credit" )
254254 )
255- self .long_term_principal_amount = sum (long_term_moves .mapped ("debit" )) - sum (
256- long_term_moves .mapped ("credit" )
255+ self .interests_amount = self .loan_id .company_id .currency_id ._convert (
256+ from_amount = interests_in_company_currency ,
257+ to_currency = self .loan_id .currency_id ,
258+ company = self .loan_id .company_id ,
259+ date = self .date ,
260+ round = False ,
257261 )
258- self .payment_amount = (
262+
263+ long_term_principal_amount_in_company_currency = sum (
264+ long_term_moves .mapped ("debit" )
265+ ) - sum (long_term_moves .mapped ("credit" ))
266+ self .long_term_principal_amount = self .loan_id .company_id .currency_id ._convert (
267+ from_amount = long_term_principal_amount_in_company_currency ,
268+ to_currency = self .loan_id .currency_id ,
269+ company = self .loan_id .company_id ,
270+ date = self .date ,
271+ round = False ,
272+ )
273+
274+ payment_amount_in_company_currency = (
259275 sum (short_term_moves .mapped ("debit" ))
260276 - sum (short_term_moves .mapped ("credit" ))
261277 + self .long_term_principal_amount
262278 + self .interests_amount
263279 )
280+ self .payment_amount = self .loan_id .company_id .currency_id ._convert (
281+ from_amount = payment_amount_in_company_currency ,
282+ to_currency = self .loan_id .currency_id ,
283+ company = self .loan_id .company_id ,
284+ date = self .date ,
285+ round = False ,
286+ )
264287
265288 def _move_vals (self , journal = False , account = False ):
266289 self .ensure_one ()
@@ -283,10 +306,19 @@ def _add_basic_values(self, vals, account):
283306 "account_id" : (account and account .id )
284307 or partner .property_account_payable_id .id ,
285308 "partner_id" : partner .id ,
286- "credit" : self .payment_amount ,
287309 "debit" : 0 ,
310+ "currency_id" : self .loan_id .currency_id .id ,
311+ "credit" : self .loan_id .currency_id ._convert (
312+ from_amount = self .payment_amount ,
313+ to_currency = self .loan_id .company_id .currency_id ,
314+ company = self .loan_id .company_id ,
315+ date = self .date ,
316+ round = False ,
317+ ),
318+ "amount_currency" : - self .payment_amount ,
288319 }
289320 )
321+
290322 return vals
291323
292324 def _add_interests_values (self , vals ):
@@ -295,7 +327,15 @@ def _add_interests_values(self, vals):
295327 {
296328 "account_id" : self .loan_id .interest_expenses_account_id .id ,
297329 "credit" : 0 ,
298- "debit" : self .interests_amount ,
330+ "currency_id" : self .loan_id .currency_id .id ,
331+ "debit" : self .loan_id .currency_id ._convert (
332+ from_amount = self .interests_amount ,
333+ to_currency = self .loan_id .company_id .currency_id ,
334+ company = self .loan_id .company_id ,
335+ date = self .date ,
336+ round = False ,
337+ ),
338+ "amount_currency" : self .interests_amount ,
299339 }
300340 )
301341 return vals
@@ -306,7 +346,15 @@ def _add_short_term_account_values(self, vals):
306346 {
307347 "account_id" : self .loan_id .short_term_loan_account_id .id ,
308348 "credit" : 0 ,
309- "debit" : self .payment_amount - self .interests_amount ,
349+ "currency_id" : self .loan_id .currency_id .id ,
350+ "debit" : self .loan_id .currency_id ._convert (
351+ from_amount = self .payment_amount - self .interests_amount ,
352+ to_currency = self .loan_id .company_id .currency_id ,
353+ company = self .loan_id .company_id ,
354+ date = self .date ,
355+ round = False ,
356+ ),
357+ "amount_currency" : self .payment_amount - self .interests_amount ,
310358 }
311359 )
312360 return vals
@@ -317,15 +365,31 @@ def _add_long_term_account_values(self, vals):
317365 vals .append (
318366 {
319367 "account_id" : self .loan_id .short_term_loan_account_id .id ,
320- "credit" : self .long_term_principal_amount ,
321368 "debit" : 0 ,
369+ "currency_id" : self .loan_id .currency_id .id ,
370+ "credit" : self .loan_id .currency_id ._convert (
371+ from_amount = self .long_term_principal_amount ,
372+ to_currency = self .loan_id .company_id .currency_id ,
373+ company = self .loan_id .company_id ,
374+ date = self .date ,
375+ round = False ,
376+ ),
377+ "amount_currency" : - self .long_term_principal_amount ,
322378 }
323379 )
324380 vals .append (
325381 {
326382 "account_id" : self .long_term_loan_account_id .id ,
327383 "credit" : 0 ,
328- "debit" : self .long_term_principal_amount ,
384+ "currency_id" : self .loan_id .currency_id .id ,
385+ "debit" : self .loan_id .currency_id ._convert (
386+ from_amount = self .long_term_principal_amount ,
387+ to_currency = self .loan_id .company_id .currency_id ,
388+ company = self .loan_id .company_id ,
389+ date = self .date ,
390+ round = False ,
391+ ),
392+ "amount_currency" : self .long_term_principal_amount ,
329393 }
330394 )
331395 return vals
0 commit comments