refactor: don't book exch gain/loss for sales/purchase orders

This commit is contained in:
ruthra kumar
2023-04-25 20:26:50 +05:30
parent 04902e1b60
commit effb34bbfa

View File

@@ -654,6 +654,28 @@ class PaymentEntry(AccountsController):
self.precision("base_received_amount"), self.precision("base_received_amount"),
) )
def calculate_base_allocated_amount_for_reference(self, d) -> float:
base_allocated_amount = 0
if d.reference_doctype in frappe.get_hooks("advance_payment_doctypes"):
# When referencing Sales/Purchase Order, use the source/target exchange rate depending on payment type.
# This is so there are no Exchange Gain/Loss generated for such doctypes
exchange_rate = 1
if self.payment_type == "Receive":
exchange_rate = self.source_exchange_rate
elif self.payment_type == "Pay":
exchange_rate = self.target_exchange_rate
base_allocated_amount += flt(
flt(d.allocated_amount) * flt(exchange_rate), self.precision("base_paid_amount")
)
else:
base_allocated_amount += flt(
flt(d.allocated_amount) * flt(d.exchange_rate), self.precision("base_paid_amount")
)
return base_allocated_amount
def set_total_allocated_amount(self): def set_total_allocated_amount(self):
if self.payment_type == "Internal Transfer": if self.payment_type == "Internal Transfer":
return return
@@ -662,9 +684,7 @@ class PaymentEntry(AccountsController):
for d in self.get("references"): for d in self.get("references"):
if d.allocated_amount: if d.allocated_amount:
total_allocated_amount += flt(d.allocated_amount) total_allocated_amount += flt(d.allocated_amount)
base_total_allocated_amount += flt( base_total_allocated_amount += self.calculate_base_allocated_amount_for_reference(d)
flt(d.allocated_amount) * flt(d.exchange_rate), self.precision("base_paid_amount")
)
self.total_allocated_amount = abs(total_allocated_amount) self.total_allocated_amount = abs(total_allocated_amount)
self.base_total_allocated_amount = abs(base_total_allocated_amount) self.base_total_allocated_amount = abs(base_total_allocated_amount)
@@ -881,9 +901,7 @@ class PaymentEntry(AccountsController):
} }
) )
allocated_amount_in_company_currency = flt( allocated_amount_in_company_currency = self.calculate_base_allocated_amount_for_reference(d)
flt(d.allocated_amount) * flt(d.exchange_rate), self.precision("paid_amount")
)
gle.update( gle.update(
{ {