Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exchange gain loss not set for advances linked with invoices #25369

Merged

Conversation

nextchamp-saqib
Copy link
Member

@nextchamp-saqib nextchamp-saqib commented Apr 16, 2021

Problem:

  • Advance Payment Entry made for a Supplier of $10000 with exchange rate Rs. 71
  • An Invoice of $5000 with an exchange rate of Rs. 72 with advance entry linked is now submitted
  • Payment Entry now has an Allocated Amount of $5000 in USD, & Rs. 3,60,000 in INR
  • Payment Entry now has an Unallocated Amount of $5000 in USD, & Rs. 3,50,000 in INR
  • Now if an invoice of $5000 with an exchange rate of Rs. 73 with advance entry linked is again submitted, it will throw debit/credit mismatch error
  • This happens cuz, invoice 2 tries to allocate 5000 * 73 = Rs. 365000 while only Rs. 3,50,000 is left as an unallocated amount

Fix:

  • Create an "Exchange Rate Difference" field in the advance table of the invoice
  • Calculate the base currency difference due to exchange rates as follows
    • Payment Entry exchange rate = 72
    • Invoice exchange rate = 73
    • Invoice amount = $5000
    • $5000 * 73 = 3,65,000
    • $5000 * 72 = 3,60,000
    • 365000 - 360000 = 5000
  • Make a gain/loss GL entry of Rs. 5000 on invoice submission to book the gain & loss at invoice date
  • Fetch this difference amount & store it in the reference table of Payment Entry
  • Calculate the INR allocated amount accordingly using the gain/loss difference
  • The debit/credit should match as the gain/loss has been accounted for

Ref. Issue - ISS-20-21-10823


  • Make it work for Sales Invoice Advances too
  • Tests

@nabinhait nabinhait changed the base branch from develop to version-13-hotfix May 3, 2021 17:24
@nextchamp-saqib nextchamp-saqib changed the base branch from version-13-hotfix to develop June 23, 2021 04:50
@coveralls
Copy link

Coverage Status

Coverage remained the same at 42.882% when pulling 7a42519 on nextchamp-saqib:purchase-exchange-gain-loss-fix into 0b320b5 on frappe:develop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants