problem: if a whitelisted document method returns a falsy value like
`[]`, `{}`, `0` then response.message is not set and not returned
in the response.
this change checks if the return value is `None` and falsy values
are returned properly in the response
* [fix] Clarified docstatus transition exceptions
Exceptions issued by the document.py `check_docstatus_transition` method are potentially very misleading. In cases where an invalid docstatus is used, users receive an confusing exception stating "Cannot change docstatus from 0 to 2" or "Cannot change docstatus from 1 to 0".
This PR adds an additional exception message when an invalid docstatus is used.
* fix: Clarified docstatus transition exceptions
Added additional clarifications to exception messages
`Document.save` returns self but `submit` and `cancel` don't.
change:
For sake of consistency and better support for `run_method` via REST API, return the document.
ref: https://github.com/frappe/frappe/issues/14869
The calendar week is based on ISO 8601 but behaves slightly different
for the first and last days of a year to ensure consecutiveness:
* If the first days of a year would be in week 53 then 00 is used
instead.
* if the last days of a year would be in week 01 then 53 is used
instead.
Closes#14413
* Revert "feat(minor): Implement __getitem__ in Base Document (#14855)"
This reverts commit 583a7ef23923d362c85beeabe57703c2d5b12a65.
(cherry picked from commit d165fb3d477e65f7a395118f69278f2cb5c7f4e5)
* fix: keyerror in auto email report
(cherry picked from commit aac20f5d159875a5f3c9b4a6d74beec390e617dd)
Co-authored-by: Ankush Menat <ankush@frappe.io>
* feat(minor): Implement __getitem__ in Base Document
This addition allows for syntactic sugars like writing doc["name"] to
access document name. This addition is solely for the sake of code
simplicity. Since dictionaries in Python follow this standard, we can
write code that works for both Vanilla Dicts, Frappe Dicts & all
Document objects
* fix: Use getattr over get in getitem
For the sake of consistency and some level of sanity in the universe.
Co-authored-by: Ankush Menat <ankush@frappe.io>
* fix: Raise KeyError instead of AttributeError
why: shit breaks down. Specifically stuff in Jinja templates, attributes
that are conditional. Either this is acceptable or subscripting objects
cannot and probably should not be possible along with our pre-condiitons
* chore: Use hasattr instead of get default
Couldn't decide between a style commit or a chore
Co-authored-by: Ankush Menat <ankush@frappe.io>
(cherry picked from commit 583a7ef23923d362c85beeabe57703c2d5b12a65)
Co-authored-by: gavin <gavin18d@gmail.com>