refactor(minor): use set_onload
to get unpacked items details
This commit is contained in:
parent
7742c592c5
commit
b0eb9ea7bd
@ -185,23 +185,7 @@ erpnext.stock.DeliveryNoteController = class DeliveryNoteController extends erpn
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(doc.docstatus==0 && !doc.__islocal) {
|
if(doc.docstatus==0 && !doc.__islocal) {
|
||||||
var remaining_qty = 0;
|
if (doc.__onload && doc.__onload.has_unpacked_items) {
|
||||||
|
|
||||||
doc.items.forEach(item => {
|
|
||||||
frappe.db.exists("Product Bundle", item.item_code).then(exists => {
|
|
||||||
if (!exists) {
|
|
||||||
remaining_qty += (item.qty - item.packed_qty);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!remaining_qty) {
|
|
||||||
doc.packed_items.forEach(item => {
|
|
||||||
remaining_qty += (item.qty - item.packed_qty);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (remaining_qty > 0) {
|
|
||||||
this.frm.add_custom_button(__('Packing Slip'), function() {
|
this.frm.add_custom_button(__('Packing Slip'), function() {
|
||||||
frappe.model.open_mapped_doc({
|
frappe.model.open_mapped_doc({
|
||||||
method: "erpnext.stock.doctype.delivery_note.delivery_note.make_packing_slip",
|
method: "erpnext.stock.doctype.delivery_note.delivery_note.make_packing_slip",
|
||||||
|
@ -86,6 +86,10 @@ class DeliveryNote(SellingController):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def onload(self):
|
||||||
|
if self.docstatus == 0:
|
||||||
|
self.set_onload("has_unpacked_items", self.has_unpacked_items())
|
||||||
|
|
||||||
def before_print(self, settings=None):
|
def before_print(self, settings=None):
|
||||||
def toggle_print_hide(meta, fieldname):
|
def toggle_print_hide(meta, fieldname):
|
||||||
df = meta.get_field(fieldname)
|
df = meta.get_field(fieldname)
|
||||||
@ -393,6 +397,20 @@ class DeliveryNote(SellingController):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def has_unpacked_items(self):
|
||||||
|
for item in self.items:
|
||||||
|
if (
|
||||||
|
not frappe.db.exists("Product Bundle", {"new_item_code": item.item_code})
|
||||||
|
and item.packed_qty < item.qty
|
||||||
|
):
|
||||||
|
return True
|
||||||
|
|
||||||
|
for item in self.packed_items:
|
||||||
|
if item.packed_qty < item.qty:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def update_billed_amount_based_on_so(so_detail, update_modified=True):
|
def update_billed_amount_based_on_so(so_detail, update_modified=True):
|
||||||
from frappe.query_builder.functions import Sum
|
from frappe.query_builder.functions import Sum
|
||||||
@ -711,9 +729,9 @@ def make_packing_slip(source_name, target_doc=None):
|
|||||||
"name": "dn_detail",
|
"name": "dn_detail",
|
||||||
},
|
},
|
||||||
"postprocess": update_item,
|
"postprocess": update_item,
|
||||||
"condition": lambda doc: (
|
"condition": lambda item: (
|
||||||
not frappe.db.exists("Product Bundle", {"new_item_code": doc.item_code})
|
not frappe.db.exists("Product Bundle", {"new_item_code": item.item_code})
|
||||||
and (doc.qty - doc.packed_qty) > 0
|
and item.packed_qty < item.qty
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
"Packed Item": {
|
"Packed Item": {
|
||||||
@ -727,7 +745,7 @@ def make_packing_slip(source_name, target_doc=None):
|
|||||||
"name": "pi_detail",
|
"name": "pi_detail",
|
||||||
},
|
},
|
||||||
"postprocess": update_item,
|
"postprocess": update_item,
|
||||||
"condition": lambda doc: ((doc.qty - doc.packed_qty) > 0),
|
"condition": lambda item: (item.packed_qty < item.qty),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
target_doc,
|
target_doc,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user