feat: Add Option to assign documents to users
Added a option to create separate documents for each users and assign document based on the setting
This commit is contained in:
parent
85730ee460
commit
97bcfa2849
2 changed files with 57 additions and 9 deletions
|
|
@ -21,6 +21,9 @@
|
|||
"repeat_on_last_day",
|
||||
"column_break_12",
|
||||
"next_schedule_date",
|
||||
"section_break_looa",
|
||||
"generate_separate_documents_for_each_assignee",
|
||||
"assignee",
|
||||
"section_break_16",
|
||||
"repeat_on_days",
|
||||
"notification",
|
||||
|
|
@ -86,7 +89,7 @@
|
|||
"fieldtype": "Select",
|
||||
"in_list_view": 1,
|
||||
"label": "Frequency",
|
||||
"options": "\nDaily\nWeekly\nMonthly\nQuarterly\nHalf-yearly\nYearly",
|
||||
"options": "\nDaily\nWeekly\nFortnightly\nMonthly\nQuarterly\nHalf-yearly\nYearly",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
|
|
@ -198,10 +201,26 @@
|
|||
"depends_on": "eval:doc.frequency==='Weekly';",
|
||||
"fieldname": "section_break_16",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "generate_separate_documents_for_each_assignee",
|
||||
"fieldtype": "Check",
|
||||
"label": "Generate Separate Documents For Each Assignee"
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_looa",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "assignee",
|
||||
"fieldtype": "Table MultiSelect",
|
||||
"label": "Assignee",
|
||||
"options": "Auto Repeat User"
|
||||
}
|
||||
],
|
||||
"links": [],
|
||||
"modified": "2025-01-20 14:15:55.287788",
|
||||
"modified": "2025-06-09 18:20:23.775881",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Automation",
|
||||
"name": "Auto Repeat",
|
||||
|
|
@ -245,10 +264,11 @@
|
|||
"write": 1
|
||||
}
|
||||
],
|
||||
"row_format": "Dynamic",
|
||||
"search_fields": "reference_document",
|
||||
"sort_field": "creation",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"title_field": "reference_document",
|
||||
"track_changes": 1
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ from frappe.contacts.doctype.contact.contact import (
|
|||
get_contacts_linking_to,
|
||||
)
|
||||
from frappe.core.doctype.communication.email import make
|
||||
from frappe.desk.form import assign_to
|
||||
from frappe.desk.form.assign_to import add as assign_to
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils import (
|
||||
add_days,
|
||||
|
|
@ -49,11 +49,16 @@ class AutoRepeat(Document):
|
|||
|
||||
if TYPE_CHECKING:
|
||||
from frappe.automation.doctype.auto_repeat_day.auto_repeat_day import AutoRepeatDay
|
||||
from frappe.automation.doctype.auto_repeat_user.auto_repeat_user import AutoRepeatUser
|
||||
from frappe.types import DF
|
||||
|
||||
assignee: DF.TableMultiSelect[AutoRepeatUser]
|
||||
disabled: DF.Check
|
||||
end_date: DF.Date | None
|
||||
frequency: DF.Literal["", "Daily", "Weekly", "Monthly", "Quarterly", "Half-yearly", "Yearly"]
|
||||
frequency: DF.Literal[
|
||||
"", "Daily", "Weekly", "Fortnightly", "Monthly", "Quarterly", "Half-yearly", "Yearly"
|
||||
]
|
||||
generate_separate_documents_for_each_assignee: DF.Check
|
||||
message: DF.Text | None
|
||||
next_schedule_date: DF.Date | None
|
||||
notify_by_email: DF.Check
|
||||
|
|
@ -219,9 +224,16 @@ class AutoRepeat(Document):
|
|||
|
||||
def create_documents(self):
|
||||
try:
|
||||
new_doc = self.make_new_document()
|
||||
if self.generate_separate_documents_for_each_assignee and self.assignee:
|
||||
new_docs = self.make_new_documents()
|
||||
else:
|
||||
new_docs = self.make_new_document([assignee.user for assignee in self.assignee])
|
||||
if self.notify_by_email and self.recipients:
|
||||
self.send_notification(new_doc)
|
||||
if isinstance(new_docs, list):
|
||||
for new_doc in new_docs:
|
||||
self.send_notification(new_doc)
|
||||
else:
|
||||
self.send_notification(new_doc)
|
||||
except Exception:
|
||||
error_log = self.log_error(
|
||||
_("Auto repeat failed. Please enable auto repeat after fixing the issues.")
|
||||
|
|
@ -232,7 +244,14 @@ class AutoRepeat(Document):
|
|||
if self.reference_document and not frappe.in_test:
|
||||
self.notify_error_to_user(error_log)
|
||||
|
||||
def make_new_document(self):
|
||||
def make_new_documents(self):
|
||||
docs = []
|
||||
for assignee in self.assignee:
|
||||
new_doc = self.make_new_document(assignee=[assignee.user])
|
||||
docs.append(new_doc)
|
||||
return docs
|
||||
|
||||
def make_new_document(self, assignee=None):
|
||||
reference_doc = frappe.get_doc(self.reference_doctype, self.reference_document)
|
||||
new_doc = frappe.copy_doc(reference_doc, ignore_no_copy=False)
|
||||
self.update_doc(new_doc, reference_doc)
|
||||
|
|
@ -242,7 +261,14 @@ class AutoRepeat(Document):
|
|||
"label": _("via Auto Repeat"),
|
||||
}
|
||||
new_doc.insert(ignore_permissions=True)
|
||||
|
||||
if assignee:
|
||||
args = {
|
||||
"assign_to": assignee,
|
||||
"doctype": self.reference_doctype,
|
||||
"name": new_doc.name,
|
||||
"description": new_doc.get_title(),
|
||||
}
|
||||
assign_to(args=args)
|
||||
if self.submit_on_creation:
|
||||
new_doc.submit()
|
||||
|
||||
|
|
@ -348,6 +374,8 @@ class AutoRepeat(Document):
|
|||
def get_days(self, schedule_date):
|
||||
if self.frequency == "Weekly":
|
||||
days = self.get_offset_for_weekly_frequency(schedule_date)
|
||||
elif self.frequency == "Fortnightly":
|
||||
days = 14
|
||||
else:
|
||||
# daily frequency
|
||||
days = 1
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue