mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-30 17:42:32 +02:00
* fix: make adjustment entry using stock reconciliation (#37995)
fix: do adjustment entry using stock reconciliation
(cherry picked from commit a8216b9727)
# Conflicts:
# erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.json
# erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
* chore: fix conflicts
* fix: conflicts
* chore: fix conflicts
---------
Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
"warehouse",
|
"warehouse",
|
||||||
"posting_date",
|
"posting_date",
|
||||||
"posting_time",
|
"posting_time",
|
||||||
|
"is_adjustment_entry",
|
||||||
"column_break_6",
|
"column_break_6",
|
||||||
"voucher_type",
|
"voucher_type",
|
||||||
"voucher_no",
|
"voucher_no",
|
||||||
@@ -309,6 +310,12 @@
|
|||||||
"label": "Recalculate Incoming/Outgoing Rate",
|
"label": "Recalculate Incoming/Outgoing Rate",
|
||||||
"no_copy": 1,
|
"no_copy": 1,
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"fieldname": "is_adjustment_entry",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Is Adjustment Entry"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"hide_toolbar": 1,
|
"hide_toolbar": 1,
|
||||||
@@ -317,7 +324,7 @@
|
|||||||
"in_create": 1,
|
"in_create": 1,
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-12-21 06:25:30.040801",
|
"modified": "2023-10-23 18:07:42.063615",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Stock",
|
"module": "Stock",
|
||||||
"name": "Stock Ledger Entry",
|
"name": "Stock Ledger Entry",
|
||||||
@@ -341,4 +348,4 @@
|
|||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
"sort_order": "DESC",
|
"sort_order": "DESC",
|
||||||
"states": []
|
"states": []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -269,6 +269,10 @@ class StockReconciliation(StockController):
|
|||||||
if item.has_batch_no:
|
if item.has_batch_no:
|
||||||
has_batch_no = True
|
has_batch_no = True
|
||||||
|
|
||||||
|
if not row.qty and not row.valuation_rate and not row.current_qty:
|
||||||
|
self.make_adjustment_entry(row, sl_entries)
|
||||||
|
continue
|
||||||
|
|
||||||
if item.has_serial_no or item.has_batch_no:
|
if item.has_serial_no or item.has_batch_no:
|
||||||
has_serial_no = True
|
has_serial_no = True
|
||||||
self.get_sle_for_serialized_items(row, sl_entries, item)
|
self.get_sle_for_serialized_items(row, sl_entries, item)
|
||||||
@@ -402,6 +406,21 @@ class StockReconciliation(StockController):
|
|||||||
# update valuation rate
|
# update valuation rate
|
||||||
self.update_valuation_rate_for_serial_nos(row, serial_nos)
|
self.update_valuation_rate_for_serial_nos(row, serial_nos)
|
||||||
|
|
||||||
|
def make_adjustment_entry(self, row, sl_entries):
|
||||||
|
from erpnext.stock.stock_ledger import get_stock_value_difference
|
||||||
|
|
||||||
|
difference_amount = get_stock_value_difference(
|
||||||
|
row.item_code, row.warehouse, self.posting_date, self.posting_time
|
||||||
|
)
|
||||||
|
|
||||||
|
if not difference_amount:
|
||||||
|
return
|
||||||
|
|
||||||
|
args = self.get_sle_for_items(row)
|
||||||
|
args.update({"stock_value_difference": -1 * difference_amount, "is_adjustment_entry": 1})
|
||||||
|
|
||||||
|
sl_entries.append(args)
|
||||||
|
|
||||||
def update_valuation_rate_for_serial_no(self):
|
def update_valuation_rate_for_serial_no(self):
|
||||||
for d in self.items:
|
for d in self.items:
|
||||||
if not d.serial_no:
|
if not d.serial_no:
|
||||||
|
|||||||
@@ -635,9 +635,11 @@ class update_entries_after(object):
|
|||||||
sle.valuation_rate = self.wh_data.valuation_rate
|
sle.valuation_rate = self.wh_data.valuation_rate
|
||||||
sle.stock_value = self.wh_data.stock_value
|
sle.stock_value = self.wh_data.stock_value
|
||||||
sle.stock_queue = json.dumps(self.wh_data.stock_queue)
|
sle.stock_queue = json.dumps(self.wh_data.stock_queue)
|
||||||
sle.stock_value_difference = stock_value_difference
|
|
||||||
sle.doctype = "Stock Ledger Entry"
|
|
||||||
|
|
||||||
|
if not sle.is_adjustment_entry or not self.args.get("sle_id"):
|
||||||
|
sle.stock_value_difference = stock_value_difference
|
||||||
|
|
||||||
|
sle.doctype = "Stock Ledger Entry"
|
||||||
frappe.get_doc(sle).db_update()
|
frappe.get_doc(sle).db_update()
|
||||||
|
|
||||||
if not self.args.get("sle_id"):
|
if not self.args.get("sle_id"):
|
||||||
@@ -1711,3 +1713,27 @@ def is_internal_transfer(sle):
|
|||||||
|
|
||||||
if data.is_internal_supplier and data.represents_company == data.company:
|
if data.is_internal_supplier and data.represents_company == data.company:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def get_stock_value_difference(item_code, warehouse, posting_date, posting_time, voucher_no=None):
|
||||||
|
table = frappe.qb.DocType("Stock Ledger Entry")
|
||||||
|
|
||||||
|
query = (
|
||||||
|
frappe.qb.from_(table)
|
||||||
|
.select(Sum(table.stock_value_difference).as_("value"))
|
||||||
|
.where(
|
||||||
|
(table.is_cancelled == 0)
|
||||||
|
& (table.item_code == item_code)
|
||||||
|
& (table.warehouse == warehouse)
|
||||||
|
& (
|
||||||
|
(table.posting_date < posting_date)
|
||||||
|
| ((table.posting_date == posting_date) & (table.posting_time <= posting_time))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if voucher_no:
|
||||||
|
query = query.where(table.voucher_no != voucher_no)
|
||||||
|
|
||||||
|
difference_amount = query.run()
|
||||||
|
return flt(difference_amount[0][0]) if difference_amount else 0
|
||||||
|
|||||||
Reference in New Issue
Block a user