mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-15 11:09:17 +00:00
Merge pull request #48761 from aerele/exchange-gain-or-loss-on-repost
fix: prevent gain or loss entry cancellation upon reposting
(cherry picked from commit a8d17b7590)
This commit is contained in:
committed by
ruthra kumar
parent
daf3aab6ae
commit
6e7fb2ea01
@@ -178,7 +178,7 @@ def start_repost(account_repost_doc=str) -> None:
|
|||||||
if doc.doctype in ["Sales Invoice", "Purchase Invoice"]:
|
if doc.doctype in ["Sales Invoice", "Purchase Invoice"]:
|
||||||
if not repost_doc.delete_cancelled_entries:
|
if not repost_doc.delete_cancelled_entries:
|
||||||
doc.docstatus = 2
|
doc.docstatus = 2
|
||||||
doc.make_gl_entries_on_cancel()
|
doc.make_gl_entries_on_cancel(from_repost=True)
|
||||||
|
|
||||||
doc.docstatus = 1
|
doc.docstatus = 1
|
||||||
if doc.doctype == "Sales Invoice":
|
if doc.doctype == "Sales Invoice":
|
||||||
@@ -190,7 +190,7 @@ def start_repost(account_repost_doc=str) -> None:
|
|||||||
elif doc.doctype == "Purchase Receipt":
|
elif doc.doctype == "Purchase Receipt":
|
||||||
if not repost_doc.delete_cancelled_entries:
|
if not repost_doc.delete_cancelled_entries:
|
||||||
doc.docstatus = 2
|
doc.docstatus = 2
|
||||||
doc.make_gl_entries_on_cancel()
|
doc.make_gl_entries_on_cancel(from_repost=True)
|
||||||
|
|
||||||
doc.docstatus = 1
|
doc.docstatus = 1
|
||||||
doc.make_gl_entries(from_repost=True)
|
doc.make_gl_entries(from_repost=True)
|
||||||
|
|||||||
@@ -1206,7 +1206,6 @@ class SalesInvoice(SellingController):
|
|||||||
|
|
||||||
self.make_exchange_gain_loss_journal()
|
self.make_exchange_gain_loss_journal()
|
||||||
elif self.docstatus == 2:
|
elif self.docstatus == 2:
|
||||||
cancel_exchange_gain_loss_journal(frappe._dict(doctype=self.doctype, name=self.name))
|
|
||||||
make_reverse_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
|
make_reverse_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
|
||||||
|
|
||||||
if update_outstanding == "No":
|
if update_outstanding == "No":
|
||||||
|
|||||||
@@ -4668,6 +4668,59 @@ class TestSalesInvoice(FrappeTestCase):
|
|||||||
|
|
||||||
doc.db_set("do_not_use_batchwise_valuation", original_value)
|
doc.db_set("do_not_use_batchwise_valuation", original_value)
|
||||||
|
|
||||||
|
def test_system_generated_exchange_gain_or_loss_je_after_repost(self):
|
||||||
|
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry
|
||||||
|
from erpnext.accounts.doctype.repost_accounting_ledger.test_repost_accounting_ledger import (
|
||||||
|
update_repost_settings,
|
||||||
|
)
|
||||||
|
|
||||||
|
update_repost_settings()
|
||||||
|
|
||||||
|
si = create_sales_invoice(
|
||||||
|
customer="_Test Customer USD",
|
||||||
|
debit_to="_Test Receivable USD - _TC",
|
||||||
|
currency="USD",
|
||||||
|
conversion_rate=80,
|
||||||
|
)
|
||||||
|
|
||||||
|
pe = get_payment_entry("Sales Invoice", si.name)
|
||||||
|
pe.reference_no = "10"
|
||||||
|
pe.reference_date = nowdate()
|
||||||
|
pe.paid_from_account_currency = si.currency
|
||||||
|
pe.paid_to_account_currency = "INR"
|
||||||
|
pe.source_exchange_rate = 85
|
||||||
|
pe.target_exchange_rate = 1
|
||||||
|
pe.paid_amount = si.outstanding_amount
|
||||||
|
pe.insert()
|
||||||
|
pe.submit()
|
||||||
|
|
||||||
|
ral = frappe.new_doc("Repost Accounting Ledger")
|
||||||
|
ral.company = si.company
|
||||||
|
ral.append("vouchers", {"voucher_type": si.doctype, "voucher_no": si.name})
|
||||||
|
ral.save()
|
||||||
|
ral.submit()
|
||||||
|
|
||||||
|
je = frappe.qb.DocType("Journal Entry")
|
||||||
|
jea = frappe.qb.DocType("Journal Entry Account")
|
||||||
|
q = (
|
||||||
|
(
|
||||||
|
frappe.qb.from_(je)
|
||||||
|
.join(jea)
|
||||||
|
.on(je.name == jea.parent)
|
||||||
|
.select(je.docstatus)
|
||||||
|
.where(
|
||||||
|
(je.voucher_type == "Exchange Gain Or Loss")
|
||||||
|
& (jea.reference_name == si.name)
|
||||||
|
& (jea.reference_type == "Sales Invoice")
|
||||||
|
& (je.is_system_generated == 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.limit(1)
|
||||||
|
.run()
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(q[0][0], 1)
|
||||||
|
|
||||||
|
|
||||||
def make_item_for_si(item_code, properties=None):
|
def make_item_for_si(item_code, properties=None):
|
||||||
from erpnext.stock.doctype.item.test_item import make_item
|
from erpnext.stock.doctype.item.test_item import make_item
|
||||||
|
|||||||
@@ -959,8 +959,9 @@ class StockController(AccountsController):
|
|||||||
make_sl_entries(sl_entries, allow_negative_stock, via_landed_cost_voucher)
|
make_sl_entries(sl_entries, allow_negative_stock, via_landed_cost_voucher)
|
||||||
update_batch_qty(self.doctype, self.name, via_landed_cost_voucher=via_landed_cost_voucher)
|
update_batch_qty(self.doctype, self.name, via_landed_cost_voucher=via_landed_cost_voucher)
|
||||||
|
|
||||||
def make_gl_entries_on_cancel(self):
|
def make_gl_entries_on_cancel(self, from_repost=False):
|
||||||
cancel_exchange_gain_loss_journal(frappe._dict(doctype=self.doctype, name=self.name))
|
if not from_repost:
|
||||||
|
cancel_exchange_gain_loss_journal(frappe._dict(doctype=self.doctype, name=self.name))
|
||||||
if frappe.db.sql(
|
if frappe.db.sql(
|
||||||
"""select name from `tabGL Entry` where voucher_type=%s
|
"""select name from `tabGL Entry` where voucher_type=%s
|
||||||
and voucher_no=%s""",
|
and voucher_no=%s""",
|
||||||
|
|||||||
Reference in New Issue
Block a user