mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-15 19:19:17 +00:00
Merge pull request #33490 from frappe/mergify/bp/version-13-hotfix/pr-33487
Revert "fix: daily scheduler to identify and fix stock transfer entries having incorrect valuation" (backport #33487)
This commit is contained in:
@@ -526,7 +526,6 @@ scheduler_events = {
|
|||||||
"erpnext.loan_management.doctype.process_loan_security_shortfall.process_loan_security_shortfall.create_process_loan_security_shortfall",
|
"erpnext.loan_management.doctype.process_loan_security_shortfall.process_loan_security_shortfall.create_process_loan_security_shortfall",
|
||||||
"erpnext.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual.process_loan_interest_accrual_for_term_loans",
|
"erpnext.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual.process_loan_interest_accrual_for_term_loans",
|
||||||
"erpnext.crm.doctype.lead.lead.daily_open_lead",
|
"erpnext.crm.doctype.lead.lead.daily_open_lead",
|
||||||
"erpnext.stock.doctype.stock_entry.stock_entry.audit_incorrect_valuation_entries",
|
|
||||||
],
|
],
|
||||||
"weekly": ["erpnext.hr.doctype.employee.employee_reminders.send_reminders_in_advance_weekly"],
|
"weekly": ["erpnext.hr.doctype.employee.employee_reminders.send_reminders_in_advance_weekly"],
|
||||||
"monthly": ["erpnext.hr.doctype.employee.employee_reminders.send_reminders_in_advance_monthly"],
|
"monthly": ["erpnext.hr.doctype.employee.employee_reminders.send_reminders_in_advance_monthly"],
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import Dict
|
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
@@ -2567,61 +2566,3 @@ def get_supplied_items(purchase_order):
|
|||||||
|
|
||||||
return supplied_item_details
|
return supplied_item_details
|
||||||
|
|
||||||
|
|
||||||
def audit_incorrect_valuation_entries():
|
|
||||||
# Audit of stock transfer entries having incorrect valuation
|
|
||||||
from erpnext.controllers.stock_controller import create_repost_item_valuation_entry
|
|
||||||
|
|
||||||
stock_entries = get_incorrect_stock_entries()
|
|
||||||
|
|
||||||
for stock_entry, values in stock_entries.items():
|
|
||||||
reposting_data = frappe._dict(
|
|
||||||
{
|
|
||||||
"posting_date": values.posting_date,
|
|
||||||
"posting_time": values.posting_time,
|
|
||||||
"voucher_type": "Stock Entry",
|
|
||||||
"voucher_no": stock_entry,
|
|
||||||
"company": values.company,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
create_repost_item_valuation_entry(reposting_data)
|
|
||||||
|
|
||||||
|
|
||||||
def get_incorrect_stock_entries() -> Dict:
|
|
||||||
stock_entry = frappe.qb.DocType("Stock Entry")
|
|
||||||
stock_ledger_entry = frappe.qb.DocType("Stock Ledger Entry")
|
|
||||||
transfer_purposes = [
|
|
||||||
"Material Transfer",
|
|
||||||
"Material Transfer for Manufacture",
|
|
||||||
"Send to Subcontractor",
|
|
||||||
]
|
|
||||||
|
|
||||||
query = (
|
|
||||||
frappe.qb.from_(stock_entry)
|
|
||||||
.inner_join(stock_ledger_entry)
|
|
||||||
.on(stock_entry.name == stock_ledger_entry.voucher_no)
|
|
||||||
.select(
|
|
||||||
stock_entry.name,
|
|
||||||
stock_entry.company,
|
|
||||||
stock_entry.posting_date,
|
|
||||||
stock_entry.posting_time,
|
|
||||||
Sum(stock_ledger_entry.stock_value_difference).as_("stock_value"),
|
|
||||||
)
|
|
||||||
.where(
|
|
||||||
(stock_entry.docstatus == 1)
|
|
||||||
& (stock_entry.purpose.isin(transfer_purposes))
|
|
||||||
& (stock_ledger_entry.modified > add_days(today(), -2))
|
|
||||||
)
|
|
||||||
.groupby(stock_ledger_entry.voucher_detail_no)
|
|
||||||
.having(Sum(stock_ledger_entry.stock_value_difference) != 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
data = query.run(as_dict=True)
|
|
||||||
stock_entries = {}
|
|
||||||
|
|
||||||
for row in data:
|
|
||||||
if abs(row.stock_value) > 0.1 and row.name not in stock_entries:
|
|
||||||
stock_entries.setdefault(row.name, row)
|
|
||||||
|
|
||||||
return stock_entries
|
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ from erpnext.stock.doctype.item.test_item import (
|
|||||||
from erpnext.stock.doctype.serial_no.serial_no import * # noqa
|
from erpnext.stock.doctype.serial_no.serial_no import * # noqa
|
||||||
from erpnext.stock.doctype.stock_entry.stock_entry import (
|
from erpnext.stock.doctype.stock_entry.stock_entry import (
|
||||||
FinishedGoodError,
|
FinishedGoodError,
|
||||||
audit_incorrect_valuation_entries,
|
|
||||||
get_incorrect_stock_entries,
|
|
||||||
move_sample_to_retention_warehouse,
|
move_sample_to_retention_warehouse,
|
||||||
)
|
)
|
||||||
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
|
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
|
||||||
@@ -1573,44 +1571,6 @@ class TestStockEntry(FrappeTestCase):
|
|||||||
|
|
||||||
self.assertRaises(BatchExpiredError, se.save)
|
self.assertRaises(BatchExpiredError, se.save)
|
||||||
|
|
||||||
def test_audit_incorrect_stock_entries(self):
|
|
||||||
item_code = "Test Incorrect Valuation Rate Item - 001"
|
|
||||||
create_item(item_code=item_code, is_stock_item=1)
|
|
||||||
|
|
||||||
make_stock_entry(
|
|
||||||
item_code=item_code,
|
|
||||||
purpose="Material Receipt",
|
|
||||||
posting_date=add_days(nowdate(), -10),
|
|
||||||
qty=2,
|
|
||||||
rate=500,
|
|
||||||
to_warehouse="_Test Warehouse - _TC",
|
|
||||||
)
|
|
||||||
|
|
||||||
transfer_entry = make_stock_entry(
|
|
||||||
item_code=item_code,
|
|
||||||
purpose="Material Transfer",
|
|
||||||
qty=2,
|
|
||||||
rate=500,
|
|
||||||
from_warehouse="_Test Warehouse - _TC",
|
|
||||||
to_warehouse="_Test Warehouse 1 - _TC",
|
|
||||||
)
|
|
||||||
|
|
||||||
sle_name = frappe.db.get_value(
|
|
||||||
"Stock Ledger Entry", {"voucher_no": transfer_entry.name, "actual_qty": (">", 0)}, "name"
|
|
||||||
)
|
|
||||||
|
|
||||||
frappe.db.set_value(
|
|
||||||
"Stock Ledger Entry", sle_name, {"modified": add_days(now(), -1), "stock_value_difference": 10}
|
|
||||||
)
|
|
||||||
|
|
||||||
stock_entries = get_incorrect_stock_entries()
|
|
||||||
self.assertTrue(transfer_entry.name in stock_entries)
|
|
||||||
|
|
||||||
audit_incorrect_valuation_entries()
|
|
||||||
|
|
||||||
stock_entries = get_incorrect_stock_entries()
|
|
||||||
self.assertFalse(transfer_entry.name in stock_entries)
|
|
||||||
|
|
||||||
|
|
||||||
def make_serialized_item(**args):
|
def make_serialized_item(**args):
|
||||||
args = frappe._dict(args)
|
args = frappe._dict(args)
|
||||||
|
|||||||
Reference in New Issue
Block a user