Skip to content

Commit

Permalink
feat: voided check
Browse files Browse the repository at this point in the history
  • Loading branch information
fproldan committed Jan 5, 2024
1 parent a9e3e8b commit e03e0f3
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 3 deletions.
175 changes: 175 additions & 0 deletions check_run/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,179 @@ def load_customizations():
property_setter.insert()


def add_workflow_for_voided_check():

workflow_actions = [
{
"docstatus": 0,
"doctype": "Workflow Action Master",
"name": "Submit",
"workflow_action_name": "Submit"
},
{
"docstatus": 0,
"doctype": "Workflow Action Master",
"name": "Void",
"workflow_action_name": "Void"
},
{
"docstatus": 0,
"doctype": "Workflow Action Master",
"name": "Cancel",
"workflow_action_name": "Cancel"
},
{
"docstatus": 0,
"doctype": "Workflow Action Master",
"name": "Save",
"workflow_action_name": "Save"
},
]

for action in workflow_actions:
if not frappe.db.exists("Workflow Action Master", action['name']):
act = frappe.new_doc("Workflow Action Master")
act.update(action)
act.insert()

workflow_states = [
{
"docstatus": 0,
"icon": "",
"name": "Submitted",
"style": "Primary",
"workflow_state_name": "Submitted"
},
{
"docstatus": 0,
"icon": "",
"name": "Voided",
"style": "Info",
"workflow_state_name": "Voided"
},
{
"docstatus": 0,
"doctype": "Workflow State",
"icon": "",
"name": "Cancelled",
"style": "Inverse",
"workflow_state_name": "Cancelled"
},
{
"docstatus": 0,
"doctype": "Workflow State",
"icon": "",
"name": "Draft",
"style": "Warning",
"workflow_state_name": "Draft"
},
]

for state in workflow_states:
if not frappe.db.exists("Workflow State", state['name']):
ws = frappe.new_doc("Workflow State")
ws.update(state)
ws.insert()

workflow_data = {
"docstatus": 0,
"doctype": "Workflow",
"document_type": "Payment Entry",
"is_active": 0,
"name": "Payment Entry",
"override_status": 1,
"send_email_alert": 0,
"states": [
{
"allow_edit": "Accounts User",
"doc_status": "0",
"is_optional_state": 0,
"parent": "Payment Entry",
"parentfield": "states",
"parenttype": "Workflow",
"state": "Draft",
},
{
"allow_edit": "Accounts User",
"doc_status": "1",
"is_optional_state": 0,
"parent": "Payment Entry",
"parentfield": "states",
"parenttype": "Workflow",
"state": "Submitted",
},
{
"allow_edit": "Accounts User",
"doc_status": "2",
"is_optional_state": 0,
"parent": "Payment Entry",
"parentfield": "states",
"parenttype": "Workflow",
"state": "Cancelled",
},
{
"allow_edit": "Accounts User",
"doc_status": "2",
"is_optional_state": 0,
"parent": "Payment Entry",
"parentfield": "states",
"parenttype": "Workflow",
"state": "Voided",
"update_field": "status",
"update_value": "Voided"
}
],
"transitions": [
{
"action": "Save",
"allow_self_approval": 1,
"allowed": "Accounts User",
"next_state": "Draft",
"parent": "Payment Entry",
"parentfield": "transitions",
"parenttype": "Workflow",
"state": "Draft"
},
{
"action": "Submit",
"allow_self_approval": 1,
"allowed": "Accounts User",
"next_state": "Submitted",
"parent": "Payment Entry",
"parentfield": "transitions",
"parenttype": "Workflow",
"state": "Draft"
},
{
"action": "Cancel",
"allow_self_approval": 1,
"allowed": "Accounts User",
"next_state": "Cancelled",
"parent": "Payment Entry",
"parentfield": "transitions",
"parenttype": "Workflow",
"state": "Submitted"
},
{
"action": "Void",
"allow_self_approval": 1,
"allowed": "Accounts User",
"next_state": "Voided",
"parent": "Payment Entry",
"parentfield": "transitions",
"parenttype": "Workflow",
"state": "Submitted"
}
],
"workflow_name": "Payment Entry",
"workflow_state_field": "status"
}
if not frappe.db.exists("Workflow", workflow_data['workflow_name']):
workflow = frappe.new_doc("Workflow")
workflow.update(workflow_data)
workflow.insert()


def after_install():
if not frappe.db.exists("File", "Home/Check Run"):
try:
Expand All @@ -52,3 +225,5 @@ def after_install():
cr_folder.save()
except Exception as e:
pass

add_workflow_for_voided_check()
9 changes: 7 additions & 2 deletions check_run/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
"Payment Entry": "public/js/custom/payment_entry_custom.js",
"Supplier": "public/js/custom/supplier_custom.js",
}
# doctype_list_js = {"doctype" : "public/js/doctype_list.js"}
doctype_list_js = {
'Payment Entry': 'public/js/custom/payment_entry_list.js',
}
# doctype_tree_js = {"doctype" : "public/js/doctype_tree.js"}
# doctype_calendar_js = {"doctype" : "public/js/doctype_calendar.js"}

Expand Down Expand Up @@ -95,7 +97,10 @@
# DocType Class
# ---------------
# Override standard doctype classes
# override_doctype_class = {"Bank": "check_run.overrides.bank.CustomBank"}
override_doctype_class = {
# "Bank": "check_run.overrides.bank.CustomBank",
'Payment Entry': 'check_run.overrides.payment_entry.CustomPaymentEntry',
}

# Document Events
# ---------------
Expand Down
36 changes: 36 additions & 0 deletions check_run/overrides/payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,42 @@

import frappe
from erpnext.accounts.doctype.payment_entry.payment_entry import PaymentEntry
from erpnext.accounts.general_ledger import make_gl_entries, process_gl_map
from frappe.utils.data import getdate


class CustomPaymentEntry(PaymentEntry):
def make_gl_entries(self, cancel=0, adv_adj=0):
if self.payment_type in ("Receive", "Pay") and not self.get("party_account_field"):
self.setup_party_account_field()

if self.status == 'Voided':
original_posting_date = self.posting_date
self.voided_date = self.posting_date = getdate()

gl_entries = []
self.add_party_gl_entries(gl_entries)
self.add_bank_gl_entries(gl_entries)
self.add_deductions_gl_entries(gl_entries)
self.add_tax_gl_entries(gl_entries)

gl_entries = process_gl_map(gl_entries)
make_gl_entries(gl_entries, cancel=cancel, adv_adj=adv_adj)

if self.status == 'Voided':
self.posting_date = original_posting_date

def set_status(self):
if self.status == "Voided":
pass
elif self.docstatus == 2:
self.status = "Cancelled"
elif self.docstatus == 1:
self.status = "Submitted"
else:
self.status = "Draft"

self.db_set("status", self.status, update_modified=True)


@frappe.whitelist()
Expand Down
3 changes: 2 additions & 1 deletion check_run/patches.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
check_run.patches.patch_payment_schedule # 12/19/23
check_run.patches.patch_payment_schedule # 12/19/23
check_run.patches.patch_voided_check_workflow # 01/05/24
6 changes: 6 additions & 0 deletions check_run/patches/patch_voided_check_workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import frappe
from check_run.customize import add_workflow_for_voided_check


def execute():
add_workflow_for_voided_check()
17 changes: 17 additions & 0 deletions check_run/public/js/custom/payment_entry_list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

frappe.listview_settings['Payment Entry'] = {
has_indicator_for_draft: 1,
has_indicator_for_cancelled: 1,
get_indicator: function (doc) {
if (doc.status) {
return [__(doc.status), {
"Draft": "orange",
"Submitted": "green",
"Cancelled": "gray",
"Voided": "purple"
}[doc.status], "status,=," + doc.status]
} else {
return [__("Not Set"), "blue", "status,=,'Not Set'"]
}
}
}

0 comments on commit e03e0f3

Please sign in to comment.