Skip to content

Commit

Permalink
fix:validations on pick_list and sales_invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
sonali8848 committed May 12, 2023
1 parent b54393e commit d25b3aa
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 89 deletions.
2 changes: 1 addition & 1 deletion ecommerce_integrations/unicommerce/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
SHIPPING_PACKAGE_STATUS_FIELD = "unicommerce_shipping_package_status"
IS_COD_CHECKBOX = "unicommerce_is_cod"
SHIPPING_METHOD_FIELD = "unicommerce_shipping_method"
ORDER_DETAILS = "order_details"
PICKLIST_ORDER_DETAILS_FIELD = "order_details"

GRN_STOCK_ENTRY_TYPE = "GRN on Unicommerce"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
ITEM_WIDTH_FIELD,
MANIFEST_GENERATED_CHECK,
ORDER_CODE_FIELD,
ORDER_DETAILS,
ORDER_INVOICE_STATUS_FIELD,
ORDER_ITEM_BATCH_NO,
ORDER_ITEM_CODE_FIELD,
ORDER_STATUS_FIELD,
PACKAGE_TYPE_FIELD,
PICKLIST_ORDER_DETAILS_FIELD,
PRODUCT_CATEGORY_FIELD,
RETURN_CODE_FIELD,
SHIPPING_METHOD_FIELD,
Expand Down Expand Up @@ -430,10 +430,9 @@ def setup_custom_fields(update=True):
],
"Pick List": [
dict(
fieldname=ORDER_DETAILS,
fieldname=PICKLIST_ORDER_DETAILS_FIELD,
label="Order Details",
fieldtype="Table",
insert_after="section_break_15",
options="Pick List Sales Order Details",
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"column_break_2",
"return_warehouse",
"company_address",
"dispatch_address",
"shelf_wise"
"dispatch_address"
],
"fields": [
{
Expand Down Expand Up @@ -58,18 +57,12 @@
"fieldtype": "Link",
"label": "Dispatch Address",
"options": "Address"
},
{
"default": "0",
"fieldname": "shelf_wise",
"fieldtype": "Check",
"label": "Shelf Wise"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2023-04-20 15:43:11.040252",
"modified": "2023-05-12 14:06:13.182121",
"modified_by": "Administrator",
"module": "unicommerce",
"name": "Unicommerce Warehouses",
Expand Down
71 changes: 38 additions & 33 deletions ecommerce_integrations/unicommerce/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,43 +574,48 @@ def update_cancellation_status(so_data, so) -> bool:

def on_submit(self, method=None):
sales_order = self.get("items")[0].sales_order
attached_docs = frappe.get_all(
"File",
fields=["file_name"],
filters={"attached_to_name": self.name, "file_name": ("like", "unicommerce%")},
order_by="file_name",
)
url = frappe.get_all(
"File",
fields=["file_url"],
filters={"attached_to_name": self.name, "file_name": ("like", "unicommerce%")},
order_by="file_name",
)
pi_so = frappe.get_all(
"Pick List Sales Order Details",
fields=["name", "parent"],
filters=[{"sales_order": sales_order, "docstatus": 0}],
)
for pl in pi_so:
if not pl.parent or not frappe.db.exists("Pick List", pl.parent):
continue
if attached_docs:
frappe.db.set_value(
"Pick List Sales Order Details",
pl.name,
{
"sales_invoice": self.name,
"invoice_url": attached_docs[0].file_name,
"invoice_pdf": url[0].file_url,
},
)
else:
frappe.db.set_value("Pick List Sales Order Details", pl.name, {"sales_invoice": self.name})
unicommerce_order_code = frappe.db.get_value("Sales Order", sales_order, "unicommerce_order_code")
if unicommerce_order_code:
attached_docs = frappe.get_all(
"File",
fields=["file_name"],
filters={"attached_to_name": self.name, "file_name": ("like", "unicommerce%")},
order_by="file_name",
)
url = frappe.get_all(
"File",
fields=["file_url"],
filters={"attached_to_name": self.name, "file_name": ("like", "unicommerce%")},
order_by="file_name",
)
pi_so = frappe.get_all(
"Pick List Sales Order Details",
fields=["name", "parent"],
filters=[{"sales_order": sales_order, "docstatus": 0}],
)
for pl in pi_so:
if not pl.parent or not frappe.db.exists("Pick List", pl.parent):
continue
if attached_docs:
frappe.db.set_value(
"Pick List Sales Order Details",
pl.name,
{
"sales_invoice": self.name,
"invoice_url": attached_docs[0].file_name,
"invoice_pdf": url[0].file_url,
},
)
else:
frappe.db.set_value("Pick List Sales Order Details", pl.name, {"sales_invoice": self.name})


def on_cancel(self, method=None):
results = frappe.db.get_all(
"Pick List Sales Order Details", filters={"sales_invoice": self.name, "docstatus": 1}
)
if results:
self.flags.ignore_links = True
# self.flags.ignore_links = True
ignored_doctypes = list(self.get("ignore_linked_doctypes", []))
ignored_doctypes.append("Pick List")
self.ignore_linked_doctypes = ignored_doctypes
89 changes: 46 additions & 43 deletions ecommerce_integrations/unicommerce/pick_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,51 @@


def validate(self, method=None):
if self.get("locations"):
for pl in self.get("locations"):
if pl.picked_qty and float(pl.picked_qty) > 0:
if pl.picked_qty > pl.qty:
pl.picked_qty = pl.qty
sales_order = self.get("locations")[0].sales_order
unicommerce_order_code = frappe.db.get_value("Sales Order", sales_order, "unicommerce_order_code")
if unicommerce_order_code:
if self.get("locations"):
for pl in self.get("locations"):
if pl.picked_qty and float(pl.picked_qty) > 0:
if pl.picked_qty > pl.qty:
pl.picked_qty = pl.qty

frappe.throw(_("Row {0} Picked Qty cannot be more than Sales Order Qty").format(pl.idx))
if pl.picked_qty == 0 and pl.docstatus == 1:
frappe.throw(
_("You have not picked {0} in row {1} . Pick the item to proceed!").format(
pl.item_code, pl.idx
frappe.throw(_("Row {0} Picked Qty cannot be more than Sales Order Qty").format(pl.idx))
if pl.picked_qty == 0 and pl.docstatus == 1:
frappe.throw(
_("You have not picked {0} in row {1} . Pick the item to proceed!").format(
pl.item_code, pl.idx
)
)
)
item_so_list = [d.sales_order for d in self.get("locations")]
unique_so_list = []
for i in item_so_list:
if i not in unique_so_list:
unique_so_list.append(i)
so_list = [d.sales_order for d in self.get("order_details")]
for so in unique_so_list:
if so not in so_list:
pl_so_child = self.append("order_details", {})
pl_so_child.sales_order = so
total_item_count = 0
fully_picked_item_count = 0
partial_picked_item_count = 0
for item in self.get("locations"):
if item.sales_order == so:
total_item_count = total_item_count + 1
if item.picked_qty == item.qty:
fully_picked_item_count = fully_picked_item_count + 1
elif int(item.picked_qty) > 0:
partial_picked_item_count = partial_picked_item_count + 1
if fully_picked_item_count == total_item_count:
for x in self.get("order_details"):
if x.sales_order == so:
x.pick_status = "Fully Picked"
elif fully_picked_item_count == 0 and partial_picked_item_count == 0:
for x in self.get("order_details"):
if x.sales_order == so:
x.pick_status = ""
elif int(partial_picked_item_count) > 0:
for x in self.get("order_details"):
if x.sales_order == so:
x.pick_status = "Partially Picked"
item_so_list = [d.sales_order for d in self.get("locations")]
unique_so_list = []
for i in item_so_list:
if i not in unique_so_list:
unique_so_list.append(i)
so_list = [d.sales_order for d in self.get("order_details")]
for so in unique_so_list:
if so not in so_list:
pl_so_child = self.append("order_details", {})
pl_so_child.sales_order = so
total_item_count = 0
fully_picked_item_count = 0
partial_picked_item_count = 0
for item in self.get("locations"):
if item.sales_order == so:
total_item_count = total_item_count + 1
if item.picked_qty == item.qty:
fully_picked_item_count = fully_picked_item_count + 1
elif int(item.picked_qty) > 0:
partial_picked_item_count = partial_picked_item_count + 1
if fully_picked_item_count == total_item_count:
for x in self.get("order_details"):
if x.sales_order == so:
x.pick_status = "Fully Picked"
elif fully_picked_item_count == 0 and partial_picked_item_count == 0:
for x in self.get("order_details"):
if x.sales_order == so:
x.pick_status = ""
elif int(partial_picked_item_count) > 0:
for x in self.get("order_details"):
if x.sales_order == so:
x.pick_status = "Partially Picked"

0 comments on commit d25b3aa

Please sign in to comment.