mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-25 07:54:46 +00:00
chore: refactor set status into a getter & setter (future perf)
This commit is contained in:
@@ -181,45 +181,65 @@ class StatusUpdater(Document):
|
|||||||
self.status = "Draft"
|
self.status = "Draft"
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.doctype in status_map:
|
if self.doctype not in status_map:
|
||||||
_status = self.status
|
return
|
||||||
if status and update:
|
_status = self.status
|
||||||
self.db_set("status", status)
|
# TODO: revise accidential complexity where update has a double meaning, see below
|
||||||
|
self.status = status if status else self.status
|
||||||
|
new_status = self.get_status()["status"]
|
||||||
|
|
||||||
sl = status_map[self.doctype][:]
|
if new_status != _status:
|
||||||
sl.reverse()
|
if new_status not in ("Cancelled", "Partially Ordered", "Ordered", "Issued", "Transferred"):
|
||||||
for s in sl:
|
self.add_comment("Label", _(new_status))
|
||||||
if not s[1]:
|
|
||||||
self.status = s[0]
|
|
||||||
break
|
|
||||||
elif s[1].startswith("eval:"):
|
|
||||||
if frappe.safe_eval(
|
|
||||||
s[1][5:],
|
|
||||||
None,
|
|
||||||
{
|
|
||||||
"self": self.as_dict(),
|
|
||||||
"getdate": getdate,
|
|
||||||
"nowdate": nowdate,
|
|
||||||
"get_value": frappe.db.get_value,
|
|
||||||
},
|
|
||||||
):
|
|
||||||
self.status = s[0]
|
|
||||||
break
|
|
||||||
elif getattr(self, s[1])():
|
|
||||||
self.status = s[0]
|
|
||||||
break
|
|
||||||
|
|
||||||
if self.status != _status and self.status not in (
|
|
||||||
"Cancelled",
|
|
||||||
"Partially Ordered",
|
|
||||||
"Ordered",
|
|
||||||
"Issued",
|
|
||||||
"Transferred",
|
|
||||||
):
|
|
||||||
self.add_comment("Label", _(self.status))
|
|
||||||
|
|
||||||
|
self.status = new_status
|
||||||
if update:
|
if update:
|
||||||
self.db_set("status", self.status, update_modified=update_modified)
|
self.db_set("status", new_status, update_modified=update_modified)
|
||||||
|
|
||||||
|
def get_status(self):
|
||||||
|
"""
|
||||||
|
Get the status of the document.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: A dictionary containing the status. This allows callers to receive
|
||||||
|
a dictionary for efficient bulk updates, for example when `per_billed`
|
||||||
|
and other status fields also need to be updated.
|
||||||
|
|
||||||
|
Note:
|
||||||
|
Can be overriden on a doctype to implement more localized status updater logic.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
{
|
||||||
|
"status": "Draft",
|
||||||
|
"per_billed": 50,
|
||||||
|
"billing_status": "Partly Billed"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
if self.doctype not in status_map:
|
||||||
|
return {"status": self.status}
|
||||||
|
|
||||||
|
sl = status_map[self.doctype][:]
|
||||||
|
sl.reverse()
|
||||||
|
|
||||||
|
for s in sl:
|
||||||
|
if not s[1]:
|
||||||
|
return {"status": s[0]}
|
||||||
|
elif s[1].startswith("eval:"):
|
||||||
|
if frappe.safe_eval(
|
||||||
|
s[1][5:],
|
||||||
|
None,
|
||||||
|
{
|
||||||
|
"self": self.as_dict(),
|
||||||
|
"getdate": getdate,
|
||||||
|
"nowdate": nowdate,
|
||||||
|
"get_value": frappe.db.get_value,
|
||||||
|
},
|
||||||
|
):
|
||||||
|
return {"status": s[0]}
|
||||||
|
elif getattr(self, s[1])():
|
||||||
|
return {"status": s[0]}
|
||||||
|
|
||||||
|
return {"status": self.status}
|
||||||
|
|
||||||
def validate_qty(self):
|
def validate_qty(self):
|
||||||
"""Validates qty at row level"""
|
"""Validates qty at row level"""
|
||||||
|
|||||||
Reference in New Issue
Block a user