Skip to content

Commit

Permalink
fix: debit credit mismatch in multi-currecy asset purchase receipt (f…
Browse files Browse the repository at this point in the history
…rappe#38342)

* fix: Debit credit mimatch in multicurrecy asset purchase receipt

* test: multi currency purchase receipt

* chore: update init files

* test: roolback
  • Loading branch information
deepeshgarg007 authored Nov 28, 2023
1 parent ad3634b commit add238c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 68 deletions.
103 changes: 36 additions & 67 deletions erpnext/assets/doctype/asset/test_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,7 @@ def test_purchase_asset(self):
("Creditors - _TC", 0.0, 100000.0),
)

gle = frappe.db.sql(
"""select account, debit, credit from `tabGL Entry`
where voucher_type='Purchase Invoice' and voucher_no = %s
order by account""",
pi.name,
)
gle = get_gl_entries("Purchase Invoice", pi.name)
self.assertSequenceEqual(gle, expected_gle)

pi.cancel()
Expand Down Expand Up @@ -264,12 +259,7 @@ def test_scrap_asset(self):
),
)

gle = frappe.db.sql(
"""select account, debit, credit from `tabGL Entry`
where voucher_type='Journal Entry' and voucher_no = %s
order by account""",
asset.journal_entry_for_scrap,
)
gle = get_gl_entries("Journal Entry", asset.journal_entry_for_scrap)
self.assertSequenceEqual(gle, expected_gle)

restore_asset(asset.name)
Expand Down Expand Up @@ -345,13 +335,7 @@ def test_gle_made_by_asset_sale(self):
("Debtors - _TC", 25000.0, 0.0),
)

gle = frappe.db.sql(
"""select account, debit, credit from `tabGL Entry`
where voucher_type='Sales Invoice' and voucher_no = %s
order by account""",
si.name,
)

gle = get_gl_entries("Sales Invoice", si.name)
self.assertSequenceEqual(gle, expected_gle)

si.cancel()
Expand Down Expand Up @@ -425,13 +409,7 @@ def test_gle_made_by_asset_sale_for_existing_asset(self):
("Debtors - _TC", 40000.0, 0.0),
)

gle = frappe.db.sql(
"""select account, debit, credit from `tabGL Entry`
where voucher_type='Sales Invoice' and voucher_no = %s
order by account""",
si.name,
)

gle = get_gl_entries("Sales Invoice", si.name)
self.assertSequenceEqual(gle, expected_gle)

def test_asset_with_maintenance_required_status_after_sale(self):
Expand Down Expand Up @@ -572,13 +550,7 @@ def test_cwip_accounting(self):
("CWIP Account - _TC", 5250.0, 0.0),
)

pr_gle = frappe.db.sql(
"""select account, debit, credit from `tabGL Entry`
where voucher_type='Purchase Receipt' and voucher_no = %s
order by account""",
pr.name,
)

pr_gle = get_gl_entries("Purchase Receipt", pr.name)
self.assertSequenceEqual(pr_gle, expected_gle)

pi = make_invoice(pr.name)
Expand All @@ -591,13 +563,7 @@ def test_cwip_accounting(self):
("Creditors - _TC", 0.0, 5500.0),
)

pi_gle = frappe.db.sql(
"""select account, debit, credit from `tabGL Entry`
where voucher_type='Purchase Invoice' and voucher_no = %s
order by account""",
pi.name,
)

pi_gle = get_gl_entries("Purchase Invoice", pi.name)
self.assertSequenceEqual(pi_gle, expected_gle)

asset = frappe.db.get_value("Asset", {"purchase_receipt": pr.name, "docstatus": 0}, "name")
Expand All @@ -624,13 +590,7 @@ def test_cwip_accounting(self):

expected_gle = (("_Test Fixed Asset - _TC", 5250.0, 0.0), ("CWIP Account - _TC", 0.0, 5250.0))

gle = frappe.db.sql(
"""select account, debit, credit from `tabGL Entry`
where voucher_type='Asset' and voucher_no = %s
order by account""",
asset_doc.name,
)

gle = get_gl_entries("Asset", asset_doc.name)
self.assertSequenceEqual(gle, expected_gle)

def test_asset_cwip_toggling_cases(self):
Expand All @@ -653,10 +613,7 @@ def test_asset_cwip_toggling_cases(self):
asset_doc.available_for_use_date = nowdate()
asset_doc.calculate_depreciation = 0
asset_doc.submit()
gle = frappe.db.sql(
"""select name from `tabGL Entry` where voucher_type='Asset' and voucher_no = %s""",
asset_doc.name,
)
gle = get_gl_entries("Asset", asset_doc.name)
self.assertFalse(gle)

# case 1 -- PR with cwip disabled, Asset with cwip enabled
Expand All @@ -670,10 +627,7 @@ def test_asset_cwip_toggling_cases(self):
asset_doc.available_for_use_date = nowdate()
asset_doc.calculate_depreciation = 0
asset_doc.submit()
gle = frappe.db.sql(
"""select name from `tabGL Entry` where voucher_type='Asset' and voucher_no = %s""",
asset_doc.name,
)
gle = get_gl_entries("Asset", asset_doc.name)
self.assertFalse(gle)

# case 2 -- PR with cwip enabled, Asset with cwip disabled
Expand All @@ -686,10 +640,7 @@ def test_asset_cwip_toggling_cases(self):
asset_doc.available_for_use_date = nowdate()
asset_doc.calculate_depreciation = 0
asset_doc.submit()
gle = frappe.db.sql(
"""select name from `tabGL Entry` where voucher_type='Asset' and voucher_no = %s""",
asset_doc.name,
)
gle = get_gl_entries("Asset", asset_doc.name)
self.assertTrue(gle)

# case 3 -- PI with cwip disabled, Asset with cwip enabled
Expand All @@ -702,10 +653,7 @@ def test_asset_cwip_toggling_cases(self):
asset_doc.available_for_use_date = nowdate()
asset_doc.calculate_depreciation = 0
asset_doc.submit()
gle = frappe.db.sql(
"""select name from `tabGL Entry` where voucher_type='Asset' and voucher_no = %s""",
asset_doc.name,
)
gle = get_gl_entries("Asset", asset_doc.name)
self.assertFalse(gle)

# case 4 -- PI with cwip enabled, Asset with cwip disabled
Expand All @@ -718,10 +666,7 @@ def test_asset_cwip_toggling_cases(self):
asset_doc.available_for_use_date = nowdate()
asset_doc.calculate_depreciation = 0
asset_doc.submit()
gle = frappe.db.sql(
"""select name from `tabGL Entry` where voucher_type='Asset' and voucher_no = %s""",
asset_doc.name,
)
gle = get_gl_entries("Asset", asset_doc.name)
self.assertTrue(gle)

frappe.db.set_value("Asset Category", "Computers", "enable_cwip_accounting", cwip)
Expand Down Expand Up @@ -1701,6 +1646,30 @@ def test_manual_depreciation_with_incorrect_jv_voucher_type(self):

self.assertRaises(frappe.ValidationError, jv.insert)

def test_multi_currency_asset_pr_creation(self):
pr = make_purchase_receipt(
item_code="Macbook Pro",
qty=1,
rate=100.0,
location="Test Location",
supplier="_Test Supplier USD",
currency="USD",
)

pr.submit()
self.assertTrue(get_gl_entries("Purchase Receipt", pr.name))


def get_gl_entries(doctype, docname):
gl_entry = frappe.qb.DocType("GL Entry")
return (
frappe.qb.from_(gl_entry)
.select(gl_entry.account, gl_entry.debit, gl_entry.credit)
.where((gl_entry.voucher_type == doctype) & (gl_entry.voucher_no == docname))
.orderby(gl_entry.account)
.run()
)


def create_asset_data():
if not frappe.db.exists("Asset Category", "Computers"):
Expand Down
2 changes: 1 addition & 1 deletion erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ def make_divisional_loss_gl_entry(item, outgoing_amount):
)

stock_value_diff = (
flt(d.net_amount)
flt(d.base_net_amount)
+ flt(d.item_tax_amount / self.conversion_rate)
+ flt(d.landed_cost_voucher_amount)
)
Expand Down
Empty file.
Empty file.

0 comments on commit add238c

Please sign in to comment.