refactor(treewide): formatting and ruff fixes, + manually enabled F401

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
Akhil Narang
2024-03-27 11:37:26 +05:30
parent 8afb7790de
commit 3effaf21ef
574 changed files with 4135 additions and 6276 deletions

View File

@@ -1,18 +1,15 @@
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
import unittest
import frappe
from frappe import qb
from frappe.query_builder.functions import Sum
from frappe.tests.utils import FrappeTestCase, change_settings
from frappe.utils import add_days, flt, getdate, nowdate
from frappe.tests.utils import FrappeTestCase
from frappe.utils import add_days, getdate, nowdate
from erpnext import get_default_cost_center
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry
from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_entry
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.accounts.party import get_party_account
from erpnext.stock.doctype.item.test_item import create_item
@@ -173,9 +170,7 @@ 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=nowdate(), customer=None):
"""
Helper function to populate default values in payment entry
"""
@@ -293,9 +288,7 @@ class TestAccountsController(FrappeTestCase):
.run(as_dict=True)[0]
)
self.assertEqual(outstanding, current_outstanding.outstanding)
self.assertEqual(
outstanding_in_account_currency, current_outstanding.outstanding_in_account_currency
)
self.assertEqual(outstanding_in_account_currency, current_outstanding.outstanding_in_account_currency)
def test_10_payment_against_sales_invoice(self):
# Sales Invoice in Foreign Currency
@@ -401,7 +394,6 @@ class TestAccountsController(FrappeTestCase):
adv.reload()
# sales invoice with advance(partial amount)
rate = 80
rate_in_account_currency = 1
si = self.create_sales_invoice(
qty=2, conversion_rate=80, rate=rate_in_account_currency, do_not_submit=True
@@ -788,7 +780,9 @@ class TestAccountsController(FrappeTestCase):
self.assert_ledger_outstanding(si.doctype, si.name, 0.0, 0.0)
# Exchange Gain/Loss Journal should've been created.
exc_je_for_si = [x for x in self.get_journals_for(si.doctype, si.name) if x.parent != adv.name]
exc_je_for_si = [
x for x in self.get_journals_for(si.doctype, si.name) if x.parent != adv.name
]
exc_je_for_adv = self.get_journals_for(adv.doctype, adv.name)
self.assertNotEqual(exc_je_for_si, [])
self.assertEqual(len(exc_je_for_si), 1)
@@ -1253,7 +1247,9 @@ class TestAccountsController(FrappeTestCase):
with self.subTest(x=x):
self.assertEqual(
[self.cost_center, self.cost_center],
frappe.db.get_all("Journal Entry Account", filters={"parent": x.parent}, pluck="cost_center"),
frappe.db.get_all(
"Journal Entry Account", filters={"parent": x.parent}, pluck="cost_center"
),
)
frappe.db.set_value("Company", self.company, "cost_center", cc)
@@ -1382,13 +1378,14 @@ class TestAccountsController(FrappeTestCase):
with self.subTest(x=x):
self.assertEqual(
[cr_note.department, cr_note.department],
frappe.db.get_all("Journal Entry Account", filters={"parent": x.parent}, pluck="department"),
frappe.db.get_all(
"Journal Entry Account", filters={"parent": x.parent}, pluck="department"
),
)
def test_92_dimension_inhertiance_exc_gain_loss(self):
# Sales Invoice in Foreign Currency
self.setup_dimensions()
rate = 80
rate_in_account_currency = 1
dpt = "Research & Development"

View File

@@ -29,7 +29,6 @@ class TestMapper(unittest.TestCase):
self.assertEqual(set(d for d in src_items), set(d.item_code for d in updated_so.items))
def make_quotation(self, item_list, customer):
qtn = frappe.get_doc(
{
"doctype": "Quotation",

View File

@@ -25,7 +25,7 @@ class TestTaxes(unittest.TestCase):
"account_name": uuid4(),
"account_type": "Tax",
"company": self.company.name,
"parent_account": "Duties and Taxes - {self.company.abbr}".format(self=self),
"parent_account": f"Duties and Taxes - {self.company.abbr}",
}
).insert()
self.item_group = frappe.get_doc(

View File

@@ -7,13 +7,10 @@ from erpnext.controllers import queries
def add_default_params(func, doctype):
return partial(
func, doctype=doctype, txt="", searchfield="name", start=0, page_len=20, filters=None
)
return partial(func, doctype=doctype, txt="", searchfield="name", start=0, page_len=20, filters=None)
class TestQueries(unittest.TestCase):
# All tests are based on doctype/test_records.json
def assert_nested_in(self, item, container):

View File

@@ -16,8 +16,6 @@ from erpnext.controllers.subcontracting_controller import (
from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom
from erpnext.stock.doctype.item.test_item import make_item
from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle import (
get_batch_from_bundle,
get_serial_nos_from_bundle,
make_serial_batch_bundle,
)
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
@@ -351,7 +349,6 @@ class TestSubcontractingController(FrappeTestCase):
- Create the 3 SCR against the SCO and split Subcontracted Items into two batches.
- Keep the qty as 2 for Subcontracted Item in the SCR.
"""
from erpnext.stock.serial_batch_bundle import get_batch_nos
set_backflush_based_on("BOM")
service_items = [
@@ -434,7 +431,7 @@ class TestSubcontractingController(FrappeTestCase):
scr1.set_missing_values()
scr1.submit()
for key, value in get_supplied_items(scr1).items():
for _key, value in get_supplied_items(scr1).items():
self.assertEqual(value.qty, 4)
frappe.flags.add_debugger = True
@@ -446,7 +443,7 @@ class TestSubcontractingController(FrappeTestCase):
scr2.set_missing_values()
scr2.submit()
for key, value in get_supplied_items(scr2).items():
for _key, value in get_supplied_items(scr2).items():
self.assertEqual(value.qty, 4)
scr3 = make_subcontracting_receipt(sco.name)
@@ -456,7 +453,7 @@ class TestSubcontractingController(FrappeTestCase):
scr3.set_missing_values()
scr3.submit()
for key, value in get_supplied_items(scr3).items():
for _key, value in get_supplied_items(scr3).items():
self.assertEqual(value.qty, 2)
def test_item_with_batch_based_on_material_transfer(self):
@@ -700,9 +697,7 @@ class TestSubcontractingController(FrappeTestCase):
scr1 = make_subcontracting_receipt(sco.name)
scr1.save()
bundle = frappe.get_doc(
"Serial and Batch Bundle", scr1.supplied_items[0].serial_and_batch_bundle
)
bundle = frappe.get_doc("Serial and Batch Bundle", scr1.supplied_items[0].serial_and_batch_bundle)
original_serial_no = ""
for row in bundle.entries:
if row.idx == 1:
@@ -773,7 +768,6 @@ class TestSubcontractingController(FrappeTestCase):
scr1.items[0].qty = 5
scr1.save()
transferred_batch_no = ""
for key, value in get_supplied_items(scr1).items():
details = itemwise_details.get(key)
self.assertEqual(value.qty, 3)
@@ -1139,9 +1133,7 @@ def make_stock_in_entry(**args):
def update_item_details(child_row, details):
details.qty += (
child_row.get("qty")
if child_row.doctype == "Stock Entry Detail"
else child_row.get("consumed_qty")
child_row.get("qty") if child_row.doctype == "Stock Entry Detail" else child_row.get("consumed_qty")
)
details.use_serial_batch_fields = child_row.get("use_serial_batch_fields")
@@ -1152,7 +1144,9 @@ def update_item_details(child_row, details):
details.serial_no.append(row.serial_no)
if row.batch_no:
details.batch_no[row.batch_no] += row.qty * (-1 if doc.type_of_transaction == "Outward" else 1)
details.batch_no[row.batch_no] += row.qty * (
-1 if doc.type_of_transaction == "Outward" else 1
)
else:
if child_row.serial_no:
details.serial_no.extend(get_serial_nos(child_row.serial_no))
@@ -1268,7 +1262,9 @@ def make_raw_materials():
make_item(item, properties)
def make_service_item(item, properties={}):
def make_service_item(item, properties=None):
if properties is None:
properties = {}
if not frappe.db.exists("Item", item):
properties.update({"is_stock_item": 0})
make_item(item, properties)
@@ -1316,9 +1312,7 @@ def make_bom_for_subcontracted_items():
def set_backflush_based_on(based_on):
frappe.db.set_single_value(
"Buying Settings", "backflush_raw_materials_of_subcontract_based_on", based_on
)
frappe.db.set_single_value("Buying Settings", "backflush_raw_materials_of_subcontract_based_on", based_on)
def get_subcontracting_order(**args):

View File

@@ -44,7 +44,10 @@ class TestUtils(unittest.TestCase):
item_code="_Test Item", qty=1, basic_rate=200, s_warehouse="_Test Warehouse - _TC"
),
frappe._dict(
item_code="_Test FG Item", qty=4, t_warehouse="_Test Warehouse 1 - _TC", is_finished_item=1
item_code="_Test FG Item",
qty=4,
t_warehouse="_Test Warehouse 1 - _TC",
is_finished_item=1,
),
],
)