Merge branch 'develop' into breadcrumb-fix
This commit is contained in:
commit
cecb89bde3
6 changed files with 44 additions and 15 deletions
|
|
@ -91,7 +91,7 @@ def validate_args(data):
|
|||
def validate_fields(data):
|
||||
wildcard = update_wildcard_field_param(data)
|
||||
|
||||
for field in data.fields or []:
|
||||
for field in list(data.fields or []):
|
||||
fieldname = extract_fieldname(field)
|
||||
if is_standard(fieldname):
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -142,9 +142,14 @@ class Document(BaseDocument):
|
|||
self._fix_numeric_types()
|
||||
|
||||
else:
|
||||
get_value_kwargs = {"for_update": self.flags.for_update, "as_dict": True}
|
||||
if not isinstance(self.name, (dict, list)):
|
||||
get_value_kwargs["order_by"] = None
|
||||
|
||||
d = frappe.db.get_value(
|
||||
self.doctype, self.name, "*", as_dict=1, for_update=self.flags.for_update
|
||||
doctype=self.doctype, filters=self.name, fieldname="*", **get_value_kwargs
|
||||
)
|
||||
|
||||
if not d:
|
||||
frappe.throw(
|
||||
_("{0} {1} not found").format(_(self.doctype), self.name), frappe.DoesNotExistError
|
||||
|
|
|
|||
|
|
@ -1,12 +1,17 @@
|
|||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: MIT. See LICENSE
|
||||
import json
|
||||
from typing import TYPE_CHECKING, Union
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.model.docstatus import DocStatus
|
||||
from frappe.utils import cint
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from frappe.model.document import Document
|
||||
from frappe.workflow.doctype.workflow.workflow import Workflow
|
||||
|
||||
|
||||
class WorkflowStateError(frappe.ValidationError):
|
||||
pass
|
||||
|
|
@ -32,20 +37,22 @@ def get_workflow_name(doctype):
|
|||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_transitions(doc, workflow=None, raise_exception=False):
|
||||
def get_transitions(
|
||||
doc: Union["Document", str, dict], workflow: "Workflow" = None, raise_exception: bool = False
|
||||
) -> list[dict]:
|
||||
"""Return list of possible transitions for the given doc"""
|
||||
doc = frappe.get_doc(frappe.parse_json(doc))
|
||||
from frappe.model.document import Document
|
||||
|
||||
if not isinstance(doc, Document):
|
||||
doc = frappe.get_doc(frappe.parse_json(doc))
|
||||
doc.load_from_db()
|
||||
|
||||
if doc.is_new():
|
||||
return []
|
||||
|
||||
doc.load_from_db()
|
||||
doc.check_permission("read")
|
||||
|
||||
frappe.has_permission(doc, "read", throw=True)
|
||||
roles = frappe.get_roles()
|
||||
|
||||
if not workflow:
|
||||
workflow = get_workflow(doc.doctype)
|
||||
workflow = workflow or get_workflow(doc.doctype)
|
||||
current_state = doc.get(workflow.workflow_state_field)
|
||||
|
||||
if not current_state:
|
||||
|
|
@ -55,11 +62,14 @@ def get_transitions(doc, workflow=None, raise_exception=False):
|
|||
frappe.throw(_("Workflow State not set"), WorkflowStateError)
|
||||
|
||||
transitions = []
|
||||
roles = frappe.get_roles()
|
||||
|
||||
for transition in workflow.transitions:
|
||||
if transition.state == current_state and transition.allowed in roles:
|
||||
if not is_transition_condition_satisfied(transition, doc):
|
||||
continue
|
||||
transitions.append(transition.as_dict())
|
||||
|
||||
return transitions
|
||||
|
||||
|
||||
|
|
@ -79,7 +89,7 @@ def get_workflow_safe_globals():
|
|||
)
|
||||
|
||||
|
||||
def is_transition_condition_satisfied(transition, doc):
|
||||
def is_transition_condition_satisfied(transition, doc) -> bool:
|
||||
if not transition.condition:
|
||||
return True
|
||||
else:
|
||||
|
|
@ -198,7 +208,7 @@ def validate_workflow(doc):
|
|||
)
|
||||
|
||||
|
||||
def get_workflow(doctype):
|
||||
def get_workflow(doctype) -> "Workflow":
|
||||
return frappe.get_doc("Workflow", get_workflow_name(doctype))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -327,13 +327,14 @@ frappe.ui.Page = class Page {
|
|||
|
||||
//--- Menu --//
|
||||
|
||||
add_menu_item(label, click, standard, shortcut) {
|
||||
add_menu_item(label, click, standard, shortcut, show_parent) {
|
||||
return this.add_dropdown_item({
|
||||
label,
|
||||
click,
|
||||
standard,
|
||||
parent: this.menu,
|
||||
shortcut,
|
||||
show_parent,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -424,7 +425,7 @@ frappe.ui.Page = class Page {
|
|||
icon = null,
|
||||
}) {
|
||||
if (show_parent) {
|
||||
parent.parent().removeClass("hide");
|
||||
parent.parent().removeClass("hide hidden-xl");
|
||||
}
|
||||
|
||||
let $link = this.is_in_group_button_dropdown(parent, "li > a.grey-link > span", label);
|
||||
|
|
@ -602,8 +603,11 @@ frappe.ui.Page = class Page {
|
|||
};
|
||||
// Add actions as menu item in Mobile View
|
||||
let menu_item_label = group ? `${group} > ${label}` : label;
|
||||
let menu_item = this.add_menu_item(menu_item_label, _action, false);
|
||||
let menu_item = this.add_menu_item(menu_item_label, _action, false, false, false);
|
||||
menu_item.parent().addClass("hidden-xl");
|
||||
if (this.menu_btn_group.hasClass("hide")) {
|
||||
this.menu_btn_group.removeClass("hide").addClass("hidden-xl");
|
||||
}
|
||||
|
||||
if (group) {
|
||||
var $group = this.get_or_add_inner_group_button(group);
|
||||
|
|
|
|||
|
|
@ -493,6 +493,10 @@ class TestDateUtils(FrappeTestCase):
|
|||
frappe.utils.get_last_day_of_week("2020-12-28"), frappe.utils.getdate("2021-01-02")
|
||||
)
|
||||
|
||||
def test_is_last_day_of_the_month(self):
|
||||
self.assertEqual(frappe.utils.is_last_day_of_the_month("2020-12-24"), False)
|
||||
self.assertEqual(frappe.utils.is_last_day_of_the_month("2020-12-31"), True)
|
||||
|
||||
def test_get_time(self):
|
||||
datetime_input = now_datetime()
|
||||
timedelta_input = get_timedelta()
|
||||
|
|
|
|||
|
|
@ -471,6 +471,12 @@ def get_last_day(dt):
|
|||
return get_first_day(dt, 0, 1) + datetime.timedelta(-1)
|
||||
|
||||
|
||||
def is_last_day_of_the_month(dt):
|
||||
last_day_of_the_month = get_last_day(dt)
|
||||
|
||||
return getdate(dt) == getdate(last_day_of_the_month)
|
||||
|
||||
|
||||
def get_quarter_ending(date):
|
||||
date = getdate(date)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue