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

@@ -11,9 +11,7 @@ def execute():
if frappe.db.has_column("Company", "default_terms"):
rename_field("Company", "default_terms", "default_selling_terms")
for company in frappe.get_all(
"Company", ["name", "default_selling_terms", "default_buying_terms"]
):
for company in frappe.get_all("Company", ["name", "default_selling_terms", "default_buying_terms"]):
if company.default_selling_terms and not company.default_buying_terms:
frappe.db.set_value(
"Company", company.name, "default_buying_terms", company.default_selling_terms

View File

@@ -3,7 +3,6 @@ from frappe.custom.doctype.custom_field.custom_field import create_custom_field
def execute():
frappe.reload_doc("accounts", "doctype", "accounting_dimension")
accounting_dimensions = frappe.db.sql(
@@ -17,7 +16,6 @@ def execute():
count = 1
for d in accounting_dimensions:
if count % 2 == 0:
insert_after_field = "dimension_col_break"
else:
@@ -31,7 +29,6 @@ def execute():
"Expense Claim Detail",
"Expense Taxes and Charges",
]:
field = frappe.db.get_value("Custom Field", {"dt": doctype, "fieldname": d.fieldname})
if field:

View File

@@ -4,7 +4,6 @@ from erpnext.regional.united_states.setup import make_custom_fields
def execute():
frappe.reload_doc("accounts", "doctype", "allowed_to_transact_with", force=True)
frappe.reload_doc("accounts", "doctype", "pricing_rule_detail", force=True)
frappe.reload_doc("crm", "doctype", "lost_reason_detail", force=True)

View File

@@ -16,9 +16,7 @@ def execute():
and qo.valid_till < so.transaction_date""" # check if SO was created after quotation expired
frappe.db.sql(
"""UPDATE `tabQuotation` qo SET qo.status = 'Expired' WHERE {cond} and exists({invalid_so_against_quo})""".format(
cond=cond, invalid_so_against_quo=invalid_so_against_quo
)
f"""UPDATE `tabQuotation` qo SET qo.status = 'Expired' WHERE {cond} and exists({invalid_so_against_quo})"""
)
valid_so_against_quo = """
@@ -31,7 +29,5 @@ def execute():
and qo.valid_till >= so.transaction_date""" # check if SO was created before quotation expired
frappe.db.sql(
"""UPDATE `tabQuotation` qo SET qo.status = 'Closed' WHERE {cond} and exists({valid_so_against_quo})""".format(
cond=cond, valid_so_against_quo=valid_so_against_quo
)
f"""UPDATE `tabQuotation` qo SET qo.status = 'Closed' WHERE {cond} and exists({valid_so_against_quo})"""
)

View File

@@ -30,8 +30,6 @@ def execute():
"""
INSERT INTO `tabItem Manufacturer`
(`name`, `item_code`, `manufacturer`, `manufacturer_part_no`, `creation`, `owner`)
VALUES {}""".format(
", ".join(["%s"] * len(item_manufacturer))
),
VALUES {}""".format(", ".join(["%s"] * len(item_manufacturer))),
tuple(item_manufacturer),
)

View File

@@ -16,7 +16,7 @@ def execute():
SET b.swift_number = ba.swift_number WHERE b.name = ba.bank
"""
)
except Exception as e:
except Exception:
frappe.log_error("Bank to Bank Account patch migration failed")
frappe.reload_doc("accounts", "doctype", "bank_account")

View File

@@ -29,12 +29,10 @@ def move_credit_limit_to_child_table():
fields = ", bypass_credit_limit_check_at_sales_order"
credit_limit_records = frappe.db.sql(
"""
SELECT name, credit_limit {0}
FROM `tab{1}` where credit_limit > 0
""".format(
fields, doctype
),
f"""
SELECT name, credit_limit {fields}
FROM `tab{doctype}` where credit_limit > 0
""",
as_dict=1,
) # nosec

View File

@@ -80,11 +80,9 @@ def execute():
for dt in doctypes:
for d in frappe.db.sql(
"""select name, parenttype, parent, item_code, item_tax_rate from `tab{0} Item`
f"""select name, parenttype, parent, item_code, item_tax_rate from `tab{dt} Item`
where ifnull(item_tax_rate, '') not in ('', '{{}}')
and item_tax_template is NULL""".format(
dt
),
and item_tax_template is NULL""",
as_dict=1,
):
item_tax_map = json.loads(d.item_tax_rate)
@@ -145,13 +143,23 @@ def get_item_tax_template(
if not parent_account:
parent_account = frappe.db.get_value(
"Account",
filters={"account_type": "Tax", "root_type": "Liability", "is_group": 0, "company": company},
filters={
"account_type": "Tax",
"root_type": "Liability",
"is_group": 0,
"company": company,
},
fieldname="parent_account",
)
if not parent_account:
parent_account = frappe.db.get_value(
"Account",
filters={"account_type": "Tax", "root_type": "Liability", "is_group": 1, "company": company},
filters={
"account_type": "Tax",
"root_type": "Liability",
"is_group": 1,
"company": company,
},
)
filters = {
"account_name": account_name,

View File

@@ -18,9 +18,7 @@ def execute():
WHERE
`tab{child_doc}`.parent = `tab{parent_doc}`.name
and `tab{parent_doc}`.distribution_id is not null and `tab{parent_doc}`.distribution_id != ''
""".format(
parent_doc=d, child_doc="Target Detail"
)
""".format(parent_doc=d, child_doc="Target Detail")
)
frappe.delete_doc("Report", "Sales Partner-wise Transaction Summary")

View File

@@ -17,16 +17,14 @@ def execute():
if not affected_purchase_receipts:
return
logger.info(
"purchase_receipt_status: begin patch, PR count: {}".format(len(affected_purchase_receipts))
)
logger.info(f"purchase_receipt_status: begin patch, PR count: {len(affected_purchase_receipts)}")
frappe.reload_doc("stock", "doctype", "Purchase Receipt")
frappe.reload_doc("stock", "doctype", "Purchase Receipt Item")
for pr in affected_purchase_receipts:
pr_name = pr[0]
logger.info("purchase_receipt_status: patching PR - {}".format(pr_name))
logger.info(f"purchase_receipt_status: patching PR - {pr_name}")
pr_doc = frappe.get_doc("Purchase Receipt", pr_name)

View File

@@ -6,12 +6,8 @@ import frappe
def _rename_single_field(**kwargs):
count = frappe.db.sql(
"SELECT COUNT(*) FROM tabSingles WHERE doctype='{doctype}' AND field='{new_name}';".format(
**kwargs
)
)[0][
0
] # nosec
"SELECT COUNT(*) FROM tabSingles WHERE doctype='{doctype}' AND field='{new_name}';".format(**kwargs)
)[0][0] # nosec
if count == 0:
frappe.db.sql(
"UPDATE tabSingles SET field='{new_name}' WHERE doctype='{doctype}' AND field='{old_name}';".format(
@@ -22,7 +18,5 @@ def _rename_single_field(**kwargs):
def execute():
_rename_single_field(doctype="Bank Clearance", old_name="bank_account", new_name="account")
_rename_single_field(
doctype="Bank Clearance", old_name="bank_account_no", new_name="bank_account"
)
_rename_single_field(doctype="Bank Clearance", old_name="bank_account_no", new_name="bank_account")
frappe.reload_doc("Accounts", "doctype", "Bank Clearance")

View File

@@ -41,35 +41,29 @@ def execute():
cond = " AND parent_doc.update_stock = 1"
data = frappe.db.sql(
""" SELECT parent_doc.name as name, child_doc.name as child_name
f""" SELECT parent_doc.name as name, child_doc.name as child_name
FROM
`tab{doctype}` parent_doc, `tab{doctype} Item` child_doc
WHERE
parent_doc.name = child_doc.parent AND parent_doc.docstatus < 2
AND child_doc.target_warehouse is not null AND child_doc.target_warehouse != ''
AND child_doc.creation > '2020-04-16' {cond}
""".format(
doctype=doctype, cond=cond
),
""",
as_dict=1,
)
if data:
names = [d.child_name for d in data]
frappe.db.sql(
""" UPDATE `tab{0} Item` set target_warehouse = null
WHERE name in ({1}) """.format(
doctype, ",".join(["%s"] * len(names))
),
""" UPDATE `tab{} Item` set target_warehouse = null
WHERE name in ({}) """.format(doctype, ",".join(["%s"] * len(names))),
tuple(names),
)
frappe.db.sql(
""" UPDATE `tabPacked Item` set target_warehouse = null
WHERE parenttype = '{0}' and parent_detail_docname in ({1})
""".format(
doctype, ",".join(["%s"] * len(names))
),
WHERE parenttype = '{}' and parent_detail_docname in ({})
""".format(doctype, ",".join(["%s"] * len(names))),
tuple(names),
)

View File

@@ -2,17 +2,14 @@ import frappe
def execute():
frappe.reload_doc("selling", "doctype", "sales_order_item", force=True)
frappe.reload_doc("buying", "doctype", "purchase_order_item", force=True)
for doctype in ("Sales Order Item", "Purchase Order Item"):
frappe.db.sql(
"""
UPDATE `tab{0}`
f"""
UPDATE `tab{doctype}`
SET against_blanket_order = 1
WHERE ifnull(blanket_order, '') != ''
""".format(
doctype
)
"""
)

View File

@@ -4,6 +4,4 @@ import frappe
def execute():
frappe.reload_doc("accounts", "doctype", "accounts_settings")
frappe.db.set_single_value(
"Accounts Settings", "automatically_process_deferred_accounting_entry", 1
)
frappe.db.set_single_value("Accounts Settings", "automatically_process_deferred_accounting_entry", 1)

View File

@@ -12,6 +12,5 @@ def execute():
fields=["sales_order", "sales_order_item"],
filters={"sales_order": ("!=", ""), "sales_order_item": ("!=", "")},
):
# update produced qty in sales order
update_produced_qty_in_so_item(d.sales_order, d.sales_order_item)

View File

@@ -4,7 +4,6 @@ import frappe
def execute():
frappe.reload_doc("stock", "doctype", "delivery_note_item", force=True)
frappe.reload_doc("stock", "doctype", "purchase_receipt_item", force=True)
@@ -50,14 +49,12 @@ def execute():
Format => { 'document' : ['return_document_1','return_document_2'] }"""
return_against_documents = frappe.db.sql(
"""
f"""
SELECT
return_against as document, name as return_document
FROM `tab{doctype}`
WHERE
is_return = 1 and docstatus = 1""".format(
doctype=doctype
),
is_return = 1 and docstatus = 1""",
as_dict=1,
) # nosec
@@ -72,7 +69,7 @@ def execute():
return_document_map = defaultdict(list)
detail_field = "purchase_receipt_item" if doctype == "Purchase Receipt" else "dn_detail"
child_doc = frappe.scrub("{0} Item".format(doctype))
child_doc = frappe.scrub(f"{doctype} Item")
frappe.reload_doc("stock", "doctype", child_doc)
return_document_map = make_return_document_map(doctype, return_document_map)
@@ -89,7 +86,8 @@ def execute():
for return_item in return_doc_items:
for doc_item in doc_items:
if (
row_is_mappable(doc_item, return_item, detail_field) and doc_item.get("name") not in mapped
row_is_mappable(doc_item, return_item, detail_field)
and doc_item.get("name") not in mapped
):
map_rows(doc_item, return_item, detail_field, doctype)
mapped.append(doc_item.get("name"))

View File

@@ -2,7 +2,6 @@ import frappe
def execute():
frappe.db.sql(
""" UPDATE `tabQuotation` set status = 'Open'
where docstatus = 1 and status = 'Submitted' """

View File

@@ -28,7 +28,6 @@ def create_stock_entry_types():
"Repack",
"Send to Subcontractor",
]:
ste_type = frappe.get_doc({"doctype": "Stock Entry Type", "name": purpose, "purpose": purpose})
try:

View File

@@ -6,21 +6,17 @@ def execute():
frappe.reload_doc("selling", "doctype", "sales_order_item")
for doctype in ["Sales Order", "Material Request"]:
condition = (
" and child_doc.stock_qty > child_doc.produced_qty and ROUND(doc.per_delivered, 2) < 100"
)
condition = " and child_doc.stock_qty > child_doc.produced_qty and ROUND(doc.per_delivered, 2) < 100"
if doctype == "Material Request":
condition = " and doc.per_ordered < 100 and doc.material_request_type = 'Manufacture'"
frappe.db.sql(
""" UPDATE `tab{doc}` as doc, `tab{doc} Item` as child_doc, tabItem as item
f""" UPDATE `tab{doctype}` as doc, `tab{doctype} Item` as child_doc, tabItem as item
SET
child_doc.bom_no = item.default_bom
WHERE
child_doc.item_code = item.name and child_doc.docstatus < 2
and child_doc.parent = doc.name
and item.default_bom is not null and item.default_bom != '' {cond}
""".format(
doc=doctype, cond=condition
)
and item.default_bom is not null and item.default_bom != '' {condition}
"""
)

View File

@@ -17,20 +17,16 @@ def execute():
continue
frappe.db.sql(
"""
f"""
UPDATE `tab{doctype}`
SET is_cancelled = 0
where is_cancelled in ('', 'No') or is_cancelled is NULL""".format(
doctype=doctype
)
where is_cancelled in ('', 'No') or is_cancelled is NULL"""
)
frappe.db.sql(
"""
f"""
UPDATE `tab{doctype}`
SET is_cancelled = 1
where is_cancelled = 'Yes'""".format(
doctype=doctype
)
where is_cancelled = 'Yes'"""
)
frappe.reload_doc(module, "doctype", frappe.scrub(doctype))

View File

@@ -19,8 +19,7 @@ def execute():
"""
UPDATE `tabCustom Field`
SET owner = 'Administrator'
WHERE fieldname = %s
AND dt IN (%s)"""
% ("%s", ", ".join(["%s"] * len(doclist))), # nosec
tuple([dimension.fieldname] + doclist),
WHERE fieldname = {}
AND dt IN ({})""".format("%s", ", ".join(["%s"] * len(doclist))), # nosec
tuple([dimension.fieldname, *doclist]),
)

View File

@@ -8,7 +8,6 @@ parentfield = {"item_code": "items", "item_group": "item_groups", "brand": "bran
def execute():
if not frappe.get_all("Pricing Rule", limit=1):
return
@@ -33,20 +32,16 @@ def execute():
child_doctype = doctype + " Item"
frappe.db.sql(
""" UPDATE `tab{child_doctype}` SET pricing_rules = pricing_rule
f""" UPDATE `tab{child_doctype}` SET pricing_rules = pricing_rule
WHERE docstatus < 2 and pricing_rule is not null and pricing_rule != ''
""".format(
child_doctype=child_doctype
)
"""
)
data = frappe.db.sql(
""" SELECT pricing_rule, name, parent,
f""" SELECT pricing_rule, name, parent,
parenttype, creation, modified, docstatus, modified_by, owner, name
FROM `tab{child_doc}` where docstatus < 2 and pricing_rule is not null
and pricing_rule != ''""".format(
child_doc=child_doctype
),
FROM `tab{child_doctype}` where docstatus < 2 and pricing_rule is not null
and pricing_rule != ''""",
as_dict=1,
)
@@ -73,9 +68,7 @@ def execute():
""" INSERT INTO
`tabPricing Rule Detail` (`pricing_rule`, `child_docname`, `parent`, `parentfield`, `parenttype`,
`creation`, `modified`, `docstatus`, `modified_by`, `owner`, `name`)
VALUES {values} """.format(
values=", ".join(["%s"] * len(values))
),
VALUES {values} """.format(values=", ".join(["%s"] * len(values))),
tuple(values),
)
@@ -116,8 +109,6 @@ def execute():
""" INSERT INTO
`tab{doctype}` ({field}, parent, parentfield, parenttype, creation, modified,
owner, modified_by, name)
VALUES {values} """.format(
doctype=doctype, field=field, values=", ".join(["%s"] * len(values))
),
VALUES {values} """.format(doctype=doctype, field=field, values=", ".join(["%s"] * len(values))),
tuple(values),
)