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 9eeedd8515
commit 960ef14b7a
575 changed files with 4086 additions and 6211 deletions

View File

@@ -28,7 +28,7 @@ class BuyingController(SubcontractingController):
def validate(self):
self.set_rate_for_standalone_debit_note()
super(BuyingController, self).validate()
super().validate()
if getattr(self, "supplier", None) and not self.supplier_name:
self.supplier_name = frappe.db.get_value("Supplier", self.supplier, "supplier_name")
@@ -45,9 +45,7 @@ class BuyingController(SubcontractingController):
if self.doctype == "Purchase Invoice":
self.validate_purchase_receipt_if_update_stock()
if self.doctype == "Purchase Receipt" or (
self.doctype == "Purchase Invoice" and self.update_stock
):
if self.doctype == "Purchase Receipt" or (self.doctype == "Purchase Invoice" and self.update_stock):
# self.validate_purchase_return()
self.validate_rejected_warehouse()
self.validate_accepted_rejected_qty()
@@ -64,12 +62,10 @@ class BuyingController(SubcontractingController):
self.set_serial_and_batch_bundle()
def onload(self):
super(BuyingController, self).onload()
super().onload()
self.set_onload(
"backflush_based_on",
frappe.db.get_single_value(
"Buying Settings", "backflush_raw_materials_of_subcontract_based_on"
),
frappe.db.get_single_value("Buying Settings", "backflush_raw_materials_of_subcontract_based_on"),
)
def create_package_for_transfer(self) -> None:
@@ -128,7 +124,7 @@ class BuyingController(SubcontractingController):
row.margin_rate_or_amount = 0.0
def set_missing_values(self, for_validate=False):
super(BuyingController, self).set_missing_values(for_validate)
super().set_missing_values(for_validate)
self.set_supplier_from_item_default()
self.set_price_list_currency("Buying")
@@ -188,9 +184,7 @@ class BuyingController(SubcontractingController):
if self.doctype not in ["Purchase Receipt", "Purchase Invoice"] or not self.is_return:
return
purchase_doc_field = (
"purchase_receipt" if self.doctype == "Purchase Receipt" else "purchase_invoice"
)
purchase_doc_field = "purchase_receipt" if self.doctype == "Purchase Receipt" else "purchase_invoice"
not_cancelled_asset = []
if self.return_against:
not_cancelled_asset = [
@@ -508,7 +502,6 @@ class BuyingController(SubcontractingController):
pr_qty = flt(flt(d.qty) * flt(d.conversion_factor), d.precision("stock_qty"))
if pr_qty:
if d.from_warehouse and (
(not cint(self.is_return) and self.docstatus == 1)
or (cint(self.is_return) and self.docstatus == 2)
@@ -546,7 +539,9 @@ class BuyingController(SubcontractingController):
"serial_and_batch_bundle": (
d.serial_and_batch_bundle
if not self.is_internal_transfer() or self.is_return
else self.get_package_for_target_warehouse(d, type_of_transaction=type_of_transaction)
else self.get_package_for_target_warehouse(
d, type_of_transaction=type_of_transaction
)
),
},
)
@@ -604,7 +599,9 @@ class BuyingController(SubcontractingController):
d,
{
"warehouse": d.rejected_warehouse,
"actual_qty": flt(flt(d.rejected_qty) * flt(d.conversion_factor), d.precision("stock_qty")),
"actual_qty": flt(
flt(d.rejected_qty) * flt(d.conversion_factor), d.precision("stock_qty")
),
"incoming_rate": 0.0,
"serial_and_batch_bundle": d.rejected_serial_and_batch_bundle,
},
@@ -670,7 +667,7 @@ class BuyingController(SubcontractingController):
update_last_purchase_rate(self, is_submit=1)
def on_cancel(self):
super(BuyingController, self).on_cancel()
super().on_cancel()
if self.get("is_return"):
return
@@ -695,7 +692,9 @@ class BuyingController(SubcontractingController):
"doctype": self.doctype,
"company": self.company,
"posting_date": (
self.schedule_date if self.doctype == "Material Request" else self.transaction_date
self.schedule_date
if self.doctype == "Material Request"
else self.transaction_date
),
}
)
@@ -727,17 +726,21 @@ class BuyingController(SubcontractingController):
asset = self.make_asset(d, is_grouped_asset=True)
created_assets.append(asset)
else:
for qty in range(cint(d.qty)):
for _qty in range(cint(d.qty)):
asset = self.make_asset(d)
created_assets.append(asset)
if len(created_assets) > 5:
# dont show asset form links if more than 5 assets are created
messages.append(
_("{} Assets created for {}").format(len(created_assets), frappe.bold(d.item_code))
_("{} Assets created for {}").format(
len(created_assets), frappe.bold(d.item_code)
)
)
else:
assets_link = list(map(lambda d: frappe.utils.get_link_to_form("Asset", d), created_assets))
assets_link = list(
map(lambda d: frappe.utils.get_link_to_form("Asset", d), created_assets)
)
assets_link = frappe.bold(",".join(assets_link))
is_plural = "s" if len(created_assets) != 1 else ""
@@ -748,9 +751,9 @@ class BuyingController(SubcontractingController):
)
else:
frappe.throw(
_("Row {}: Asset Naming Series is mandatory for the auto creation for item {}").format(
d.idx, frappe.bold(d.item_code)
)
_(
"Row {}: Asset Naming Series is mandatory for the auto creation for item {}"
).format(d.idx, frappe.bold(d.item_code))
)
else:
messages.append(
@@ -912,11 +915,9 @@ def validate_item_type(doc, fieldname, message):
invalid_items = [
d[0]
for d in frappe.db.sql(
"""
select item_code from tabItem where name in ({0}) and {1}=0
""".format(
item_list, fieldname
),
f"""
select item_code from tabItem where name in ({item_list}) and {fieldname}=0
""",
as_list=True,
)
]