Skip to content

Commit

Permalink
fix: incoming rate should be zero for rejected items (backport #44857) (
Browse files Browse the repository at this point in the history
#44859)

fix: incoming rate should be zero for rejected items (#44857)

(cherry picked from commit a515a39)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
  • Loading branch information
mergify[bot] and rohitwaghchaure authored Dec 23, 2024
1 parent 9543a4c commit 0969877
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
46 changes: 46 additions & 0 deletions erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -1838,6 +1838,52 @@ def test_adjust_incoming_rate(self):

frappe.db.set_single_value("Buying Settings", "maintain_same_rate", 1)

def test_adjust_incoming_rate_for_rejected_item(self):
frappe.db.set_single_value("Buying Settings", "maintain_same_rate", 0)

frappe.db.set_single_value("Buying Settings", "set_landed_cost_based_on_purchase_invoice_rate", 1)

# Cost of Item is zero in Purchase Receipt
pr = make_purchase_receipt(qty=1, rejected_qty=1, rate=0)

stock_value_difference = frappe.db.get_value(
"Stock Ledger Entry",
{"voucher_type": "Purchase Receipt", "voucher_no": pr.name},
"stock_value_difference",
)
self.assertEqual(stock_value_difference, 0)

pi = create_purchase_invoice_from_receipt(pr.name)
for row in pi.items:
row.qty = 1
row.rate = 150

pi.save()
pi.submit()

stock_value_difference = frappe.db.get_value(
"Stock Ledger Entry",
{"voucher_type": "Purchase Receipt", "voucher_no": pr.name, "warehouse": pi.items[0].warehouse},
"stock_value_difference",
)
self.assertEqual(stock_value_difference, 150)

stock_value_difference = frappe.db.get_value(
"Stock Ledger Entry",
{
"voucher_type": "Purchase Receipt",
"voucher_no": pr.name,
"warehouse": pi.items[0].rejected_warehouse,
},
"stock_value_difference",
)

self.assertFalse(stock_value_difference)

frappe.db.set_single_value("Buying Settings", "set_landed_cost_based_on_purchase_invoice_rate", 0)

frappe.db.set_single_value("Buying Settings", "maintain_same_rate", 1)

def test_item_less_defaults(self):
pi = frappe.new_doc("Purchase Invoice")
pi.supplier = "_Test Supplier"
Expand Down
5 changes: 5 additions & 0 deletions erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,12 +920,17 @@ def reserve_stock_for_sales_order(self):
)

def enable_recalculate_rate_in_sles(self):
rejected_warehouses = frappe.get_all(
"Purchase Receipt Item", filters={"parent": self.name}, pluck="rejected_warehouse"
)

sle_table = frappe.qb.DocType("Stock Ledger Entry")
(
frappe.qb.update(sle_table)
.set(sle_table.recalculate_rate, 1)
.where(sle_table.voucher_no == self.name)
.where(sle_table.voucher_type == "Purchase Receipt")
.where(sle_table.warehouse.notin(rejected_warehouses))
).run()


Expand Down

0 comments on commit 0969877

Please sign in to comment.