refactor: simplify conditional logic

Command: `sourcery review --fix --enable de-morgan .`
This commit is contained in:
barredterra 2023-12-05 11:22:55 +01:00
parent 5da3e532c9
commit eb9ee3f79b
51 changed files with 104 additions and 85 deletions

View File

@ -36,7 +36,7 @@ def get_default_cost_center(company):
if not frappe.flags.company_cost_center:
frappe.flags.company_cost_center = {}
if not company in frappe.flags.company_cost_center:
if company not in frappe.flags.company_cost_center:
frappe.flags.company_cost_center[company] = frappe.get_cached_value(
"Company", company, "cost_center"
)
@ -47,7 +47,7 @@ def get_company_currency(company):
"""Returns the default company currency"""
if not frappe.flags.company_currency:
frappe.flags.company_currency = {}
if not company in frappe.flags.company_currency:
if company not in frappe.flags.company_currency:
frappe.flags.company_currency[company] = frappe.db.get_value(
"Company", company, "default_currency", cache=True
)
@ -81,7 +81,7 @@ def is_perpetual_inventory_enabled(company):
if not hasattr(frappe.local, "enable_perpetual_inventory"):
frappe.local.enable_perpetual_inventory = {}
if not company in frappe.local.enable_perpetual_inventory:
if company not in frappe.local.enable_perpetual_inventory:
frappe.local.enable_perpetual_inventory[company] = (
frappe.get_cached_value("Company", company, "enable_perpetual_inventory") or 0
)
@ -96,7 +96,7 @@ def get_default_finance_book(company=None):
if not hasattr(frappe.local, "default_finance_book"):
frappe.local.default_finance_book = {}
if not company in frappe.local.default_finance_book:
if company not in frappe.local.default_finance_book:
frappe.local.default_finance_book[company] = frappe.get_cached_value(
"Company", company, "default_finance_book"
)
@ -108,7 +108,7 @@ def get_party_account_type(party_type):
if not hasattr(frappe.local, "party_account_types"):
frappe.local.party_account_types = {}
if not party_type in frappe.local.party_account_types:
if party_type not in frappe.local.party_account_types:
frappe.local.party_account_types[party_type] = (
frappe.db.get_value("Party Type", party_type, "account_type") or ""
)

View File

@ -232,7 +232,7 @@ def calculate_monthly_amount(
if amount + already_booked_amount_in_account_currency > item.net_amount:
amount = item.net_amount - already_booked_amount_in_account_currency
if not (get_first_day(start_date) == start_date and get_last_day(end_date) == end_date):
if get_first_day(start_date) != start_date or get_last_day(end_date) != end_date:
partial_month = flt(date_diff(end_date, start_date)) / flt(
date_diff(get_last_day(end_date), get_first_day(start_date))
)

View File

@ -44,7 +44,7 @@ class ExchangeRateRevaluation(Document):
self.set_total_gain_loss()
def validate_rounding_loss_allowance(self):
if not (self.rounding_loss_allowance >= 0 and self.rounding_loss_allowance < 1):
if self.rounding_loss_allowance < 0 or self.rounding_loss_allowance >= 1:
frappe.throw(_("Rounding Loss Allowance should be between 0 and 1"))
def set_total_gain_loss(self):

View File

@ -631,7 +631,7 @@ class JournalEntry(AccountsController):
)
# set totals
if not d.reference_name in self.reference_totals:
if d.reference_name not in self.reference_totals:
self.reference_totals[d.reference_name] = 0.0
if self.voucher_type not in ("Deferred Revenue", "Deferred Expense"):

View File

@ -140,7 +140,7 @@ class TestLoyaltyProgram(unittest.TestCase):
"Loyalty Point Entry",
{"invoice_type": "Sales Invoice", "invoice": si.name, "customer": si.customer},
)
self.assertEqual(True, not (lpe is None))
self.assertEqual(True, lpe is not None)
# cancelling sales invoice
si.cancel()

View File

@ -369,12 +369,12 @@ class PaymentEntry(AccountsController):
self.set(self.party_account_field, party_account)
self.party_account = party_account
if self.paid_from and not (self.paid_from_account_currency or self.paid_from_account_balance):
if self.paid_from and not self.paid_from_account_currency and not self.paid_from_account_balance:
acc = get_account_details(self.paid_from, self.posting_date, self.cost_center)
self.paid_from_account_currency = acc.account_currency
self.paid_from_account_balance = acc.account_balance
if self.paid_to and not (self.paid_to_account_currency or self.paid_to_account_balance):
if self.paid_to and not self.paid_to_account_currency and not self.paid_to_account_balance:
acc = get_account_details(self.paid_to, self.posting_date, self.cost_center)
self.paid_to_account_currency = acc.account_currency
self.paid_to_account_balance = acc.account_balance
@ -390,8 +390,9 @@ class PaymentEntry(AccountsController):
) -> None:
for d in self.get("references"):
if d.allocated_amount:
if update_ref_details_only_for and (
not (d.reference_doctype, d.reference_name) in update_ref_details_only_for
if (
update_ref_details_only_for
and (d.reference_doctype, d.reference_name) not in update_ref_details_only_for
):
continue
@ -702,7 +703,7 @@ class PaymentEntry(AccountsController):
self.db_set("status", self.status, update_modified=True)
def set_tax_withholding(self):
if not self.party_type == "Supplier":
if self.party_type != "Supplier":
return
if not self.apply_tax_withholding_amount:
@ -793,7 +794,7 @@ class PaymentEntry(AccountsController):
self.base_received_amount = self.base_paid_amount
if (
self.paid_from_account_currency == self.paid_to_account_currency
and not self.payment_type == "Internal Transfer"
and self.payment_type != "Internal Transfer"
):
self.received_amount = self.paid_amount
@ -1757,7 +1758,7 @@ def get_split_invoice_rows(invoice: dict, payment_term_template: str, exc_rates:
"Payment Schedule", filters={"parent": invoice.voucher_no}, fields=["*"], order_by="due_date"
)
for payment_term in payment_schedule:
if not payment_term.outstanding > 0.1:
if payment_term.outstanding <= 0.1:
continue
doc_details = exc_rates.get(payment_term.parent, None)

View File

@ -286,7 +286,7 @@ class PricingRule(Document):
def validate_price_list_with_currency(self):
if self.currency and self.for_price_list:
price_list_currency = frappe.db.get_value("Price List", self.for_price_list, "currency", True)
if not self.currency == price_list_currency:
if self.currency != price_list_currency:
throw(_("Currency should be same as Price List Currency: {0}").format(price_list_currency))
def validate_dates(self):

View File

@ -475,7 +475,7 @@ def reconcile(doc: None | str = None) -> None:
frappe.db.set_value("Process Payment Reconciliation", doc, "status", "Completed")
else:
if not (frappe.db.get_value("Process Payment Reconciliation", doc, "status") == "Paused"):
if frappe.db.get_value("Process Payment Reconciliation", doc, "status") != "Paused":
# trigger next batch in job
# generate reconcile job name
allocation = get_next_allocation(log)

View File

@ -371,7 +371,7 @@ class PurchaseInvoice(BuyingController):
check_list = []
for d in self.get("items"):
if d.purchase_order and not d.purchase_order in check_list and not d.purchase_receipt:
if d.purchase_order and d.purchase_order not in check_list and not d.purchase_receipt:
check_list.append(d.purchase_order)
check_on_hold_or_closed_status("Purchase Order", d.purchase_order)

View File

@ -458,7 +458,7 @@ class SalesInvoice(SellingController):
self.update_billing_status_for_zero_amount_refdoc("Sales Order")
self.check_credit_limit()
if not cint(self.is_pos) == 1 and not self.is_return:
if cint(self.is_pos) != 1 and not self.is_return:
self.update_against_document_in_jv()
self.update_time_sheet(self.name)
@ -1960,9 +1960,9 @@ def validate_inter_company_party(doctype, party, company, inter_company_referenc
if inter_company_reference:
doc = frappe.get_doc(ref_doc, inter_company_reference)
ref_party = doc.supplier if doctype in ["Sales Invoice", "Sales Order"] else doc.customer
if not frappe.db.get_value(partytype, {"represents_company": doc.company}, "name") == party:
if frappe.db.get_value(partytype, {"represents_company": doc.company}, "name") != party:
frappe.throw(_("Invalid {0} for Inter Company Transaction.").format(_(partytype)))
if not frappe.get_cached_value(ref_partytype, ref_party, "represents_company") == company:
if frappe.get_cached_value(ref_partytype, ref_party, "represents_company") != company:
frappe.throw(_("Invalid Company for Inter Company Transaction."))
elif frappe.db.get_value(partytype, {"name": party, internal: 1}, "name") == party:
@ -1972,7 +1972,7 @@ def validate_inter_company_party(doctype, party, company, inter_company_referenc
filters={"parenttype": partytype, "parent": party},
)
companies = [d.company for d in companies]
if not company in companies:
if company not in companies:
frappe.throw(
_("{0} not allowed to transact with {1}. Please change the Company.").format(
_(partytype), company

View File

@ -142,12 +142,12 @@ class ShippingRule(Document):
}
if self.shipping_rule_type == "Selling":
# check if not applied on purchase
if not doc.meta.get_field("taxes").options == "Sales Taxes and Charges":
if doc.meta.get_field("taxes").options != "Sales Taxes and Charges":
frappe.throw(_("Shipping rule only applicable for Selling"))
shipping_charge["doctype"] = "Sales Taxes and Charges"
else:
# check if not applied on sales
if not doc.meta.get_field("taxes").options == "Purchase Taxes and Charges":
if doc.meta.get_field("taxes").options != "Purchase Taxes and Charges":
frappe.throw(_("Shipping rule only applicable for Buying"))
shipping_charge["doctype"] = "Purchase Taxes and Charges"

View File

@ -676,7 +676,7 @@ class Subscription(Document):
to_generate_invoice = (
True
if self.status == "Active"
and not self.generate_invoice_at == "Beginning of the current subscription period"
and self.generate_invoice_at != "Beginning of the current subscription period"
else False
)
self.status = "Cancelled"
@ -694,7 +694,7 @@ class Subscription(Document):
subscription and the `Subscription` will lose all the history of generated invoices
it has.
"""
if not self.status == "Cancelled":
if self.status != "Cancelled":
frappe.throw(_("You cannot restart a Subscription that is not cancelled."), InvoiceNotCancelled)
self.status = "Active"

View File

@ -37,7 +37,7 @@ class UnreconcilePayment(Document):
def validate(self):
self.supported_types = ["Payment Entry", "Journal Entry"]
if not self.voucher_type in self.supported_types:
if self.voucher_type not in self.supported_types:
frappe.throw(_("Only {0} are supported").format(comma_and(self.supported_types)))
@frappe.whitelist()

View File

@ -775,7 +775,7 @@ def validate_party_frozen_disabled(party_type, party_name):
frozen_accounts_modifier = frappe.db.get_single_value(
"Accounts Settings", "frozen_accounts_modifier"
)
if not frozen_accounts_modifier in frappe.get_roles():
if frozen_accounts_modifier not in frappe.get_roles():
frappe.throw(_("{0} {1} is frozen").format(party_type, party_name), PartyFrozen)
elif party_type == "Employee":

View File

@ -123,7 +123,7 @@ class ReceivablePayableReport(object):
else:
key = (ple.account, ple.voucher_type, ple.voucher_no, ple.party)
if not key in self.voucher_balance:
if key not in self.voucher_balance:
self.voucher_balance[key] = frappe._dict(
voucher_type=ple.voucher_type,
voucher_no=ple.voucher_no,
@ -938,7 +938,7 @@ class ReceivablePayableReport(object):
return True
def get_party_details(self, party):
if not party in self.party_details:
if party not in self.party_details:
if self.account_type == "Receivable":
fields = ["customer_name", "territory", "customer_group", "customer_primary_contact"]

View File

@ -97,7 +97,7 @@ class Deferred_Item(object):
if base_amount + already_booked_amount > self.base_net_amount:
base_amount = self.base_net_amount - already_booked_amount
if not (get_first_day(start_date) == start_date and get_last_day(end_date) == end_date):
if get_first_day(start_date) != start_date or get_last_day(end_date) != end_date:
partial_month = flt(date_diff(end_date, start_date)) / flt(
date_diff(get_last_day(end_date), get_first_day(start_date))
)

View File

@ -170,7 +170,7 @@ def set_total(node, value, complete_list, totals):
totals[node["account"]] += value
parent = node["parent_account"]
if not parent == "":
if parent != "":
return set_total(
next(item for item in complete_list if item["account"] == parent), value, complete_list, totals
)

View File

@ -695,7 +695,7 @@ class GrossProfitGenerator(object):
def get_average_buying_rate(self, row, item_code):
args = row
if not item_code in self.average_buying_rate:
if item_code not in self.average_buying_rate:
args.update(
{
"voucher_type": row.parenttype,

View File

@ -154,7 +154,7 @@ def get_gle_map(documents):
)
for d in gle:
if not d.voucher_no in gle_map:
if d.voucher_no not in gle_map:
gle_map[d.voucher_no] = [d]
else:
gle_map[d.voucher_no].append(d)

View File

@ -1062,11 +1062,11 @@ def get_outstanding_invoices(
if (
min_outstanding
and max_outstanding
and not (outstanding_amount >= min_outstanding and outstanding_amount <= max_outstanding)
and (outstanding_amount < min_outstanding or outstanding_amount > max_outstanding)
):
continue
if not d.voucher_type == "Purchase Invoice" or d.voucher_no not in held_invoices:
if d.voucher_type != "Purchase Invoice" or d.voucher_no not in held_invoices:
outstanding_invoices.append(
frappe._dict(
{

View File

@ -313,7 +313,7 @@ class Asset(AccountsController):
frappe.throw(_("Gross Purchase Amount is mandatory"), frappe.MandatoryError)
if is_cwip_accounting_enabled(self.asset_category):
if not self.is_existing_asset and not (self.purchase_receipt or self.purchase_invoice):
if not self.is_existing_asset and not self.purchase_receipt and not self.purchase_invoice:
frappe.throw(
_("Please create purchase receipt or purchase invoice for the item {0}").format(
self.item_code

View File

@ -84,7 +84,7 @@ class AssetMovement(Document):
frappe.throw(_("Source and Target Location cannot be same"))
if self.purpose == "Receipt":
if not (d.source_location) and not (d.target_location or d.to_employee):
if not (d.source_location) and not d.target_location and not d.to_employee:
frappe.throw(
_("Target Location or To Employee is required while receiving Asset {0}").format(d.asset)
)

View File

@ -114,7 +114,7 @@ def prepare_data(data, filters):
if filters.get("group_by_po"):
po_name = row["purchase_order"]
if not po_name in purchase_order_map:
if po_name not in purchase_order_map:
# create an entry
row_copy = copy.deepcopy(row)
purchase_order_map[po_name] = row_copy

View File

@ -110,7 +110,7 @@ def prepare_data(data, filters):
for row in data:
# item wise map for charts
if not row["item_code"] in item_qty_map:
if row["item_code"] not in item_qty_map:
item_qty_map[row["item_code"]] = {
"qty": flt(row["stock_qty"], precision),
"stock_qty": flt(row["stock_qty"], precision),
@ -127,7 +127,7 @@ def prepare_data(data, filters):
if filters.get("group_by_mr"):
# consolidated material request map for group by filter
if not row["material_request"] in material_request_map:
if row["material_request"] not in material_request_map:
# create an entry with mr as key
row_copy = copy.deepcopy(row)
material_request_map[row["material_request"]] = row_copy

View File

@ -126,7 +126,7 @@ def prepare_data(supplier_quotation_data, filters):
# map for chart preparation of the form {'supplier1': {'qty': 'price'}}
supplier = data.get("supplier_name")
if filters.get("item_code"):
if not supplier in supplier_qty_price_map:
if supplier not in supplier_qty_price_map:
supplier_qty_price_map[supplier] = {}
supplier_qty_price_map[supplier][row["qty"]] = row["price"]
@ -169,7 +169,7 @@ def prepare_chart_data(suppliers, qty_list, supplier_qty_price_map):
for supplier in suppliers:
entry = supplier_qty_price_map[supplier]
for qty in qty_list:
if not qty in data_points_map:
if qty not in data_points_map:
data_points_map[qty] = []
if qty in entry:
data_points_map[qty].append(entry[qty])

View File

@ -222,7 +222,7 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals
searchfields = meta.get_search_fields()
columns = ""
extra_searchfields = [field for field in searchfields if not field in ["name", "description"]]
extra_searchfields = [field for field in searchfields if field not in ["name", "description"]]
if extra_searchfields:
columns += ", " + ", ".join(extra_searchfields)
@ -233,8 +233,13 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals
searchfields = searchfields + [
field
for field in [searchfield or "name", "item_code", "item_group", "item_name"]
if not field in searchfields
for field in [
searchfield or "name",
"item_code",
"item_group",
"item_name",
]
if field not in searchfields
]
searchfields = " or ".join([field + " like %(txt)s" for field in searchfields])
@ -872,7 +877,7 @@ def get_fields(doctype, fields=None):
meta = frappe.get_meta(doctype)
fields.extend(meta.get_search_fields())
if meta.title_field and not meta.title_field.strip() in fields:
if meta.title_field and meta.title_field.strip() not in fields:
fields.insert(1, meta.title_field.strip())
return unique(fields)

View File

@ -642,7 +642,7 @@ class StockController(AccountsController):
)
qa_docstatus = frappe.db.get_value("Quality Inspection", row.quality_inspection, "docstatus")
if not qa_docstatus == 1:
if qa_docstatus != 1:
link = frappe.utils.get_link_to_form("Quality Inspection", row.quality_inspection)
msg = (
f"Row #{row.idx}: Quality Inspection {link} is not submitted for the item: {row.item_code}"

View File

@ -55,7 +55,7 @@ class Appointment(Document):
"Appointment", filters={"scheduled_time": self.scheduled_time}
)
number_of_agents = frappe.db.get_single_value("Appointment Booking Settings", "number_of_agents")
if not number_of_agents == 0:
if number_of_agents != 0:
if number_of_appointments_in_same_slot >= number_of_agents:
frappe.throw(_("Time slot is not available"))
# Link lead
@ -110,7 +110,7 @@ class Appointment(Document):
cal_event.save(ignore_permissions=True)
def set_verified(self, email):
if not email == self.customer_email:
if email != self.customer_email:
frappe.throw(_("Email verification failed."))
# Create new lead
self.create_lead_and_link()

View File

@ -16,7 +16,7 @@ def validate_webhooks_request(doctype, hmac_key, secret_key="secret"):
hmac.new(settings.get(secret_key).encode("utf8"), frappe.request.data, hashlib.sha256).digest()
)
if frappe.request.data and not sig == bytes(frappe.get_request_header(hmac_key).encode()):
if frappe.request.data and sig != bytes(frappe.get_request_header(hmac_key).encode()):
frappe.throw(_("Unverified Webhook Data"))
frappe.set_user(settings.modified_by)

View File

@ -89,7 +89,7 @@ def make_order(source_name):
def update_item(source, target, source_parent):
target_qty = source.get("qty") - source.get("ordered_qty")
target.qty = target_qty if not flt(target_qty) < 0 else 0
target.qty = target_qty if flt(target_qty) >= 0 else 0
item = get_item_defaults(target.item_code, source_parent.company)
if item:
target.item_name = item.get("item_name")

View File

@ -1381,7 +1381,7 @@ def get_bom_diff(bom1, bom2):
# check for deletions
for d in old_value:
if not d.get(identifier) in new_row_by_identifier:
if d.get(identifier) not in new_row_by_identifier:
out.removed.append([df.fieldname, d.as_dict()])
return out
@ -1397,13 +1397,18 @@ def item_query(doctype, txt, searchfield, start, page_len, filters):
fields = ["name", "item_name", "item_group", "description"]
fields.extend(
[field for field in searchfields if not field in ["name", "item_group", "description"]]
[field for field in searchfields if field not in ["name", "item_group", "description"]]
)
searchfields = searchfields + [
field
for field in [searchfield or "name", "item_code", "item_group", "item_name"]
if not field in searchfields
for field in [
searchfield or "name",
"item_code",
"item_group",
"item_name",
]
if field not in searchfields
]
query_filters = {"disabled": 0, "ifnull(end_of_life, '3099-12-31')": (">", today())}

View File

@ -815,7 +815,7 @@ class ProductionPlan(Document):
key = "{}:{}:{}".format(item.sales_order, material_request_type, item_doc.customer or "")
schedule_date = item.schedule_date or add_days(nowdate(), cint(item_doc.lead_time_days))
if not key in material_request_map:
if key not in material_request_map:
# make a new MR for the combination
material_request_map[key] = frappe.new_doc("Material Request")
material_request = material_request_map[key]

View File

@ -930,7 +930,7 @@ class WorkOrder(Document):
validate_end_of_life(self.production_item)
def validate_qty(self):
if not self.qty > 0:
if self.qty <= 0:
frappe.throw(_("Quantity to Manufacture must be greater than 0."))
if (
@ -957,7 +957,7 @@ class WorkOrder(Document):
max_qty = qty_dict.get("planned_qty", 0) + allowance_qty - qty_dict.get("ordered_qty", 0)
if not max_qty > 0:
if max_qty <= 0:
frappe.throw(
_("Cannot produce more item for {0}").format(self.production_item), OverProductionError
)
@ -968,7 +968,7 @@ class WorkOrder(Document):
)
def validate_transfer_against(self):
if not self.docstatus == 1:
if self.docstatus != 1:
# let user configure operations until they're ready to submit
return
if not self.operations:
@ -981,7 +981,7 @@ class WorkOrder(Document):
def validate_operation_time(self):
for d in self.operations:
if not d.time_in_mins > 0:
if d.time_in_mins <= 0:
frappe.throw(_("Operation Time must be greater than 0 for Operation {0}").format(d.operation))
def update_required_items(self):

View File

@ -10,7 +10,7 @@ def execute():
)
if property_setter_name:
property_setter = frappe.get_doc("Property Setter", property_setter_name)
if not "Completed" in property_setter.value:
if "Completed" not in property_setter.value:
property_setter.value = property_setter.value + "\nCompleted"
property_setter.save()

View File

@ -46,7 +46,7 @@ def execute():
{"response_time": response_time, "resolution_time": resolution_time},
)
if priority.parenttype == "Service Level":
if not priority.parent in priority_dict:
if priority.parent not in priority_dict:
priority_dict[priority.parent] = []
priority_dict[priority.parent].append(priority)

View File

@ -50,7 +50,7 @@ def create_customer_or_supplier():
party = frappe.new_doc(doctype)
fullname = frappe.utils.get_fullname(user)
if not doctype == "Customer":
if doctype != "Customer":
party.update(
{
"supplier_name": fullname,

View File

@ -661,7 +661,7 @@ def set_project_status(project, status):
"""
set status for project and all related tasks
"""
if not status in ("Completed", "Cancelled"):
if status not in ("Completed", "Cancelled"):
frappe.throw(_("Status must be Cancelled or Completed"))
project = frappe.get_doc("Project", project)

View File

@ -240,7 +240,7 @@ def get_chart_data(data):
for row in data:
item_key = row.get("item_code")
if not item_key in item_wise_sales_map:
if item_key not in item_wise_sales_map:
item_wise_sales_map[item_key] = 0
item_wise_sales_map[item_key] = flt(item_wise_sales_map[item_key]) + flt(row.get("amount"))

View File

@ -167,7 +167,7 @@ def prepare_data(data, so_elapsed_time, filters):
if filters.get("group_by_so"):
so_name = row["sales_order"]
if not so_name in sales_order_map:
if so_name not in sales_order_map:
# create an entry
row_copy = copy.deepcopy(row)
sales_order_map[so_name] = row_copy

View File

@ -185,7 +185,10 @@ class AuthorizationControl(TransactionBase):
# Remove user specific rules from global authorization rules
for r in based_on:
if r in final_based_on and not r in ["Itemwise Discount", "Item Group wise Discount"]:
if r in final_based_on and r not in [
"Itemwise Discount",
"Item Group wise Discount",
]:
final_based_on.remove(r)
# Check for authorization set on particular roles
@ -213,7 +216,10 @@ class AuthorizationControl(TransactionBase):
# Remove role specific rules from global authorization rules
for r in based_on:
if r in final_based_on and not r in ["Itemwise Discount", "Item Group wise Discount"]:
if r in final_based_on and r not in [
"Itemwise Discount",
"Item Group wise Discount",
]:
final_based_on.remove(r)
# Check for global authorization

View File

@ -44,7 +44,7 @@ class Department(NestedSet):
def before_rename(self, old, new, merge=False):
# renaming consistency with abbreviation
if not frappe.get_cached_value("Company", self.company, "abbr") in new:
if frappe.get_cached_value("Company", self.company, "abbr") not in new:
new = get_abbreviated_name(new, self.company)
return new

View File

@ -689,7 +689,7 @@ class EmailDigest(Document):
]
def get_root_type_accounts(self, root_type):
if not root_type in self._accounts:
if root_type not in self._accounts:
self._accounts[root_type] = [
d.name
for d in frappe.db.get_all(

View File

@ -187,7 +187,7 @@ class Employee(NestedSet):
throw(_("Please enter relieving date."))
def validate_for_enabled_user_id(self, enabled):
if not self.status == "Active":
if self.status != "Active":
return
if enabled is None:

View File

@ -197,7 +197,7 @@ def add_standard_navbar_items():
for item in erpnext_navbar_items:
current_labels = [item.get("item_label") for item in current_navbar_items]
if not item.get("item_label") in current_labels:
if item.get("item_label") not in current_labels:
navbar_settings.append("help_dropdown", item)
for item in current_navbar_items:

View File

@ -79,10 +79,10 @@ class MaterialRequest(BuyingController):
so_items = {} # Format --> {'SO/00001': {'Item/001': 120, 'Item/002': 24}}
for d in self.get("items"):
if d.sales_order:
if not d.sales_order in so_items:
if d.sales_order not in so_items:
so_items[d.sales_order] = {d.item_code: flt(d.qty)}
else:
if not d.item_code in so_items[d.sales_order]:
if d.item_code not in so_items[d.sales_order]:
so_items[d.sales_order][d.item_code] = flt(d.qty)
else:
so_items[d.sales_order][d.item_code] += flt(d.qty)

View File

@ -170,7 +170,7 @@ def apply_putaway_rule(doctype, items, company, sync=None, purpose=None):
pending_qty -= qty_to_allocate
rule["free_space"] -= stock_qty_to_allocate
if not pending_stock_qty > 0:
if pending_stock_qty <= 0:
break
# if pending qty after applying all rules, add row without warehouse

View File

@ -227,7 +227,7 @@ class StockEntry(StockController):
self.calculate_rate_and_amount()
self.validate_putaway_capacity()
if not self.get("purpose") == "Manufacture":
if self.get("purpose") != "Manufacture":
# ignore scrap item wh difference and empty source/target wh
# in Manufacture Entry
self.reset_default_field_value("from_warehouse", "items", "s_warehouse")

View File

@ -214,7 +214,9 @@ class StockLedgerEntry(Document):
if not self.serial_and_batch_bundle:
self.throw_error_message(f"Serial No / Batch No are mandatory for Item {self.item_code}")
if self.serial_and_batch_bundle and not (item_detail.has_serial_no or item_detail.has_batch_no):
if (
self.serial_and_batch_bundle and not item_detail.has_serial_no and not item_detail.has_batch_no
):
self.throw_error_message(f"Serial No and Batch No are not allowed for Item {self.item_code}")
def throw_error_message(self, message, exception=frappe.ValidationError):

View File

@ -931,7 +931,7 @@ def create_stock_reservation_entries_for_so_items(
continue
# Stock should be reserved from the Pick List if has Picked Qty.
if not from_voucher_type == "Pick List" and flt(item.picked_qty) > 0:
if from_voucher_type != "Pick List" and flt(item.picked_qty) > 0:
frappe.throw(
_("Row #{0}: Item {1} has been picked, please reserve stock from the Pick List.").format(
item.idx, frappe.bold(item.item_code)

View File

@ -1711,7 +1711,7 @@ def get_datetime_limit_condition(detail):
def validate_negative_qty_in_future_sle(args, allow_negative_stock=False):
if allow_negative_stock or is_negative_stock_allowed(item_code=args.item_code):
return
if not (args.actual_qty < 0 or args.voucher_type == "Stock Reconciliation"):
if args.actual_qty >= 0 and args.voucher_type != "Stock Reconciliation":
return
neg_sle = get_future_sle_with_negative_qty(args)

View File

@ -100,7 +100,7 @@ class ServiceLevelAgreement(Document):
priorities.append(priority.priority)
# Check if repeated priority
if not len(set(priorities)) == len(priorities):
if len(set(priorities)) != len(priorities):
repeated_priority = get_repeated(priorities)
frappe.throw(_("Priority {0} has been repeated.").format(repeated_priority))
@ -128,7 +128,7 @@ class ServiceLevelAgreement(Document):
)
# Check for repeated workday
if not len(set(support_days)) == len(support_days):
if len(set(support_days)) != len(support_days):
repeated_days = get_repeated(support_days)
frappe.throw(_("Workday {0} has been repeated.").format(repeated_days))
@ -748,13 +748,13 @@ def change_service_level_agreement_and_priority(self):
and frappe.db.get_single_value("Support Settings", "track_service_level_agreement")
):
if not self.priority == frappe.db.get_value("Issue", self.name, "priority"):
if self.priority != frappe.db.get_value("Issue", self.name, "priority"):
self.set_response_and_resolution_time(
priority=self.priority, service_level_agreement=self.service_level_agreement
)
frappe.msgprint(_("Priority has been changed to {0}.").format(self.priority))
if not self.service_level_agreement == frappe.db.get_value(
if self.service_level_agreement != frappe.db.get_value(
"Issue", self.name, "service_level_agreement"
):
self.set_response_and_resolution_time(