Skip to content

Commit

Permalink
chore: linter changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ruthra-kumar committed Sep 25, 2024
1 parent 8eaf5d0 commit 6a0d4f1
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 56 deletions.
6 changes: 3 additions & 3 deletions erpnext/accounts/doctype/journal_entry/journal_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ def get_title(self):

def update_advance_paid(self):
advance_paid = frappe._dict()
advance_payment_doctypes = frappe.get_hooks(
"advance_payment_customer_doctypes"
) + frappe.get_hooks("advance_payment_supplier_doctypes")
advance_payment_doctypes = frappe.get_hooks("advance_payment_customer_doctypes") + frappe.get_hooks(
"advance_payment_supplier_doctypes"
)
for d in self.get("accounts"):
if d.is_advance:
if d.reference_type in advance_payment_doctypes:
Expand Down
6 changes: 3 additions & 3 deletions erpnext/accounts/doctype/payment_entry/payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,9 +919,9 @@ def set_amounts_in_company_currency(self):

def calculate_base_allocated_amount_for_reference(self, d) -> float:
base_allocated_amount = 0
advance_payment_doctypes = frappe.get_hooks(
"advance_payment_customer_doctypes"
) + frappe.get_hooks("advance_payment_supplier_doctypes")
advance_payment_doctypes = frappe.get_hooks("advance_payment_customer_doctypes") + frappe.get_hooks(
"advance_payment_supplier_doctypes"
)
if d.reference_doctype in advance_payment_doctypes:
# When referencing Sales/Purchase Order, use the source/target exchange rate depending on payment type.
# This is so there are no Exchange Gain/Loss generated for such doctypes
Expand Down
12 changes: 6 additions & 6 deletions erpnext/accounts/doctype/payment_request/payment_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ def on_submit(self):
elif self.payment_channel == "Phone":
self.request_phone_payment()

advance_payment_doctypes = frappe.get_hooks(
"advance_payment_customer_doctypes"
) + frappe.get_hooks("advance_payment_supplier_doctypes")
advance_payment_doctypes = frappe.get_hooks("advance_payment_customer_doctypes") + frappe.get_hooks(
"advance_payment_supplier_doctypes"
)
if self.reference_doctype in advance_payment_doctypes:
# set advance payment status
ref_doc.set_total_advance_paid()
Expand Down Expand Up @@ -215,9 +215,9 @@ def on_cancel(self):
self.check_if_payment_entry_exists()
self.set_as_cancelled()
ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name)
advance_payment_doctypes = frappe.get_hooks(
"advance_payment_customer_doctypes"
) + frappe.get_hooks("advance_payment_supplier_doctypes")
advance_payment_doctypes = frappe.get_hooks("advance_payment_customer_doctypes") + frappe.get_hooks(
"advance_payment_supplier_doctypes"
)
if self.reference_doctype in advance_payment_doctypes:
# set advance payment status
ref_doc.set_total_advance_paid()
Expand Down
13 changes: 6 additions & 7 deletions erpnext/accounts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,13 +618,12 @@ def update_reference_in_journal_entry(d, journal_entry, do_not_save=False):

# Update Advance Paid in SO/PO since they might be getting unlinked
update_advance_paid = []
advance_payment_doctypes = frappe.get_hooks(
"advance_payment_customer_doctypes"
) + frappe.get_hooks("advance_payment_supplier_doctypes")
advance_payment_doctypes = frappe.get_hooks("advance_payment_customer_doctypes") + frappe.get_hooks(
"advance_payment_supplier_doctypes"
)
if jv_detail.get("reference_type") in advance_payment_doctypes:
update_advance_paid.append((jv_detail.reference_type, jv_detail.reference_name))


if flt(d["unadjusted_amount"]) - flt(d["allocated_amount"]) != 0:
# adjust the unreconciled balance
amount_in_account_currency = flt(d["unadjusted_amount"]) - flt(d["allocated_amount"])
Expand Down Expand Up @@ -699,9 +698,9 @@ def update_reference_in_payment_entry(
existing_row = payment_entry.get("references", {"name": d["voucher_detail_no"]})[0]

# Update Advance Paid in SO/PO since they are getting unlinked
advance_payment_doctypes = frappe.get_hooks(
"advance_payment_customer_doctypes"
) + frappe.get_hooks("advance_payment_supplier_doctypes")
advance_payment_doctypes = frappe.get_hooks("advance_payment_customer_doctypes") + frappe.get_hooks(
"advance_payment_supplier_doctypes"
)
if existing_row.get("reference_doctype") in advance_payment_doctypes:
update_advance_paid.append((existing_row.reference_doctype, existing_row.reference_name))

Expand Down
12 changes: 3 additions & 9 deletions erpnext/buying/doctype/purchase_order/test_purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -1128,27 +1128,21 @@ def test_purchase_order_advance_payment_status(self):
from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request

po = create_purchase_order()
self.assertEqual(
frappe.db.get_value(po.doctype, po.name, "advance_payment_status"), "Not Initiated"
)
self.assertEqual(frappe.db.get_value(po.doctype, po.name, "advance_payment_status"), "Not Initiated")

pr = make_payment_request(dt=po.doctype, dn=po.name, submit_doc=True, return_doc=True)
self.assertEqual(frappe.db.get_value(po.doctype, po.name, "advance_payment_status"), "Initiated")

pe = get_payment_entry(po.doctype, po.name).save().submit()
self.assertEqual(
frappe.db.get_value(po.doctype, po.name, "advance_payment_status"), "Fully Paid"
)
self.assertEqual(frappe.db.get_value(po.doctype, po.name, "advance_payment_status"), "Fully Paid")

pe.reload()
pe.cancel()
self.assertEqual(frappe.db.get_value(po.doctype, po.name, "advance_payment_status"), "Initiated")

pr.reload()
pr.cancel()
self.assertEqual(
frappe.db.get_value(po.doctype, po.name, "advance_payment_status"), "Not Initiated"
)
self.assertEqual(frappe.db.get_value(po.doctype, po.name, "advance_payment_status"), "Not Initiated")


def prepare_data_for_internal_transfer():
Expand Down
4 changes: 1 addition & 3 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1975,9 +1975,7 @@ def set_total_advance_paid(self):

self.set_advance_payment_status(advance_paid, order_total)

def set_advance_payment_status(
self, advance_paid: float | None = None, order_total: float | None = None
):
def set_advance_payment_status(self, advance_paid: float | None = None, order_total: float | None = None):
new_status = None
# if money is paid set the paid states
if advance_paid:
Expand Down
28 changes: 12 additions & 16 deletions erpnext/patches/v15_0/create_advance_payment_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ def execute():

if frappe.reload_doc("selling", "doctype", "Sales Order"):
so = frappe.qb.DocType("Sales Order")
frappe.qb.update(so).set(so.advance_payment_status, "Not Requested").where(
so.docstatus == 1
).where(so.advance_paid == 0.0).run()

frappe.qb.update(so).set(so.advance_payment_status, "Partially Paid").where(
so.docstatus == 1
).where(so.advance_payment_status.isnull()).where(
so.advance_paid < (so.rounded_total or so.grand_total)
frappe.qb.update(so).set(so.advance_payment_status, "Not Requested").where(so.docstatus == 1).where(
so.advance_paid == 0.0
).run()

frappe.qb.update(so).set(so.advance_payment_status, "Partially Paid").where(so.docstatus == 1).where(
so.advance_payment_status.isnull()
).where(so.advance_paid < (so.rounded_total or so.grand_total)).run()

frappe.qb.update(so).set(so.advance_payment_status, "Fully Paid").where(so.docstatus == 1).where(
so.advance_payment_status.isnull()
).where(so.advance_paid == (so.rounded_total or so.grand_total)).run()
Expand All @@ -32,16 +30,14 @@ def execute():

if frappe.reload_doc("buying", "doctype", "Purchase Order"):
po = frappe.qb.DocType("Purchase Order")
frappe.qb.update(po).set(po.advance_payment_status, "Not Initiated").where(
po.docstatus == 1
).where(po.advance_paid == 0.0).run()

frappe.qb.update(po).set(po.advance_payment_status, "Partially Paid").where(
po.docstatus == 1
).where(po.advance_payment_status.isnull()).where(
po.advance_paid < (po.rounded_total or po.grand_total)
frappe.qb.update(po).set(po.advance_payment_status, "Not Initiated").where(po.docstatus == 1).where(
po.advance_paid == 0.0
).run()

frappe.qb.update(po).set(po.advance_payment_status, "Partially Paid").where(po.docstatus == 1).where(
po.advance_payment_status.isnull()
).where(po.advance_paid < (po.rounded_total or po.grand_total)).run()

frappe.qb.update(po).set(po.advance_payment_status, "Fully Paid").where(po.docstatus == 1).where(
po.advance_payment_status.isnull()
).where(po.advance_paid == (po.rounded_total or po.grand_total)).run()
Expand Down
12 changes: 3 additions & 9 deletions erpnext/selling/doctype/sales_order/test_sales_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -2117,27 +2117,21 @@ def test_sales_order_advance_payment_status(self):
from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request

so = make_sales_order(qty=1, rate=100)
self.assertEqual(
frappe.db.get_value(so.doctype, so.name, "advance_payment_status"), "Not Requested"
)
self.assertEqual(frappe.db.get_value(so.doctype, so.name, "advance_payment_status"), "Not Requested")

pr = make_payment_request(dt=so.doctype, dn=so.name, submit_doc=True, return_doc=True)
self.assertEqual(frappe.db.get_value(so.doctype, so.name, "advance_payment_status"), "Requested")

pe = get_payment_entry(so.doctype, so.name).save().submit()
self.assertEqual(
frappe.db.get_value(so.doctype, so.name, "advance_payment_status"), "Fully Paid"
)
self.assertEqual(frappe.db.get_value(so.doctype, so.name, "advance_payment_status"), "Fully Paid")

pe.reload()
pe.cancel()
self.assertEqual(frappe.db.get_value(so.doctype, so.name, "advance_payment_status"), "Requested")

pr.reload()
pr.cancel()
self.assertEqual(
frappe.db.get_value(so.doctype, so.name, "advance_payment_status"), "Not Requested"
)
self.assertEqual(frappe.db.get_value(so.doctype, so.name, "advance_payment_status"), "Not Requested")


def automatically_fetch_payment_terms(enable=1):
Expand Down

0 comments on commit 6a0d4f1

Please sign in to comment.