Skip to content

Commit

Permalink
feat: allow return of components for SCO that don't have SCR created …
Browse files Browse the repository at this point in the history
…(backport #37686) (#37693)

* feat: allow return of components for SCO that don't have SCR created

(cherry picked from commit 8e3b9ec)

* fix: consider returned qty while calculating unsupplied qty

(cherry picked from commit 3290df5)

---------

Co-authored-by: s-aga-r <[email protected]>
  • Loading branch information
mergify[bot] and s-aga-r authored Oct 26, 2023
1 parent 2f5d991 commit 4044325
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
28 changes: 24 additions & 4 deletions erpnext/stock/doctype/stock_entry/stock_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,14 +1014,34 @@ def validate_subcontract_order(self):
& (se.docstatus == 1)
& (se_detail.item_code == se_item.item_code)
& (
(se.purchase_order == self.purchase_order)
((se.purchase_order == self.purchase_order) & (se_detail.po_detail == se_item.po_detail))
if self.subcontract_data.order_doctype == "Purchase Order"
else (se.subcontracting_order == self.subcontracting_order)
else (
(se.subcontracting_order == self.subcontracting_order)
& (se_detail.sco_rm_detail == se_item.sco_rm_detail)
)
)
)
).run()[0][0]
).run()[0][0] or 0

total_returned = 0
if self.subcontract_data.order_doctype == "Subcontracting Order":
total_returned = (
frappe.qb.from_(se)
.inner_join(se_detail)
.on(se.name == se_detail.parent)
.select(Sum(se_detail.transfer_qty))
.where(
(se.purpose == "Material Transfer")
& (se.docstatus == 1)
& (se.is_return == 1)
& (se_detail.item_code == se_item.item_code)
& (se_detail.sco_rm_detail == se_item.sco_rm_detail)
& (se.subcontracting_order == self.subcontracting_order)
)
).run()[0][0] or 0

if flt(total_supplied, precision) > flt(total_allowed, precision):
if flt(total_supplied - total_returned, precision) > flt(total_allowed, precision):
frappe.throw(
_("Row {0}# Item {1} cannot be transferred more than {2} against {3} {4}").format(
se_item.idx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ frappe.ui.form.on('Subcontracting Order', {
get_materials_from_supplier: function (frm) {
let sco_rm_details = [];

if (frm.doc.status != "Closed" && frm.doc.supplied_items && frm.doc.per_received > 0) {
if (frm.doc.status != "Closed" && frm.doc.supplied_items) {
frm.doc.supplied_items.forEach(d => {
if (d.total_supplied_qty > 0 && d.total_supplied_qty != d.consumed_qty) {
sco_rm_details.push(d.name);
Expand Down Expand Up @@ -193,7 +193,7 @@ erpnext.buying.SubcontractingOrderController = class SubcontractingOrderControll
}

has_unsupplied_items() {
return this.frm.doc['supplied_items'].some(item => item.required_qty > item.supplied_qty);
return this.frm.doc['supplied_items'].some(item => item.required_qty > (item.supplied_qty - item.returned_qty));
}

make_subcontracting_receipt() {
Expand Down

0 comments on commit 4044325

Please sign in to comment.