Beispiel #1
0
def get_bin_packing_details(delivery_note):
    """create 3D bin packing API JSON request and parse the JSON response"""
    try:
        # dn = frappe.get_doc("Delivery Note", delivery_note)
        dn = frappe.get_doc(json.loads(delivery_note))

        if dn.dn_status not in ["Draft","Partialy Packed"]:
            frappe.throw("Packing Slips are already created. Please Reload the Document")
        else:
            items_to_pack = get_items_to_pack(dn)
            to_pack = [item.get("id") for item in items_to_pack]

            # get unique box items to create packing slips
            items_with_unique_boxes = get_unique_box_items_to_pack(dn, to_pack)

            if items_to_pack:
                bins = get_bin_details()
                if not bins:
                    frappe.throw("No Bins Founds, Please check the stock")
                credentials = get_bin_packing_credentials()
                request = get_bin_packing_request(bins,items_to_pack,credentials,params)
                response = get_bin_packing_response(request)
                return get_packing_slip_details(delivery_note, response.get("response"), items_with_unique_boxes)
            elif items_with_unique_boxes:
                return get_packing_slip_details(delivery_note, None, items_with_unique_boxes)
            else:
                frappe.throw("No items found for bin packing process")
    except Exception, e:
        frappe.throw(e)
def get_bin_packing_details(delivery_note):
        """create 3D bin packing API JSON request and parse the JSON response"""
#    try:
        # dn = frappe.get_doc("Delivery Note", delivery_note)
        dn = frappe.get_doc(json.loads(delivery_note))
        delete_ps = []

        if dn.dn_status not in ["Draft","Partialy Packed", "Manual Partialy Packed", "Manual Packing Slips Created"]:
            frappe.throw("Packing Slips are already created. Please Reload the Document")
        else:
            if dn.dn_status in ["Draft", "Manual Partialy Packed", "Manual Packing Slips Created"]:
                if dn.packing_slip_details:
                    for ps in dn.packing_slip_details:
                        if ps.packing_slip :
                            delete_ps.append(ps)
                if delete_ps:
                    for chlid_row in delete_ps:
                        if chlid_row.packing_slip:
                            frappe.errprint(chlid_row.packing_slip)
                            frappe.db.sql("""update `tabPacking Slip` set docstatus = 2 where name = '%s' """%(chlid_row.packing_slip))
                            frappe.delete_doc("Packing Slip", chlid_row.packing_slip, force=True, ignore_permissions=True)
                        dn.remove(chlid_row)

            items_to_pack = get_items_to_pack(dn)
            to_pack = [item.get("id") for item in items_to_pack]

            # get unique box items to create packing slips
            items_with_unique_boxes = get_unique_box_items_to_pack(dn, to_pack)

            if items_to_pack:
                bins = get_bin_details()
                if not bins:
                    frappe.throw("No Bins Founds, Please check the stock")
                credentials = get_bin_packing_credentials()
                request = get_bin_packing_request(bins,items_to_pack,credentials,params)
                response = get_bin_packing_response(request)
                return get_packing_slip_details(delivery_note, response.get("response"), items_with_unique_boxes)
            elif items_with_unique_boxes:
                return get_packing_slip_details(delivery_note, None, items_with_unique_boxes)
            else:
                frappe.throw("No items found for bin packing process")

        dn.pack_manualy = 0
        dn.save(ignore_permissions = True)
        
        return "Packing Slips"
Beispiel #3
0
def get_bin_packing_details(delivery_note):
    """create 3D bin packing API JSON request and parse the JSON response"""
    #    try:
    # dn = frappe.get_doc("Delivery Note", delivery_note)
    dn = frappe.get_doc(json.loads(delivery_note))
    delete_ps = []

    if dn.dn_status not in [
            "Draft", "Partialy Packed", "Manual Partialy Packed",
            "Manual Packing Slips Created"
    ]:
        frappe.throw(
            "Packing Slips are already created. Please Reload the Document")
    else:
        if dn.dn_status in [
                "Draft", "Manual Partialy Packed",
                "Manual Packing Slips Created"
        ]:
            if dn.packing_slip_details:
                for ps in dn.packing_slip_details:
                    if ps.packing_slip:
                        delete_ps.append(ps)
            if delete_ps:
                for chlid_row in delete_ps:
                    if chlid_row.packing_slip:
                        frappe.errprint(chlid_row.packing_slip)
                        frappe.db.sql(
                            """update `tabPacking Slip` set docstatus = 2 where name = '%s' """
                            % (chlid_row.packing_slip))
                        frappe.delete_doc("Packing Slip",
                                          chlid_row.packing_slip,
                                          force=True,
                                          ignore_permissions=True)
                    dn.remove(chlid_row)

        items_to_pack = get_items_to_pack(dn)
        to_pack = [item.get("id") for item in items_to_pack]

        # get unique box items to create packing slips
        items_with_unique_boxes = get_unique_box_items_to_pack(dn, to_pack)

        if items_to_pack:
            bins = get_bin_details()
            if not bins:
                frappe.throw("No Bins Founds, Please check the stock")
            credentials = get_bin_packing_credentials()
            request = get_bin_packing_request(bins, items_to_pack, credentials,
                                              params)
            response = get_bin_packing_response(request)
            return get_packing_slip_details(delivery_note,
                                            response.get("response"),
                                            items_with_unique_boxes)
        elif items_with_unique_boxes:
            return get_packing_slip_details(delivery_note, None,
                                            items_with_unique_boxes)
        else:
            frappe.throw("No items found for bin packing process")

    dn.pack_manualy = 0
    dn.save(ignore_permissions=True)

    return "Packing Slips"