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: add fallbacks for mode of payment per source document type #180

Merged
merged 3 commits into from
Dec 12, 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
29 changes: 19 additions & 10 deletions check_run/check_run/doctype/check_run/check_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from frappe.utils.password import get_decrypted_password
from frappe.contacts.doctype.address.address import get_default_address
from frappe.query_builder.custom import ConstantColumn
from frappe.query_builder.functions import Coalesce, Sum
from frappe.query_builder.functions import Coalesce, Sum, NullIf
from frappe.desk.form.load import get_attachments

from erpnext.accounts.utils import get_balance_on
Expand Down Expand Up @@ -523,8 +523,8 @@ def get_entries(doc: CheckRun | str) -> dict:
purchase_invoices.posting_date,
Coalesce(
purchase_invoices.supplier_default_mode_of_payment,
supplier_mop_sub_query, # suppliers.supplier_default_mode_of_payment,
"\n",
NullIf(supplier_mop_sub_query, ""), # suppliers.supplier_default_mode_of_payment,
f"{settings.purchase_invoice}" or "\n",
).as_("mode_of_payment"),
(payment_schedule.payment_term).as_("payment_term"),
)
Expand Down Expand Up @@ -553,7 +553,11 @@ def get_entries(doc: CheckRun | str) -> dict:
(exp_claims.grand_total).as_("amount"),
(exp_claims.posting_date).as_("due_date"),
exp_claims.posting_date,
Coalesce(exp_claims.mode_of_payment, employees.mode_of_payment, "\n").as_("mode_of_payment"),
Coalesce(
exp_claims.mode_of_payment,
NullIf(employees.mode_of_payment, ""),
f"{settings.expense_claim}" or "\n",
).as_("mode_of_payment"),
ConstantColumn("").as_("payment_term"),
)
.where(exp_claims.grand_total > exp_claims.total_amount_reimbursed)
Expand Down Expand Up @@ -593,7 +597,9 @@ def get_entries(doc: CheckRun | str) -> dict:
(je_accounts.credit_in_account_currency).as_("amount"),
journal_entries.due_date,
journal_entries.posting_date,
Coalesce(journal_entries.mode_of_payment, "\n").as_("mode_of_payment"),
Coalesce(journal_entries.mode_of_payment, f"{settings.journal_entry}" or "\n").as_(
"mode_of_payment"
),
ConstantColumn("").as_("payment_term"),
)
.where(journal_entries.company == company)
Expand Down Expand Up @@ -623,7 +629,9 @@ def get_entries(doc: CheckRun | str) -> dict:
query = query.orderby("due_date", "name").get_sql()

transactions = frappe.db.sql(
query, {"company": company, "pay_to_account": pay_to_account, "end_date": end_date}, as_dict=True
query,
{"company": company, "pay_to_account": pay_to_account, "end_date": end_date},
as_dict=True,
)
for transaction in transactions:
doc_name = transaction.ref_number if transaction.ref_number else transaction.name
Expand All @@ -639,13 +647,14 @@ def get_entries(doc: CheckRun | str) -> dict:
if transaction.doctype == "Journal Entry":
if transaction.party_type == "Supplier":
transaction.party_name = frappe.get_value("Supplier", transaction.party, "supplier_name")
transaction.mode_of_payment = frappe.get_value(
"Supplier", transaction.party, "supplier_default_mode_of_payment"
transaction.mode_of_payment = (
frappe.get_value("Supplier", transaction.party, "supplier_default_mode_of_payment")
or settings.journal_entry
)
if transaction.party_type == "Employee":
transaction.party_name = frappe.get_value("Employee", transaction.party, "employee_name")
transaction.mode_of_payment = frappe.get_value(
"Employee", transaction.party, "mode_of_payment"
transaction.mode_of_payment = (
frappe.get_value("Employee", transaction.party, "mode_of_payment") or settings.journal_entry
)

return {"transactions": transactions, "modes_of_payment": modes_of_payment}
Expand Down
Loading
Loading