Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: stock reconciliation for serialized and batch items #17832

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions erpnext/stock/doctype/serial_no/serial_no.py
Expand Up @@ -222,7 +222,7 @@ def validate_serial_no(sle, item_det):
frappe.throw(_("Serial No {0} has already been received").format(serial_no),
SerialNoDuplicateError)

if (sr.delivery_document_no and sle.voucher_type != 'Stock Entry'
if (sr.delivery_document_no and sle.voucher_type not in ['Stock Entry', 'Stock Reconciliation']
and sle.voucher_type == sr.delivery_document_type):
return_against = frappe.db.get_value(sle.voucher_type, sle.voucher_no, 'return_against')
if return_against and return_against != sr.delivery_document_no:
Expand Down Expand Up @@ -299,7 +299,7 @@ def validate_so_serial_no(sr, sales_order,):
be delivered""").format(sales_order, sr.item_code, sr.name))

def has_duplicate_serial_no(sn, sle):
if sn.warehouse:
if sn.warehouse and sle.voucher_type != 'Stock Reconciliation':
return True

if sn.company != sle.company:
Expand Down Expand Up @@ -413,12 +413,14 @@ def update_serial_nos_after_submit(controller, parentfield):
update_rejected_serial_nos = True if (controller.doctype in ("Purchase Receipt", "Purchase Invoice")
and d.rejected_qty) else False
accepted_serial_nos_updated = False

if controller.doctype == "Stock Entry":
warehouse = d.t_warehouse
qty = d.transfer_qty
else:
warehouse = d.warehouse
qty = d.stock_qty
qty = (d.qty if controller.doctype == "Stock Reconciliation"
else d.stock_qty)

for sle in stock_ledger_entries:
if sle.voucher_detail_no==d.name:
Expand Down
Expand Up @@ -38,7 +38,7 @@ def on_submit(self):
self.check_stock_frozen_date()
self.actual_amt_check()

if not self.get("via_landed_cost_voucher") and self.voucher_type != 'Stock Reconciliation':
if not self.get("via_landed_cost_voucher"):
from erpnext.stock.doctype.serial_no.serial_no import process_serial_no
process_serial_no(self)

Expand Down
Expand Up @@ -12,8 +12,7 @@ frappe.ui.form.on("Stock Reconciliation", {
return {
query: "erpnext.controllers.queries.item_query",
filters:{
"is_stock_item": 1,
"has_serial_no": 0
"is_stock_item": 1
}
}
});
Expand Down Expand Up @@ -77,14 +76,16 @@ frappe.ui.form.on("Stock Reconciliation", {

set_valuation_rate_and_qty: function(frm, cdt, cdn) {
var d = frappe.model.get_doc(cdt, cdn);

if(d.item_code && d.warehouse) {
frappe.call({
method: "erpnext.stock.doctype.stock_reconciliation.stock_reconciliation.get_stock_balance_for",
args: {
item_code: d.item_code,
warehouse: d.warehouse,
posting_date: frm.doc.posting_date,
posting_time: frm.doc.posting_time
posting_time: frm.doc.posting_time,
batch_no: d.batch_no
},
callback: function(r) {
frappe.model.set_value(cdt, cdn, "qty", r.message.qty);
Expand All @@ -93,7 +94,7 @@ frappe.ui.form.on("Stock Reconciliation", {
frappe.model.set_value(cdt, cdn, "current_valuation_rate", r.message.rate);
frappe.model.set_value(cdt, cdn, "current_amount", r.message.rate * r.message.qty);
frappe.model.set_value(cdt, cdn, "amount", r.message.rate * r.message.qty);

frappe.model.set_value(cdt, cdn, "current_serial_no", r.message.serial_nos);
}
});
}
Expand Down Expand Up @@ -152,17 +153,44 @@ frappe.ui.form.on("Stock Reconciliation Item", {
barcode: function(frm, cdt, cdn) {
frm.events.set_item_code(frm, cdt, cdn);
},

warehouse: function(frm, cdt, cdn) {
var child = locals[cdt][cdn];
if (child.batch_no) {
frappe.model.set_value(child.cdt, child.cdn, "batch_no", "");
}

frm.events.set_valuation_rate_and_qty(frm, cdt, cdn);
},

item_code: function(frm, cdt, cdn) {
var child = locals[cdt][cdn];
if (child.batch_no) {
frappe.model.set_value(cdt, cdn, "batch_no", "");
}

frm.events.set_valuation_rate_and_qty(frm, cdt, cdn);
},

batch_no: function(frm, cdt, cdn) {
frm.events.set_valuation_rate_and_qty(frm, cdt, cdn);
},

qty: function(frm, cdt, cdn) {
frm.events.set_amount_quantity(frm, cdt, cdn);
},

valuation_rate: function(frm, cdt, cdn) {
frm.events.set_amount_quantity(frm, cdt, cdn);
},

serial_no: function(frm, cdt, cdn) {
var child = locals[cdt][cdn];

if (child.serial_no) {
const serial_nos = child.serial_no.trim().split('\n');
frappe.model.set_value(cdt, cdn, "qty", serial_nos.length);
}
}

});
Expand Down