mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 16:34:46 +00:00
refactor: sample retention stock entry
This commit is contained in:
@@ -568,10 +568,6 @@ frappe.ui.form.on("Stock Entry", {
|
|||||||
if (r.message) {
|
if (r.message) {
|
||||||
var doc = frappe.model.sync(r.message)[0];
|
var doc = frappe.model.sync(r.message)[0];
|
||||||
frappe.set_route("Form", doc.doctype, doc.name);
|
frappe.set_route("Form", doc.doctype, doc.name);
|
||||||
} else {
|
|
||||||
frappe.msgprint(
|
|
||||||
__("Retention Stock Entry already created or Sample Quantity not provided")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -1054,7 +1050,7 @@ frappe.ui.form.on("Stock Entry Detail", {
|
|||||||
|
|
||||||
var validate_sample_quantity = function (frm, cdt, cdn) {
|
var validate_sample_quantity = function (frm, cdt, cdn) {
|
||||||
var d = locals[cdt][cdn];
|
var d = locals[cdt][cdn];
|
||||||
if (d.sample_quantity && frm.doc.purpose == "Material Receipt") {
|
if (d.sample_quantity && d.transfer_qty && frm.doc.purpose == "Material Receipt") {
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: "erpnext.stock.doctype.stock_entry.stock_entry.validate_sample_quantity",
|
method: "erpnext.stock.doctype.stock_entry.stock_entry.validate_sample_quantity",
|
||||||
args: {
|
args: {
|
||||||
|
|||||||
@@ -3408,10 +3408,10 @@ class StockEntry(StockController, SubcontractingInwardController):
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def move_sample_to_retention_warehouse(company, items):
|
def move_sample_to_retention_warehouse(company, items):
|
||||||
from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle import (
|
from erpnext.stock.serial_batch_bundle import (
|
||||||
get_batch_from_bundle,
|
SerialBatchCreation,
|
||||||
|
get_batch_nos,
|
||||||
)
|
)
|
||||||
from erpnext.stock.serial_batch_bundle import SerialBatchCreation
|
|
||||||
|
|
||||||
if isinstance(items, str):
|
if isinstance(items, str):
|
||||||
items = json.loads(items)
|
items = json.loads(items)
|
||||||
@@ -3422,38 +3422,46 @@ def move_sample_to_retention_warehouse(company, items):
|
|||||||
stock_entry.set_stock_entry_type()
|
stock_entry.set_stock_entry_type()
|
||||||
for item in items:
|
for item in items:
|
||||||
if item.get("sample_quantity") and item.get("serial_and_batch_bundle"):
|
if item.get("sample_quantity") and item.get("serial_and_batch_bundle"):
|
||||||
batch_no = get_batch_from_bundle(item.get("serial_and_batch_bundle"))
|
warehouse = item.get("t_warehouse") or item.get("warehouse")
|
||||||
sample_quantity = validate_sample_quantity(
|
total_qty = 0
|
||||||
item.get("item_code"),
|
cls_obj = SerialBatchCreation(
|
||||||
item.get("sample_quantity"),
|
{
|
||||||
item.get("transfer_qty") or item.get("qty"),
|
"type_of_transaction": "Outward",
|
||||||
batch_no,
|
"serial_and_batch_bundle": item.get("serial_and_batch_bundle"),
|
||||||
|
"item_code": item.get("item_code"),
|
||||||
|
"warehouse": warehouse,
|
||||||
|
"do_not_save": True,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
sabb = cls_obj.duplicate_package()
|
||||||
if sample_quantity:
|
batches = get_batch_nos(item.get("serial_and_batch_bundle"))
|
||||||
cls_obj = SerialBatchCreation(
|
for batch_no in batches.keys():
|
||||||
{
|
sample_quantity = validate_sample_quantity(
|
||||||
"type_of_transaction": "Outward",
|
item.get("item_code"),
|
||||||
"serial_and_batch_bundle": item.get("serial_and_batch_bundle"),
|
item.get("sample_quantity"),
|
||||||
"item_code": item.get("item_code"),
|
item.get("transfer_qty") or item.get("qty"),
|
||||||
"warehouse": item.get("t_warehouse"),
|
batch_no,
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
cls_obj.duplicate_package()
|
if sample_quantity:
|
||||||
|
total_qty += sample_quantity
|
||||||
|
sabe = next(item for item in sabb.entries if item.batch_no == batch_no)
|
||||||
|
sabe.qty = -1 * sample_quantity
|
||||||
|
|
||||||
|
if total_qty:
|
||||||
|
sabb.save()
|
||||||
stock_entry.append(
|
stock_entry.append(
|
||||||
"items",
|
"items",
|
||||||
{
|
{
|
||||||
"item_code": item.get("item_code"),
|
"item_code": item.get("item_code"),
|
||||||
"s_warehouse": item.get("t_warehouse"),
|
"s_warehouse": warehouse,
|
||||||
"t_warehouse": retention_warehouse,
|
"t_warehouse": retention_warehouse,
|
||||||
"qty": item.get("sample_quantity"),
|
"qty": total_qty,
|
||||||
"basic_rate": item.get("valuation_rate"),
|
"basic_rate": item.get("valuation_rate"),
|
||||||
"uom": item.get("uom"),
|
"uom": item.get("uom"),
|
||||||
"stock_uom": item.get("stock_uom"),
|
"stock_uom": item.get("stock_uom"),
|
||||||
"conversion_factor": item.get("conversion_factor") or 1.0,
|
"conversion_factor": item.get("conversion_factor") or 1.0,
|
||||||
"serial_and_batch_bundle": cls_obj.serial_and_batch_bundle,
|
"serial_and_batch_bundle": sabb.name,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if stock_entry.get("items"):
|
if stock_entry.get("items"):
|
||||||
|
|||||||
@@ -1116,7 +1116,7 @@ class SerialBatchCreation:
|
|||||||
|
|
||||||
id = self.serial_and_batch_bundle
|
id = self.serial_and_batch_bundle
|
||||||
package = frappe.get_doc("Serial and Batch Bundle", id)
|
package = frappe.get_doc("Serial and Batch Bundle", id)
|
||||||
new_package = frappe.copy_doc(package)
|
new_package = frappe.copy_doc(package, ignore_no_copy=False)
|
||||||
|
|
||||||
if self.get("returned_serial_nos"):
|
if self.get("returned_serial_nos"):
|
||||||
self.remove_returned_serial_nos(new_package)
|
self.remove_returned_serial_nos(new_package)
|
||||||
|
|||||||
Reference in New Issue
Block a user