Skip to content

Commit

Permalink
Allow or Disallow stand-alone debit note in check run -- Version 15 (#…
Browse files Browse the repository at this point in the history
…257)

* allow or disallow standalone debit note

* test cases changes'
  • Loading branch information
viralkansodiya authored Jul 10, 2024
1 parent 624f36e commit e0707df
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
11 changes: 7 additions & 4 deletions check_run/check_run/doctype/check_run/check_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,7 @@ def create_payment_entries(self: Self, transactions: list[frappe._dict]) -> list
pe.bank_account = self.bank_account
pe.paid_from = gl_account
pe.paid_to = self.pay_to_account
pe.paid_to_account_currency = frappe.db.get_value(
"Account", self.bank_account, "account_currency"
)
pe.paid_to_account_currency = frappe.db.get_value("Account", gl_account, "account_currency")
pe.paid_from_account_currency = pe.paid_to_account_currency
pe.reference_date = self.posting_date
pe.party_type = group[0].party_type
Expand Down Expand Up @@ -571,7 +569,11 @@ def get_entries(doc: CheckRun | str) -> dict:
.as_("supplier_default_mode_of_payment")
.where(purchase_invoices.supplier == suppliers.name)
)

stand_alone_debit_note_filter = (
(Coalesce(payment_schedule.outstanding, purchase_invoices.outstanding_amount) > 0)
if settings.allow_stand_alone_debit_notes == "No"
else (Coalesce(payment_schedule.outstanding, purchase_invoices.outstanding_amount) != 0)
)
pi_qb = (
frappe.qb.from_(purchase_invoices)
.left_join(payment_schedule)
Expand All @@ -595,6 +597,7 @@ def get_entries(doc: CheckRun | str) -> dict:
)
.where(Coalesce(payment_schedule.due_date, purchase_invoices.due_date) <= end_date)
.where(Coalesce(payment_schedule.outstanding, purchase_invoices.outstanding_amount) != 0)
.where(stand_alone_debit_note_filter)
.where(purchase_invoices.company == company)
.where(purchase_invoices.docstatus == 1)
.where(purchase_invoices.credit_to == pay_to_account)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"split_by_address",
"automatically_release_on_hold_invoices",
"file_preview_threshold",
"allow_stand_alone_debit_notes",
"default_modes_of_payment_section_section",
"purchase_invoice",
"journal_entry",
Expand Down Expand Up @@ -227,6 +228,13 @@
"fieldtype": "Check",
"label": "Validate Unique Check Number"
},
{
"default": "No",
"fieldname": "allow_stand_alone_debit_notes",
"fieldtype": "Select",
"label": "Allow stand-alone debit notes?",
"options": "Yes\nNo"
},
{
"description": "Users with this role are allowed to download ACH file multiple times. Users without this role are allowed to download it only once.",
"fieldname": "role_allowed_to_download_ach_file_multiple_times",
Expand Down Expand Up @@ -273,4 +281,4 @@
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
}
15 changes: 11 additions & 4 deletions check_run/tests/test_check_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,19 @@ def test_process_check_run_on_hold_invoice_auto_release(cr):


def test_return_included_in_check_run_error(cr):
# Test for ValidationError when Check Run only includes a return transaction
cr.transactions = frappe.utils.safe_json_loads(cr.transactions)
for row in cr.transactions:
_transactions = get_entries(cr).get("transactions")
settings = get_check_run_settings(cr)
assert settings.allow_stand_alone_debit_notes == "No"
settings.allow_stand_alone_debit_notes = "Yes"
settings.save()
cr.posting_date = cr.end_date = datetime.date(year, 12, 30)
cr.transactions = ""
transactions = get_entries(cr).get("transactions")
assert transactions != _transactions
for row in transactions:
if row.get("party") == "Cooperative Ag Finance" and row.get("amount") < 0:
row["pay"] = True
cr.transactions = frappe.as_json(cr.transactions)
cr.transactions = frappe.as_json(transactions)
cr.flags.in_test = True
cr.save()

Expand Down

0 comments on commit e0707df

Please sign in to comment.