refactor(Sales Invoice): convert to guard clause

This commit is contained in:
barredterra
2024-02-16 23:17:41 +01:00
parent cc83af0dd4
commit f99f7fd2cf

View File

@@ -591,43 +591,48 @@ class SalesInvoice(SellingController):
self.delete_auto_created_batches()
def update_status_updater_args(self):
if cint(self.update_stock):
self.status_updater.append(
{
"source_dt": "Sales Invoice Item",
"target_dt": "Sales Order Item",
"target_parent_dt": "Sales Order",
"target_parent_field": "per_delivered",
"target_field": "delivered_qty",
"target_ref_field": "qty",
"source_field": "qty",
"join_field": "so_detail",
"percent_join_field": "sales_order",
"status_field": "delivery_status",
"keyword": "Delivered",
"second_source_dt": "Delivery Note Item",
"second_source_field": "qty",
"second_join_field": "so_detail",
"overflow_type": "delivery",
"extra_cond": """ and exists(select name from `tabSales Invoice`
where name=`tabSales Invoice Item`.parent and update_stock = 1)""",
}
)
if cint(self.is_return):
self.status_updater.append(
{
"source_dt": "Sales Invoice Item",
"target_dt": "Sales Order Item",
"join_field": "so_detail",
"target_field": "returned_qty",
"target_parent_dt": "Sales Order",
"source_field": "-1 * qty",
"second_source_dt": "Delivery Note Item",
"second_source_field": "-1 * qty",
"second_join_field": "so_detail",
"extra_cond": """ and exists (select name from `tabSales Invoice` where name=`tabSales Invoice Item`.parent and update_stock=1 and is_return=1)""",
}
)
if not cint(self.update_stock):
return
self.status_updater.append(
{
"source_dt": "Sales Invoice Item",
"target_dt": "Sales Order Item",
"target_parent_dt": "Sales Order",
"target_parent_field": "per_delivered",
"target_field": "delivered_qty",
"target_ref_field": "qty",
"source_field": "qty",
"join_field": "so_detail",
"percent_join_field": "sales_order",
"status_field": "delivery_status",
"keyword": "Delivered",
"second_source_dt": "Delivery Note Item",
"second_source_field": "qty",
"second_join_field": "so_detail",
"overflow_type": "delivery",
"extra_cond": """ and exists(select name from `tabSales Invoice`
where name=`tabSales Invoice Item`.parent and update_stock = 1)""",
}
)
if not cint(self.is_return):
return
self.status_updater.append(
{
"source_dt": "Sales Invoice Item",
"target_dt": "Sales Order Item",
"join_field": "so_detail",
"target_field": "returned_qty",
"target_parent_dt": "Sales Order",
"source_field": "-1 * qty",
"second_source_dt": "Delivery Note Item",
"second_source_field": "-1 * qty",
"second_join_field": "so_detail",
"extra_cond": """ and exists (select name from `tabSales Invoice` where name=`tabSales Invoice Item`.parent and update_stock=1 and is_return=1)""",
}
)
def check_credit_limit(self):
from erpnext.selling.doctype.customer.customer import check_credit_limit