diff --git a/erpnext/accounts/doctype/bank_transaction/bank_transaction.py b/erpnext/accounts/doctype/bank_transaction/bank_transaction.py index 94a66d7957e..4354f238a42 100644 --- a/erpnext/accounts/doctype/bank_transaction/bank_transaction.py +++ b/erpnext/accounts/doctype/bank_transaction/bank_transaction.py @@ -182,7 +182,7 @@ class BankTransaction(Document): frappe.throw(_("Voucher {0} is over-allocated by {1}").format(unallocated_amount)) for payment_entry in to_remove: - self.remove(to_remove) + self.remove(payment_entry) @frappe.whitelist() def remove_payment_entries(self): diff --git a/erpnext/accounts/doctype/budget/budget.py b/erpnext/accounts/doctype/budget/budget.py index 7f73533a02d..d7545ef1520 100644 --- a/erpnext/accounts/doctype/budget/budget.py +++ b/erpnext/accounts/doctype/budget/budget.py @@ -373,12 +373,9 @@ def get_actual_expense(args): args.update(lft_rgt) - condition2 = """and exists(select name from `tab{doctype}` + condition2 = f"""and exists(select name from `tab{args.budget_against_doctype}` where lft>=%(lft)s and rgt<=%(rgt)s - and name=gle.{budget_against_field})""".format( - doctype=args.budget_against_doctype, - budget_against_field=budget_against_field, # nosec - ) + and name=gle.{budget_against_field})""" else: condition2 = f"""and exists(select name from `tab{args.budget_against_doctype}` where name=gle.{budget_against_field} and diff --git a/erpnext/accounts/doctype/invoice_discounting/test_invoice_discounting.py b/erpnext/accounts/doctype/invoice_discounting/test_invoice_discounting.py index 65e3c3dcd6a..01050c058e8 100644 --- a/erpnext/accounts/doctype/invoice_discounting/test_invoice_discounting.py +++ b/erpnext/accounts/doctype/invoice_discounting/test_invoice_discounting.py @@ -75,8 +75,8 @@ class TestInvoiceDiscounting(unittest.TestCase): gle = get_gl_entries("Invoice Discounting", inv_disc.name) expected_gle = {inv.debit_to: [0.0, 200], self.ar_credit: [200, 0.0]} - for _i, gle in enumerate(gle): - self.assertEqual([gle.debit, gle.credit], expected_gle.get(gle.account)) + for _i, gle_value in enumerate(gle): + self.assertEqual([gle_value.debit, gle_value.credit], expected_gle.get(gle_value.account)) def test_loan_on_submit(self): inv = create_sales_invoice(rate=300) diff --git a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py index 28bafcea749..c3aafef9ad1 100644 --- a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py @@ -160,7 +160,7 @@ class TestPaymentEntry(FrappeTestCase): supplier.on_hold = 0 supplier.save() - except: + except Exception: pass else: raise Exception diff --git a/erpnext/accounts/doctype/payment_ledger_entry/test_payment_ledger_entry.py b/erpnext/accounts/doctype/payment_ledger_entry/test_payment_ledger_entry.py index c867e68d1a6..3eac98d7910 100644 --- a/erpnext/accounts/doctype/payment_ledger_entry/test_payment_ledger_entry.py +++ b/erpnext/accounts/doctype/payment_ledger_entry/test_payment_ledger_entry.py @@ -84,11 +84,14 @@ class TestPaymentLedgerEntry(FrappeTestCase): self.customer = customer.name def create_sales_invoice( - self, qty=1, rate=100, posting_date=nowdate(), do_not_save=False, do_not_submit=False + self, qty=1, rate=100, posting_date=None, do_not_save=False, do_not_submit=False ): """ Helper function to populate default values in sales invoice """ + if posting_date is None: + posting_date = nowdate() + sinv = create_sales_invoice( qty=qty, rate=rate, @@ -112,10 +115,12 @@ class TestPaymentLedgerEntry(FrappeTestCase): ) return sinv - def create_payment_entry(self, amount=100, posting_date=nowdate()): + def create_payment_entry(self, amount=100, posting_date=None): """ Helper function to populate default values in payment entry """ + if posting_date is None: + posting_date = nowdate() payment = create_payment_entry( company=self.company, payment_type="Receive", @@ -128,9 +133,10 @@ class TestPaymentLedgerEntry(FrappeTestCase): payment.posting_date = posting_date return payment - def create_sales_order( - self, qty=1, rate=100, posting_date=nowdate(), do_not_save=False, do_not_submit=False - ): + def create_sales_order(self, qty=1, rate=100, posting_date=None, do_not_save=False, do_not_submit=False): + if posting_date is None: + posting_date = nowdate() + so = make_sales_order( company=self.company, transaction_date=posting_date, diff --git a/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py index f0ed348f3c3..0a3a0678084 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py +++ b/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py @@ -134,11 +134,14 @@ class TestPaymentReconciliation(FrappeTestCase): setattr(self, x.attribute, acc.name) def create_sales_invoice( - self, qty=1, rate=100, posting_date=nowdate(), do_not_save=False, do_not_submit=False + self, qty=1, rate=100, posting_date=None, do_not_save=False, do_not_submit=False ): """ Helper function to populate default values in sales invoice """ + if posting_date is None: + posting_date = nowdate() + sinv = create_sales_invoice( qty=qty, rate=rate, @@ -162,10 +165,13 @@ class TestPaymentReconciliation(FrappeTestCase): ) return sinv - def create_payment_entry(self, amount=100, posting_date=nowdate(), customer=None): + def create_payment_entry(self, amount=100, posting_date=None, customer=None): """ Helper function to populate default values in payment entry """ + if posting_date is None: + posting_date = nowdate() + payment = create_payment_entry( company=self.company, payment_type="Receive", @@ -179,11 +185,14 @@ class TestPaymentReconciliation(FrappeTestCase): return payment def create_purchase_invoice( - self, qty=1, rate=100, posting_date=nowdate(), do_not_save=False, do_not_submit=False + self, qty=1, rate=100, posting_date=None, do_not_save=False, do_not_submit=False ): """ Helper function to populate default values in sales invoice """ + if posting_date is None: + posting_date = nowdate() + pinv = make_purchase_invoice( qty=qty, rate=rate, @@ -208,11 +217,14 @@ class TestPaymentReconciliation(FrappeTestCase): return pinv def create_purchase_order( - self, qty=1, rate=100, posting_date=nowdate(), do_not_save=False, do_not_submit=False + self, qty=1, rate=100, posting_date=None, do_not_save=False, do_not_submit=False ): """ Helper function to populate default values in sales invoice """ + if posting_date is None: + posting_date = nowdate() + pord = create_purchase_order( qty=qty, rate=rate, diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py index fb916721b23..7501df02c3f 100644 --- a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py +++ b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py @@ -480,7 +480,7 @@ def create_merge_logs(invoice_by_customer, closing_entry=None): if closing_entry: closing_entry.set_status(update=True, status="Failed") - if type(error_message) == list: + if isinstance(error_message, list): error_message = frappe.json.dumps(error_message) closing_entry.db_set("error_message", error_message) raise diff --git a/erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation.py b/erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation.py index d5a039411a9..d4d66a51c34 100644 --- a/erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation.py +++ b/erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation.py @@ -503,7 +503,7 @@ def reconcile(doc: None | str = None) -> None: def is_any_doc_running(for_filter: str | dict | None = None) -> str | None: running_doc = None if for_filter: - if type(for_filter) == str: + if isinstance(for_filter, str): for_filter = frappe.json.loads(for_filter) running_doc = frappe.db.get_value( diff --git a/erpnext/accounts/doctype/process_subscription/process_subscription.py b/erpnext/accounts/doctype/process_subscription/process_subscription.py index f0a224443f5..b4d18a3c0a8 100644 --- a/erpnext/accounts/doctype/process_subscription/process_subscription.py +++ b/erpnext/accounts/doctype/process_subscription/process_subscription.py @@ -1,13 +1,11 @@ # Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors # For license information, please see license.txt -from datetime import datetime - import frappe from frappe.model.document import Document from frappe.utils import getdate -from erpnext.accounts.doctype.subscription.subscription import process_all +from erpnext.accounts.doctype.subscription.subscription import DateTimeLikeObject, process_all class ProcessSubscription(Document): @@ -29,7 +27,7 @@ class ProcessSubscription(Document): def create_subscription_process( - subscription: str | None = None, posting_date: str | datetime.date | None = None + subscription: str | None = None, posting_date: DateTimeLikeObject | None = None ): """Create a new Process Subscription document""" doc = frappe.new_doc("Process Subscription") diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index 2c2ac75b0b5..3ea88f195d8 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -221,7 +221,7 @@ class TestPurchaseInvoice(FrappeTestCase, StockTestMixin): supplier.on_hold = 0 supplier.save() - except: + except Exception: pass else: raise Exception diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index f3a37d3096e..7d7e1633044 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -3730,41 +3730,6 @@ def set_advance_flag(company, flag, default_account): ) -def get_sales_invoice_for_e_invoice(): - si = make_sales_invoice_for_ewaybill() - si.naming_series = "INV-2020-.#####" - si.items = [] - si.append( - "items", - { - "item_code": "_Test Item", - "uom": "Nos", - "warehouse": "_Test Warehouse - _TC", - "qty": 2000, - "rate": 12, - "income_account": "Sales - _TC", - "expense_account": "Cost of Goods Sold - _TC", - "cost_center": "_Test Cost Center - _TC", - }, - ) - - si.append( - "items", - { - "item_code": "_Test Item 2", - "uom": "Nos", - "warehouse": "_Test Warehouse - _TC", - "qty": 420, - "rate": 15, - "income_account": "Sales - _TC", - "expense_account": "Cost of Goods Sold - _TC", - "cost_center": "_Test Cost Center - _TC", - }, - ) - - return si - - def check_gl_entries(doc, voucher_no, expected_gle, posting_date, voucher_type="Sales Invoice"): gl = frappe.qb.DocType("GL Entry") q = ( diff --git a/erpnext/accounts/doctype/subscription/subscription.py b/erpnext/accounts/doctype/subscription/subscription.py index 476e797e955..0d5f24eb199 100644 --- a/erpnext/accounts/doctype/subscription/subscription.py +++ b/erpnext/accounts/doctype/subscription/subscription.py @@ -2,8 +2,7 @@ # For license information, please see license.txt -from datetime import datetime -from typing import Optional, Union +from datetime import date import frappe from frappe import _ @@ -37,7 +36,7 @@ class InvoiceNotCancelled(frappe.ValidationError): pass -DateTimeLikeObject = Union[str, datetime.date] +DateTimeLikeObject = str | date class Subscription(Document): @@ -88,7 +87,7 @@ class Subscription(Document): # update start just before the subscription doc is created self.update_subscription_period(self.start_date) - def update_subscription_period(self, date: Optional["DateTimeLikeObject"] = None): + def update_subscription_period(self, date: DateTimeLikeObject | None = None): """ Subscription period is the period to be billed. This method updates the beginning of the billing period and end of the billing period. @@ -99,13 +98,13 @@ class Subscription(Document): self.current_invoice_start = self.get_current_invoice_start(date) self.current_invoice_end = self.get_current_invoice_end(self.current_invoice_start) - def _get_subscription_period(self, date: Optional["DateTimeLikeObject"] = None): + def _get_subscription_period(self, date: DateTimeLikeObject | None = None): _current_invoice_start = self.get_current_invoice_start(date) _current_invoice_end = self.get_current_invoice_end(_current_invoice_start) return _current_invoice_start, _current_invoice_end - def get_current_invoice_start(self, date: Optional["DateTimeLikeObject"] = None) -> datetime.date | str: + def get_current_invoice_start(self, date: DateTimeLikeObject | None = None) -> DateTimeLikeObject: """ This returns the date of the beginning of the current billing period. If the `date` parameter is not given , it will be automatically set as today's @@ -128,7 +127,7 @@ class Subscription(Document): return _current_invoice_start - def get_current_invoice_end(self, date: Optional["DateTimeLikeObject"] = None) -> datetime.date | str: + def get_current_invoice_end(self, date: DateTimeLikeObject | None = None) -> DateTimeLikeObject: """ This returns the date of the end of the current billing period. If the subscription is in trial period, it will be set as the end of the @@ -222,7 +221,7 @@ class Subscription(Document): return data - def set_subscription_status(self, posting_date: Optional["DateTimeLikeObject"] = None) -> None: + def set_subscription_status(self, posting_date: DateTimeLikeObject | None = None) -> None: """ Sets the status of the `Subscription` """ @@ -246,7 +245,7 @@ class Subscription(Document): @staticmethod def period_has_passed( - end_date: str | datetime.date, posting_date: Optional["DateTimeLikeObject"] = None + end_date: DateTimeLikeObject, posting_date: DateTimeLikeObject | None = None ) -> bool: """ Returns true if the given `end_date` has passed @@ -266,7 +265,7 @@ class Subscription(Document): return status - def is_past_grace_period(self, posting_date: Optional["DateTimeLikeObject"] = None) -> bool: + def is_past_grace_period(self, posting_date: DateTimeLikeObject | None = None) -> bool: """ Returns `True` if the grace period for the `Subscription` has passed """ @@ -276,7 +275,7 @@ class Subscription(Document): grace_period = cint(frappe.get_value("Subscription Settings", None, "grace_period")) return getdate(posting_date) >= getdate(add_days(self.current_invoice.due_date, grace_period)) - def current_invoice_is_past_due(self, posting_date: Optional["DateTimeLikeObject"] = None) -> bool: + def current_invoice_is_past_due(self, posting_date: DateTimeLikeObject | None = None) -> bool: """ Returns `True` if the current generated invoice is overdue """ @@ -377,9 +376,9 @@ class Subscription(Document): def generate_invoice( self, - from_date: str | datetime.date | None = None, - to_date: str | datetime.date | None = None, - posting_date: str | datetime.date | None = None, + from_date: DateTimeLikeObject | None = None, + to_date: DateTimeLikeObject | None = None, + posting_date: DateTimeLikeObject | None = None, ) -> Document: """ Creates a `Invoice` for the `Subscription`, updates `self.invoices` and @@ -390,9 +389,9 @@ class Subscription(Document): def create_invoice( self, - from_date: str | datetime.date | None = None, - to_date: str | datetime.date | None = None, - posting_date: str | datetime.date | None = None, + from_date: DateTimeLikeObject | None = None, + to_date: DateTimeLikeObject | None = None, + posting_date: DateTimeLikeObject | None = None, ) -> Document: """ Creates a `Invoice`, submits it and returns it @@ -572,7 +571,7 @@ class Subscription(Document): return items @frappe.whitelist() - def process(self, posting_date: Optional["DateTimeLikeObject"] = None) -> bool: + def process(self, posting_date: DateTimeLikeObject | None = None) -> bool: """ To be called by task periodically. It checks the subscription and takes appropriate action as need be. It calls either of these methods depending the `Subscription` status: @@ -597,7 +596,7 @@ class Subscription(Document): self.save() - def can_generate_new_invoice(self, posting_date: Optional["DateTimeLikeObject"] = None) -> bool: + def can_generate_new_invoice(self, posting_date: DateTimeLikeObject | None = None) -> bool: if self.cancelation_date: return False @@ -619,8 +618,8 @@ class Subscription(Document): def is_current_invoice_generated( self, - _current_start_date: datetime.date | str | None = None, - _current_end_date: datetime.date | str | None = None, + _current_start_date: DateTimeLikeObject | None = None, + _current_end_date: DateTimeLikeObject | None = None, ) -> bool: if not (_current_start_date and _current_end_date): _current_start_date, _current_end_date = self._get_subscription_period( @@ -716,7 +715,7 @@ class Subscription(Document): self.save() @frappe.whitelist() - def restart_subscription(self, posting_date: Optional["DateTimeLikeObject"] = None) -> None: + def restart_subscription(self, posting_date: DateTimeLikeObject | None = None) -> None: """ This sets the subscription as active. The subscription will be made to be like a new subscription and the `Subscription` will lose all the history of generated invoices @@ -736,8 +735,8 @@ def is_prorate() -> int: def get_prorata_factor( - period_end: datetime.date | str, - period_start: datetime.date | str, + period_end: DateTimeLikeObject, + period_start: DateTimeLikeObject, is_prepaid: int | None = None, ) -> int | float: if is_prepaid: @@ -748,7 +747,7 @@ def get_prorata_factor( return diff / plan_days -def process_all(subscription: str | None = None, posting_date: Optional["DateTimeLikeObject"] = None) -> None: +def process_all(subscription: str | None = None, posting_date: DateTimeLikeObject | None = None) -> None: """ Task to updates the status of all `Subscription` apart from those that are cancelled """ diff --git a/erpnext/accounts/report/deferred_revenue_and_expense/deferred_revenue_and_expense.py b/erpnext/accounts/report/deferred_revenue_and_expense/deferred_revenue_and_expense.py index 303305d20c5..8999ef710f0 100644 --- a/erpnext/accounts/report/deferred_revenue_and_expense/deferred_revenue_and_expense.py +++ b/erpnext/accounts/report/deferred_revenue_and_expense/deferred_revenue_and_expense.py @@ -192,7 +192,7 @@ class Deferred_Invoice: for item in self.items: item_total = item.calculate_item_revenue_expense_for_period() # update invoice total - for idx, period in enumerate(self.period_list, 0): + for idx in range(len(self.period_list)): self.period_total[idx].total += item_total[idx].total self.period_total[idx].actual += item_total[idx].actual return self.period_total @@ -346,7 +346,7 @@ class Deferred_Revenue_and_Expense_Report: for inv in self.deferred_invoices: inv_total = inv.calculate_invoice_revenue_expense_for_period() # calculate total for whole report - for idx, period in enumerate(self.period_list, 0): + for idx in range(len(self.period_list)): self.period_total[idx].total += inv_total[idx].total self.period_total[idx].actual += inv_total[idx].actual diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py index 44778f3318c..4fd6a3bcf62 100644 --- a/erpnext/accounts/report/general_ledger/general_ledger.py +++ b/erpnext/accounts/report/general_ledger/general_ledger.py @@ -491,7 +491,7 @@ def get_accountwise_gle(filters, accounting_dimensions, gl_entries, gle_map): else: update_value_in_dict(consolidated_gle, key, gle) - for key, value in consolidated_gle.items(): + for value in consolidated_gle.values(): update_value_in_dict(totals, "total", value) update_value_in_dict(totals, "closing", value) entries.append(value) diff --git a/erpnext/accounts/report/gross_profit/gross_profit.py b/erpnext/accounts/report/gross_profit/gross_profit.py index 8e2d9c6ca72..dd4546db5ab 100644 --- a/erpnext/accounts/report/gross_profit/gross_profit.py +++ b/erpnext/accounts/report/gross_profit/gross_profit.py @@ -494,7 +494,7 @@ class GrossProfitGenerator: def get_average_rate_based_on_group_by(self): for key in list(self.grouped): if self.filters.get("group_by") == "Invoice": - for i, row in enumerate(self.grouped[key]): + for row in self.grouped[key]: if row.indent == 1.0: if ( row.parent in self.returned_invoices diff --git a/erpnext/accounts/report/gross_profit/test_gross_profit.py b/erpnext/accounts/report/gross_profit/test_gross_profit.py index 8d15900741e..741ea46a516 100644 --- a/erpnext/accounts/report/gross_profit/test_gross_profit.py +++ b/erpnext/accounts/report/gross_profit/test_gross_profit.py @@ -86,11 +86,14 @@ class TestGrossProfit(FrappeTestCase): self.customer = customer.name def create_sales_invoice( - self, qty=1, rate=100, posting_date=nowdate(), do_not_save=False, do_not_submit=False + self, qty=1, rate=100, posting_date=None, do_not_save=False, do_not_submit=False ): """ Helper function to populate default values in sales invoice """ + if posting_date is None: + posting_date = nowdate() + sinv = create_sales_invoice( qty=qty, rate=rate, @@ -115,11 +118,14 @@ class TestGrossProfit(FrappeTestCase): return sinv def create_delivery_note( - self, item=None, qty=1, rate=100, posting_date=nowdate(), do_not_save=False, do_not_submit=False + self, item=None, qty=1, rate=100, posting_date=None, do_not_save=False, do_not_submit=False ): """ Helper function to populate default values in Delivery Note """ + if posting_date is None: + posting_date = nowdate() + dnote = create_delivery_note( company=self.company, customer=self.customer, diff --git a/erpnext/buying/doctype/purchase_order/test_purchase_order.py b/erpnext/buying/doctype/purchase_order/test_purchase_order.py index 1c9d9614bc0..1d87aac2c36 100644 --- a/erpnext/buying/doctype/purchase_order/test_purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/test_purchase_order.py @@ -692,7 +692,7 @@ class TestPurchaseOrder(FrappeTestCase): supplier.on_hold = 0 supplier.save() - except: + except Exception: pass else: raise Exception diff --git a/erpnext/controllers/tests/test_accounts_controller.py b/erpnext/controllers/tests/test_accounts_controller.py index d772ccd8c6a..6218bd6ddf0 100644 --- a/erpnext/controllers/tests/test_accounts_controller.py +++ b/erpnext/controllers/tests/test_accounts_controller.py @@ -140,13 +140,16 @@ class TestAccountsController(FrappeTestCase): qty=1, rate=1, conversion_rate=80, - posting_date=nowdate(), + posting_date=None, do_not_save=False, do_not_submit=False, ): """ Helper function to populate default values in sales invoice """ + if posting_date is None: + posting_date = nowdate() + sinv = create_sales_invoice( qty=qty, rate=rate, @@ -171,10 +174,13 @@ class TestAccountsController(FrappeTestCase): ) return sinv - def create_payment_entry(self, amount=1, source_exc_rate=75, posting_date=nowdate(), customer=None): + def create_payment_entry(self, amount=1, source_exc_rate=75, posting_date=None, customer=None): """ Helper function to populate default values in payment entry """ + if posting_date is None: + posting_date = nowdate() + payment = create_payment_entry( company=self.company, payment_type="Receive", diff --git a/erpnext/controllers/tests/test_subcontracting_controller.py b/erpnext/controllers/tests/test_subcontracting_controller.py index b0c57e9586a..dfd4351dcad 100644 --- a/erpnext/controllers/tests/test_subcontracting_controller.py +++ b/erpnext/controllers/tests/test_subcontracting_controller.py @@ -560,7 +560,7 @@ class TestSubcontractingController(FrappeTestCase): scr2.set_missing_values() scr2.submit() - for key, value in get_supplied_items(scr2).items(): + for value in get_supplied_items(scr2).values(): self.assertEqual(value.qty, 4) scr3 = make_subcontracting_receipt(sco.name) @@ -570,7 +570,7 @@ class TestSubcontractingController(FrappeTestCase): scr3.set_missing_values() scr3.submit() - for key, value in get_supplied_items(scr3).items(): + for value in get_supplied_items(scr3).values(): self.assertEqual(value.qty, 1) def test_partial_transfer_serial_no_components_based_on_material_transfer(self): diff --git a/erpnext/crm/doctype/appointment_booking_settings/appointment_booking_settings.py b/erpnext/crm/doctype/appointment_booking_settings/appointment_booking_settings.py index 52869017b4e..9997f97dcc8 100644 --- a/erpnext/crm/doctype/appointment_booking_settings/appointment_booking_settings.py +++ b/erpnext/crm/doctype/appointment_booking_settings/appointment_booking_settings.py @@ -3,6 +3,7 @@ import datetime +import typing import frappe from frappe import _ @@ -36,7 +37,7 @@ class AppointmentBookingSettings(Document): success_redirect_url: DF.Data | None # end: auto-generated types - agent_list = [] # Hack + agent_list: typing.ClassVar[list] = [] # Hack min_date = "01/01/1970 " format_string = "%d/%m/%Y %H:%M:%S" diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py index 82075ad286e..80b156487bd 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py @@ -1580,7 +1580,7 @@ def get_items_for_material_requests(doc, warehouses=None, get_parent_warehouse_d so_item_details[sales_order][item_code] = details mr_items = [] - for sales_order, item_code in so_item_details.items(): + for sales_order in so_item_details: item_dict = so_item_details[sales_order] for details in item_dict.values(): bin_dict = get_bin_details(details, doc.company, warehouse) diff --git a/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py b/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py index 6d91246963f..85648d6b326 100644 --- a/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py +++ b/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py @@ -87,7 +87,7 @@ class ForecastingReport(ExponentialSmoothingForecast): entry.get(self.based_on_field) ) - for key, value in self.period_wise_data.items(): + for value in self.period_wise_data.values(): list_of_period_value = [value.get(p.key, 0) for p in self.period_list] if list_of_period_value: diff --git a/erpnext/patches/v12_0/update_due_date_in_gle.py b/erpnext/patches/v12_0/update_due_date_in_gle.py index a1c4f51ad01..693311001de 100644 --- a/erpnext/patches/v12_0/update_due_date_in_gle.py +++ b/erpnext/patches/v12_0/update_due_date_in_gle.py @@ -8,13 +8,11 @@ def execute(): frappe.reload_doc("accounts", "doctype", frappe.scrub(doctype)) frappe.db.sql( - """ UPDATE `tabGL Entry`, `tab{doctype}` + f""" UPDATE `tabGL Entry`, `tab{doctype}` SET `tabGL Entry`.due_date = `tab{doctype}`.due_date WHERE `tabGL Entry`.voucher_no = `tab{doctype}`.name and `tabGL Entry`.party is not null and `tabGL Entry`.voucher_type in ('Sales Invoice', 'Purchase Invoice', 'Journal Entry') - and `tabGL Entry`.account in (select name from `tabAccount` where account_type in ('Receivable', 'Payable'))""".format( # nosec - doctype=doctype - ) + and `tabGL Entry`.account in (select name from `tabAccount` where account_type in ('Receivable', 'Payable'))""" ) diff --git a/erpnext/selling/page/sales_funnel/sales_funnel.py b/erpnext/selling/page/sales_funnel/sales_funnel.py index 155d21ed5d1..24bb0d2fe71 100644 --- a/erpnext/selling/page/sales_funnel/sales_funnel.py +++ b/erpnext/selling/page/sales_funnel/sales_funnel.py @@ -100,7 +100,7 @@ def get_opp_by_lead_source(from_date, to_date, company): pivot_table = [] for sales_stage in sales_stages: row = [] - for source, sales_stage_values in summary.items(): + for sales_stage_values in summary.values(): row.append(flt(sales_stage_values.get(sales_stage))) pivot_table.append({"chartType": "bar", "name": sales_stage, "values": row}) diff --git a/erpnext/setup/doctype/holiday_list/test_holiday_list.py b/erpnext/setup/doctype/holiday_list/test_holiday_list.py index 21dacc624b6..0d3c35fb2cf 100644 --- a/erpnext/setup/doctype/holiday_list/test_holiday_list.py +++ b/erpnext/setup/doctype/holiday_list/test_holiday_list.py @@ -112,7 +112,13 @@ class TestHolidayList(unittest.TestCase): frappe.local.lang = lang -def make_holiday_list(name, from_date=getdate() - timedelta(days=10), to_date=getdate(), holiday_dates=None): +def make_holiday_list(name, from_date=None, to_date=None, holiday_dates=None): + if from_date is None: + from_date = getdate() - timedelta(days=10) + + if to_date is None: + to_date = getdate() + frappe.delete_doc_if_exists("Holiday List", name, force=1) doc = frappe.get_doc( { diff --git a/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py b/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py index 735e4989bde..c9c3c837ceb 100644 --- a/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py +++ b/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py @@ -486,12 +486,7 @@ def is_deletion_doc_running(company: str | None = None, err_msg: str | None = No def check_for_running_deletion_job(doc, method=None): # Check if DocType has 'company' field df = qb.DocType("DocField") - if ( - not_allowed := qb.from_(df) - .select(df.parent) - .where((df.fieldname == "company") & (df.parent == doc.doctype)) - .run() - ): + if qb.from_(df).select(df.parent).where((df.fieldname == "company") & (df.parent == doc.doctype)).run(): is_deletion_doc_running( doc.company, _("Cannot make any transactions until the deletion job is completed") ) diff --git a/erpnext/stock/doctype/batch/test_batch.py b/erpnext/stock/doctype/batch/test_batch.py index 1adffaed62e..3f37b7bf098 100644 --- a/erpnext/stock/doctype/batch/test_batch.py +++ b/erpnext/stock/doctype/batch/test_batch.py @@ -117,10 +117,10 @@ class TestBatch(FrappeTestCase): self.assertTrue(receipt2.items[0].serial_and_batch_bundle) batchwise_qty = frappe._dict({}) - for receipt in [receipt, receipt2]: - batch_no = get_batch_from_bundle(receipt.items[0].serial_and_batch_bundle) - key = (batch_no, receipt.items[0].warehouse) - batchwise_qty[key] = receipt.items[0].qty + for r in [receipt, receipt2]: + batch_no = get_batch_from_bundle(r.items[0].serial_and_batch_bundle) + key = (batch_no, r.items[0].warehouse) + batchwise_qty[key] = r.items[0].qty batches = get_batch_qty(batch_no) for d in batches: diff --git a/erpnext/stock/doctype/item_variant_settings/item_variant_settings.py b/erpnext/stock/doctype/item_variant_settings/item_variant_settings.py index 3ee46e4887a..277042c9d6f 100644 --- a/erpnext/stock/doctype/item_variant_settings/item_variant_settings.py +++ b/erpnext/stock/doctype/item_variant_settings/item_variant_settings.py @@ -1,6 +1,6 @@ # Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors # For license information, please see license.txt - +import typing import frappe from frappe import _ @@ -23,7 +23,7 @@ class ItemVariantSettings(Document): fields: DF.Table[VariantField] # end: auto-generated types - invalid_fields_for_copy_fields_in_variants = ["barcodes"] + invalid_fields_for_copy_fields_in_variants: typing.ClassVar[list] = ["barcodes"] def set_default_fields(self): self.fields = [] diff --git a/erpnext/stock/doctype/packed_item/test_packed_item.py b/erpnext/stock/doctype/packed_item/test_packed_item.py index 3f87cede7d6..24a302f009f 100644 --- a/erpnext/stock/doctype/packed_item/test_packed_item.py +++ b/erpnext/stock/doctype/packed_item/test_packed_item.py @@ -182,12 +182,12 @@ class TestPackedItem(FrappeTestCase): def sort_function(p): return p.parent_item, p.item_code, p.qty - for sent, returned in zip( + for sent_item, returned_item in zip( sorted(original, key=sort_function), sorted(returned, key=sort_function), strict=False ): - self.assertEqual(sent.item_code, returned.item_code) - self.assertEqual(sent.parent_item, returned.parent_item) - self.assertEqual(sent.qty, -1 * returned.qty) + self.assertEqual(sent_item.item_code, returned_item.item_code) + self.assertEqual(sent_item.parent_item, returned_item.parent_item) + self.assertEqual(sent_item.qty, -1 * returned_item.qty) def test_returning_full_bundles(self): from erpnext.stock.doctype.delivery_note.delivery_note import make_sales_return diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py index 208f2c35ba7..e3dbdb5726b 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.py +++ b/erpnext/stock/doctype/pick_list/pick_list.py @@ -4,7 +4,6 @@ import json from collections import OrderedDict, defaultdict from itertools import groupby -from typing import Dict, List import frappe from frappe import _ diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py index 864817c7375..6c4c825c072 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -2,10 +2,9 @@ # License: GNU General Public License v3. See license.txt -import frappe from frappe.permissions import add_user_permission, remove_user_permission from frappe.tests.utils import FrappeTestCase, change_settings -from frappe.utils import add_days, flt, nowdate, nowtime, today +from frappe.utils import add_days, flt, nowtime, today from erpnext.accounts.doctype.account.test_account import get_inventory_account from erpnext.stock.doctype.item.test_item import ( @@ -530,10 +529,10 @@ class TestStockEntry(FrappeTestCase): self.assertTrue(sle) sle.sort(key=lambda x: x[1]) - for i, sle in enumerate(sle): - self.assertEqual(expected_sle[i][0], sle[0]) - self.assertEqual(expected_sle[i][1], sle[1]) - self.assertEqual(expected_sle[i][2], sle[2]) + for i, sle_value in enumerate(sle): + self.assertEqual(expected_sle[i][0], sle_value[0]) + self.assertEqual(expected_sle[i][1], sle_value[1]) + self.assertEqual(expected_sle[i][2], sle_value[2]) def check_gl_entries(self, voucher_type, voucher_no, expected_gl_entries): expected_gl_entries.sort(key=lambda x: x[0]) diff --git a/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py index 6c12b3676c8..ce50155ffd5 100644 --- a/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py +++ b/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py @@ -915,14 +915,14 @@ class TestStockLedgerEntry(FrappeTestCase, StockTestMixin): receipt.submit() expected_queues = [] - for idx, rate in enumerate(rates, start=1): + for idx in range(1, len(rates) + 1): expected_queues.append({"stock_queue": [[10, 10 * i] for i in range(1, idx + 1)]}) self.assertSLEs(receipt, expected_queues) transfer = make_stock_entry( item_code=item.name, source=source, target=target, qty=10, do_not_save=True, rate=10 ) - for rate in rates[1:]: + for _ in rates[1:]: row = frappe.copy_doc(transfer.items[0], ignore_no_copy=False) transfer.append("items", row) @@ -951,7 +951,7 @@ class TestStockLedgerEntry(FrappeTestCase, StockTestMixin): repack = make_stock_entry( item_code=rm.name, source=warehouse, qty=10, do_not_save=True, rate=10, purpose="Repack" ) - for rate in rates[1:]: + for _ in rates[1:]: row = frappe.copy_doc(repack.items[0], ignore_no_copy=False) repack.append("items", row) diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py index 2ccd881b7c6..ccd7f64e6e7 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -743,9 +743,7 @@ class StockReconciliation(StockController): data.incoming_rate = (data.total_amount) / data.actual_qty - for key, value in merge_similar_entries.items(): - new_sl_entries.append(value) - + new_sl_entries.extend(merge_similar_entries.values()) return new_sl_entries def get_gl_entries(self, warehouse_account=None): diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py index 6b31910a523..6dcd3b6f484 100644 --- a/erpnext/stock/doctype/warehouse/warehouse.py +++ b/erpnext/stock/doctype/warehouse/warehouse.py @@ -217,7 +217,7 @@ def get_child_warehouses(warehouse): from frappe.utils.nestedset import get_descendants_of children = get_descendants_of("Warehouse", warehouse, ignore_permissions=True, order_by="lft") - return children + [warehouse] # append self for backward compatibility + return [*children, warehouse] # append self for backward compatibility def get_warehouses_based_on_account(account, company=None): diff --git a/erpnext/stock/report/cogs_by_item_group/cogs_by_item_group.py b/erpnext/stock/report/cogs_by_item_group/cogs_by_item_group.py index b3c8e93e4e1..07119411304 100644 --- a/erpnext/stock/report/cogs_by_item_group/cogs_by_item_group.py +++ b/erpnext/stock/report/cogs_by_item_group/cogs_by_item_group.py @@ -3,7 +3,6 @@ import datetime from collections import OrderedDict -from typing import Union import frappe from frappe import _ @@ -15,7 +14,7 @@ Filters = frappe._dict Row = frappe._dict Data = list[Row] Columns = list[dict[str, str]] -DateTime = Union[datetime.date, datetime.datetime] +DateTime = datetime.date | datetime.datetime FilteredEntries = list[dict[str, str | float | DateTime | None]] ItemGroupsDict = dict[tuple[int, int], dict[str, str | int]] SVDList = list[frappe._dict]