Revert "fix: daily scheduler to identify and fix stock transfer entries having incorrect valuation"
(cherry picked from commit 728dc1acf4)
# Conflicts:
# erpnext/hooks.py
# erpnext/stock/doctype/stock_entry/stock_entry.py
# erpnext/stock/doctype/stock_entry/test_stock_entry.py
This commit is contained in:
@@ -525,8 +525,12 @@ scheduler_events = {
|
|||||||
"erpnext.hr.utils.allocate_earned_leaves",
|
"erpnext.hr.utils.allocate_earned_leaves",
|
||||||
"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",
|
||||||
|
<<<<<<< HEAD
|
||||||
"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",
|
"erpnext.stock.doctype.stock_entry.stock_entry.audit_incorrect_valuation_entries",
|
||||||
|
=======
|
||||||
|
"erpnext.crm.utils.open_leads_opportunities_based_on_todays_event",
|
||||||
|
>>>>>>> 728dc1acf4 (Revert "fix: daily scheduler to identify and fix stock transfer entries having incorrect valuation")
|
||||||
],
|
],
|
||||||
"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,12 +4,12 @@
|
|||||||
|
|
||||||
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 _
|
||||||
from frappe.model.mapper import get_mapped_doc
|
from frappe.model.mapper import get_mapped_doc
|
||||||
from frappe.query_builder.functions import Sum
|
from frappe.query_builder.functions import Sum
|
||||||
|
<<<<<<< HEAD
|
||||||
from frappe.utils import (
|
from frappe.utils import (
|
||||||
add_days,
|
add_days,
|
||||||
cint,
|
cint,
|
||||||
@@ -23,6 +23,9 @@ from frappe.utils import (
|
|||||||
today,
|
today,
|
||||||
)
|
)
|
||||||
from six import iteritems, itervalues, string_types
|
from six import iteritems, itervalues, string_types
|
||||||
|
=======
|
||||||
|
from frappe.utils import cint, comma_or, cstr, flt, format_time, formatdate, getdate, nowdate
|
||||||
|
>>>>>>> 728dc1acf4 (Revert "fix: daily scheduler to identify and fix stock transfer entries having incorrect valuation")
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
from erpnext.accounts.general_ledger import process_gl_map
|
from erpnext.accounts.general_ledger import process_gl_map
|
||||||
@@ -2568,6 +2571,7 @@ def get_supplied_items(purchase_order):
|
|||||||
return supplied_item_details
|
return supplied_item_details
|
||||||
|
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
def audit_incorrect_valuation_entries():
|
def audit_incorrect_valuation_entries():
|
||||||
# Audit of stock transfer entries having incorrect valuation
|
# Audit of stock transfer entries having incorrect valuation
|
||||||
from erpnext.controllers.stock_controller import create_repost_item_valuation_entry
|
from erpnext.controllers.stock_controller import create_repost_item_valuation_entry
|
||||||
@@ -2625,3 +2629,96 @@ def get_incorrect_stock_entries() -> Dict:
|
|||||||
stock_entries.setdefault(row.name, row)
|
stock_entries.setdefault(row.name, row)
|
||||||
|
|
||||||
return stock_entries
|
return stock_entries
|
||||||
|
=======
|
||||||
|
@frappe.whitelist()
|
||||||
|
def get_items_from_subcontract_order(source_name, target_doc=None):
|
||||||
|
from erpnext.controllers.subcontracting_controller import make_rm_stock_entry
|
||||||
|
|
||||||
|
if isinstance(target_doc, str):
|
||||||
|
target_doc = frappe.get_doc(json.loads(target_doc))
|
||||||
|
|
||||||
|
order_doctype = "Purchase Order" if target_doc.purchase_order else "Subcontracting Order"
|
||||||
|
target_doc = make_rm_stock_entry(
|
||||||
|
subcontract_order=source_name, order_doctype=order_doctype, target_doc=target_doc
|
||||||
|
)
|
||||||
|
|
||||||
|
return target_doc
|
||||||
|
|
||||||
|
|
||||||
|
def get_available_materials(work_order) -> dict:
|
||||||
|
data = get_stock_entry_data(work_order)
|
||||||
|
|
||||||
|
available_materials = {}
|
||||||
|
for row in data:
|
||||||
|
key = (row.item_code, row.warehouse)
|
||||||
|
if row.purpose != "Material Transfer for Manufacture":
|
||||||
|
key = (row.item_code, row.s_warehouse)
|
||||||
|
|
||||||
|
if key not in available_materials:
|
||||||
|
available_materials.setdefault(
|
||||||
|
key,
|
||||||
|
frappe._dict(
|
||||||
|
{"item_details": row, "batch_details": defaultdict(float), "qty": 0, "serial_nos": []}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
item_data = available_materials[key]
|
||||||
|
|
||||||
|
if row.purpose == "Material Transfer for Manufacture":
|
||||||
|
item_data.qty += row.qty
|
||||||
|
if row.batch_no:
|
||||||
|
item_data.batch_details[row.batch_no] += row.qty
|
||||||
|
|
||||||
|
if row.serial_no:
|
||||||
|
item_data.serial_nos.extend(get_serial_nos(row.serial_no))
|
||||||
|
item_data.serial_nos.sort()
|
||||||
|
else:
|
||||||
|
# Consume raw material qty in case of 'Manufacture' or 'Material Consumption for Manufacture'
|
||||||
|
|
||||||
|
item_data.qty -= row.qty
|
||||||
|
if row.batch_no:
|
||||||
|
item_data.batch_details[row.batch_no] -= row.qty
|
||||||
|
|
||||||
|
if row.serial_no:
|
||||||
|
for serial_no in get_serial_nos(row.serial_no):
|
||||||
|
item_data.serial_nos.remove(serial_no)
|
||||||
|
|
||||||
|
return available_materials
|
||||||
|
|
||||||
|
|
||||||
|
def get_stock_entry_data(work_order):
|
||||||
|
stock_entry = frappe.qb.DocType("Stock Entry")
|
||||||
|
stock_entry_detail = frappe.qb.DocType("Stock Entry Detail")
|
||||||
|
|
||||||
|
return (
|
||||||
|
frappe.qb.from_(stock_entry)
|
||||||
|
.from_(stock_entry_detail)
|
||||||
|
.select(
|
||||||
|
stock_entry_detail.item_name,
|
||||||
|
stock_entry_detail.original_item,
|
||||||
|
stock_entry_detail.item_code,
|
||||||
|
stock_entry_detail.qty,
|
||||||
|
(stock_entry_detail.t_warehouse).as_("warehouse"),
|
||||||
|
(stock_entry_detail.s_warehouse).as_("s_warehouse"),
|
||||||
|
stock_entry_detail.description,
|
||||||
|
stock_entry_detail.stock_uom,
|
||||||
|
stock_entry_detail.expense_account,
|
||||||
|
stock_entry_detail.cost_center,
|
||||||
|
stock_entry_detail.batch_no,
|
||||||
|
stock_entry_detail.serial_no,
|
||||||
|
stock_entry.purpose,
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
(stock_entry.name == stock_entry_detail.parent)
|
||||||
|
& (stock_entry.work_order == work_order)
|
||||||
|
& (stock_entry.docstatus == 1)
|
||||||
|
& (stock_entry_detail.s_warehouse.isnotnull())
|
||||||
|
& (
|
||||||
|
stock_entry.purpose.isin(
|
||||||
|
["Manufacture", "Material Consumption for Manufacture", "Material Transfer for Manufacture"]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.orderby(stock_entry.creation, stock_entry_detail.item_code, stock_entry_detail.idx)
|
||||||
|
).run(as_dict=1)
|
||||||
|
>>>>>>> 728dc1acf4 (Revert "fix: daily scheduler to identify and fix stock transfer entries having incorrect valuation")
|
||||||
|
|||||||
@@ -5,8 +5,12 @@
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe.permissions import add_user_permission, remove_user_permission
|
from frappe.permissions import add_user_permission, remove_user_permission
|
||||||
from frappe.tests.utils import FrappeTestCase, change_settings
|
from frappe.tests.utils import FrappeTestCase, change_settings
|
||||||
|
<<<<<<< HEAD
|
||||||
from frappe.utils import add_days, flt, now, nowdate, nowtime, today
|
from frappe.utils import add_days, flt, now, nowdate, nowtime, today
|
||||||
from six import iteritems
|
from six import iteritems
|
||||||
|
=======
|
||||||
|
from frappe.utils import add_days, flt, nowdate, nowtime, today
|
||||||
|
>>>>>>> 728dc1acf4 (Revert "fix: daily scheduler to identify and fix stock transfer entries having incorrect valuation")
|
||||||
|
|
||||||
from erpnext.accounts.doctype.account.test_account import get_inventory_account
|
from erpnext.accounts.doctype.account.test_account import get_inventory_account
|
||||||
from erpnext.stock.doctype.item.test_item import (
|
from erpnext.stock.doctype.item.test_item import (
|
||||||
@@ -18,8 +22,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 +1575,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