chore: allow return of components in SCO (#31994)

chore: allow return of components in sco
This commit is contained in:
Sagar Sharma 2022-08-26 22:49:40 +05:30 committed by GitHub
parent 7da39c3ff3
commit af5cbc881f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 32 additions and 12 deletions

View File

@ -2229,7 +2229,7 @@ class StockEntry(StockController):
return sorted(list(set(get_serial_nos(self.pro_doc.serial_no)) - set(used_serial_nos)))
def update_subcontracting_order_status(self):
if self.subcontracting_order and self.purpose == "Send to Subcontractor":
if self.subcontracting_order and self.purpose in ["Send to Subcontractor", "Material Transfer"]:
from erpnext.subcontracting.doctype.subcontracting_order.subcontracting_order import (
update_subcontracting_order_status,
)

View File

@ -107,9 +107,9 @@ frappe.ui.form.on('Subcontracting Order', {
get_materials_from_supplier: function (frm) {
let sco_rm_details = [];
if (frm.doc.supplied_items && (frm.doc.per_received == 100)) {
if (frm.doc.supplied_items && frm.doc.per_received > 0) {
frm.doc.supplied_items.forEach(d => {
if (d.total_supplied_qty && d.total_supplied_qty != d.consumed_qty) {
if (d.total_supplied_qty > 0 && d.total_supplied_qty != d.consumed_qty) {
sco_rm_details.push(d.name);
}
});
@ -160,7 +160,7 @@ erpnext.buying.SubcontractingOrderController = class SubcontractingOrderControll
var me = this;
if (doc.docstatus == 1) {
if (doc.status != 'Completed') {
if (!['Closed', 'Completed'].includes(doc.status)) {
if (flt(doc.per_received) < 100) {
cur_frm.add_custom_button(__('Subcontracting Receipt'), this.make_subcontracting_receipt, __('Create'));
if (me.has_unsupplied_items()) {

View File

@ -153,7 +153,7 @@ class SubcontractingOrder(SubcontractingController):
else:
self.set_missing_values()
def update_status(self, status=None, update_modified=False):
def update_status(self, status=None, update_modified=True):
if self.docstatus >= 1 and not status:
if self.docstatus == 1:
if self.status == "Draft":
@ -162,6 +162,10 @@ class SubcontractingOrder(SubcontractingController):
status = "Completed"
elif self.per_received > 0 and self.per_received < 100:
status = "Partially Received"
for item in self.supplied_items:
if item.returned_qty:
status = "Closed"
break
else:
total_required_qty = total_supplied_qty = 0
for item in self.supplied_items:
@ -176,7 +180,10 @@ class SubcontractingOrder(SubcontractingController):
elif self.docstatus == 2:
status = "Cancelled"
frappe.db.set_value("Subcontracting Order", self.name, "status", status, update_modified)
if status:
frappe.db.set_value(
"Subcontracting Order", self.name, "status", status, update_modified=update_modified
)
@frappe.whitelist()

View File

@ -10,6 +10,7 @@ frappe.listview_settings['Subcontracting Order'] = {
"Completed": "green",
"Partial Material Transferred": "purple",
"Material Transferred": "blue",
"Closed": "red",
};
return [__(doc.status), status_colors[doc.status], "status,=," + doc.status];
},

View File

@ -7,7 +7,10 @@ import frappe
from frappe.tests.utils import FrappeTestCase
from erpnext.buying.doctype.purchase_order.purchase_order import get_mapped_subcontracting_order
from erpnext.controllers.subcontracting_controller import make_rm_stock_entry
from erpnext.controllers.subcontracting_controller import (
get_materials_from_supplier,
make_rm_stock_entry,
)
from erpnext.controllers.tests.test_subcontracting_controller import (
get_rm_items,
get_subcontracting_order,
@ -89,6 +92,16 @@ class TestSubcontractingOrder(FrappeTestCase):
sco.load_from_db()
self.assertEqual(sco.status, "Partially Received")
# Closed
ste = get_materials_from_supplier(sco.name, [d.name for d in sco.supplied_items])
ste.save()
ste.submit()
sco.load_from_db()
self.assertEqual(sco.status, "Closed")
ste.cancel()
sco.load_from_db()
self.assertEqual(sco.status, "Partially Received")
# Completed
scr = make_subcontracting_receipt(sco.name)
scr.save()

View File

@ -150,8 +150,7 @@
"label": "Returned Qty",
"no_copy": 1,
"print_hide": 1,
"read_only": 1,
"hidden": 1
"read_only": 1
},
{
"fieldname": "total_supplied_qty",
@ -166,7 +165,7 @@
"hide_toolbar": 1,
"istable": 1,
"links": [],
"modified": "2022-04-07 12:58:28.208847",
"modified": "2022-08-26 16:04:56.125951",
"modified_by": "Administrator",
"module": "Subcontracting",
"name": "Subcontracting Order Supplied Item",

View File

@ -369,7 +369,7 @@
"in_standard_filter": 1,
"label": "Status",
"no_copy": 1,
"options": "\nDraft\nCompleted\nReturn\nReturn Issued\nCancelled",
"options": "\nDraft\nCompleted\nReturn\nReturn Issued\nCancelled\nClosed",
"print_hide": 1,
"print_width": "150px",
"read_only": 1,
@ -628,7 +628,7 @@
"in_create": 1,
"is_submittable": 1,
"links": [],
"modified": "2022-08-22 17:30:40.827517",
"modified": "2022-08-26 21:02:26.353870",
"modified_by": "Administrator",
"module": "Subcontracting",
"name": "Subcontracting Receipt",