Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: look up party on PE submission to avoid renaming problems #67

Merged
merged 1 commit into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions check_run/check_run/doctype/check_run/check_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_dimensions

from atnacha import ACHEntry, ACHBatch, NACHAFile
from check_run.check_run.doctype.check_run_settings.check_run_settings import create


class CheckRun(Document):
def onload(self):
Expand All @@ -49,7 +51,6 @@ def validate(self):
else:
self.validate_transactions()
self.validate_last_check_number()
# Check all selected invoices have correct docstatus (saved/submitted)

def on_cancel(self):
settings = get_check_run_settings(self)
Expand Down Expand Up @@ -102,7 +103,8 @@ def validate_transactions(self):
for t in selected:
if not t['mode_of_payment']:
frappe.throw(frappe._(f"Mode of Payment Required: {t['party_name']} {t['ref_number']}"))
if frappe.get_value(t['doctype'], filters=t['name'], fieldname='docstatus') != 1:
filters = {'name': t['name'] if t['doctype'] != 'Journal Entry' else t['ref_number']}
if frappe.get_value(t['doctype'], filters, 'docstatus') != 1:
wrong_status.append({'party_name': t['party_name'], 'ref_number': t['ref_number'] or '', 'name': t['name']})
if len(wrong_status) < 1:
return
Expand Down Expand Up @@ -208,6 +210,12 @@ def create_payment_entries(self, transactions):
continue
for group in groups:
_references = []
if group[0].doctype == 'Purchase Invoice':
party = frappe.db.get_value('Purchase Invoice', group[0].name, 'supplier')
elif group[0].doctype == 'Expense Claim':
party = frappe.db.get_value('Expense Claim', group[0].name, 'employee')
elif group[0].doctype == 'Journal Entry':
party = frappe.db.get_value('Journal Entry Account', group[0].name, 'party')
pe = frappe.new_doc("Payment Entry")
pe.payment_type = "Pay"
pe.posting_date = nowdate()
Expand All @@ -220,7 +228,7 @@ def create_payment_entries(self, transactions):
pe.paid_from_account_currency = pe.paid_to_account_currency
pe.reference_date = self.posting_date
pe.party_type = group[0].party_type
pe.party = group[0].party
pe.party = party
pe.check_run = self.name
total_amount = 0
if frappe.db.get_value('Mode of Payment', _group[0].mode_of_payment, 'type') == 'Bank':
Expand All @@ -236,9 +244,13 @@ def create_payment_entries(self, transactions):
if settings.automatically_release_on_hold_invoices and reference.doctype == 'Purchase Invoice':
if frappe.get_value(reference.doctype, reference.name, 'on_hold'):
frappe.db.set_value(reference.doctype, reference.name, 'on_hold', 0)
if reference.doctype == 'Journal Entry':
reference_name = reference.ref_number
else:
reference_name = reference.name or reference.ref_number
pe.append('references', {
"reference_doctype": reference.doctype,
"reference_name": reference.name or reference.ref_number,
"reference_name": reference_name,
"due_date": reference.get("due_date"),
"outstanding_amount": flt(reference.amount),
"allocated_amount": flt(reference.amount),
Expand Down Expand Up @@ -420,7 +432,7 @@ def get_entries(doc):
SELECT
'Journal Entry' AS doctype,
`tabJournal Entry Account`.party_type,
`tabJournal Entry`.name,
`tabJournal Entry Account`.name,
`tabJournal Entry`.name AS ref_number,
`tabJournal Entry Account`.party,
`tabJournal Entry Account`.party AS party_name,
Expand Down
12 changes: 9 additions & 3 deletions check_run/public/js/check_run/CheckRun.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,15 @@ export default {
},
methods: {
transactionUrl: transaction => {
return encodeURI(
`${frappe.urllib.get_base_url()}/app/${transaction.doctype.toLowerCase().replace(' ', '-')}/${transaction.name}`
)
if(transaction.doctype !== 'Journal Entry'){
return encodeURI(
`${frappe.urllib.get_base_url()}/app/${transaction.doctype.toLowerCase().replace(' ', '-')}/${transaction.name}`
)
} else {
return encodeURI(
`${frappe.urllib.get_base_url()}/app/${transaction.doctype.toLowerCase().replace(' ', '-')}/${transaction.ref_number}`
)
}
},
paymentEntryUrl: transaction => {
if (!transaction.payment_entry) {
Expand Down