refactor: Clean up mutable defaults and add CI check (#27828)
* refactor: Clean up mutable defaults and add CI check
This commit is contained in:
parent
d4b2471cea
commit
772d4753e7
5
.github/helper/.flake8_strict
vendored
5
.github/helper/.flake8_strict
vendored
@ -65,6 +65,11 @@ ignore =
|
|||||||
E713,
|
E713,
|
||||||
E712,
|
E712,
|
||||||
|
|
||||||
|
enable-extensions =
|
||||||
|
M90
|
||||||
|
|
||||||
|
select =
|
||||||
|
M511
|
||||||
|
|
||||||
max-line-length = 200
|
max-line-length = 200
|
||||||
exclude=.github/helper/semgrep_rules,test_*.py
|
exclude=.github/helper/semgrep_rules,test_*.py
|
||||||
|
@ -20,7 +20,10 @@ repos:
|
|||||||
rev: 3.9.2
|
rev: 3.9.2
|
||||||
hooks:
|
hooks:
|
||||||
- id: flake8
|
- id: flake8
|
||||||
args: ['--config', '.github/helper/.flake8_strict']
|
additional_dependencies: [
|
||||||
|
'flake8-mutable',
|
||||||
|
]
|
||||||
|
args: ['--select=M511', '--config', '.github/helper/.flake8_strict']
|
||||||
exclude: ".*setup.py$"
|
exclude: ".*setup.py$"
|
||||||
|
|
||||||
- repo: https://github.com/timothycrosley/isort
|
- repo: https://github.com/timothycrosley/isort
|
||||||
|
@ -33,7 +33,9 @@ class TestPOSProfile(unittest.TestCase):
|
|||||||
|
|
||||||
frappe.db.sql("delete from `tabPOS Profile`")
|
frappe.db.sql("delete from `tabPOS Profile`")
|
||||||
|
|
||||||
def get_customers_list(pos_profile={}):
|
def get_customers_list(pos_profile=None):
|
||||||
|
if pos_profile is None:
|
||||||
|
pos_profile = {}
|
||||||
cond = "1=1"
|
cond = "1=1"
|
||||||
customer_groups = []
|
customer_groups = []
|
||||||
if pos_profile.get('customer_groups'):
|
if pos_profile.get('customer_groups'):
|
||||||
|
@ -398,7 +398,9 @@ def get_qty_and_rate_for_other_item(doc, pr_doc, pricing_rules):
|
|||||||
pricing_rules[0].apply_rule_on_other_items = items
|
pricing_rules[0].apply_rule_on_other_items = items
|
||||||
return pricing_rules
|
return pricing_rules
|
||||||
|
|
||||||
def get_qty_amount_data_for_cumulative(pr_doc, doc, items=[]):
|
def get_qty_amount_data_for_cumulative(pr_doc, doc, items=None):
|
||||||
|
if items is None:
|
||||||
|
items = []
|
||||||
sum_qty, sum_amt = [0, 0]
|
sum_qty, sum_amt = [0, 0]
|
||||||
doctype = doc.get('parenttype') or doc.doctype
|
doctype = doc.get('parenttype') or doc.doctype
|
||||||
|
|
||||||
|
@ -69,7 +69,9 @@ class PromotionalScheme(Document):
|
|||||||
{'promotional_scheme': self.name}):
|
{'promotional_scheme': self.name}):
|
||||||
frappe.delete_doc('Pricing Rule', rule.name)
|
frappe.delete_doc('Pricing Rule', rule.name)
|
||||||
|
|
||||||
def get_pricing_rules(doc, rules = {}):
|
def get_pricing_rules(doc, rules=None):
|
||||||
|
if rules is None:
|
||||||
|
rules = {}
|
||||||
new_doc = []
|
new_doc = []
|
||||||
for child_doc, fields in {'price_discount_slabs': price_discount_fields,
|
for child_doc, fields in {'price_discount_slabs': price_discount_fields,
|
||||||
'product_discount_slabs': product_discount_fields}.items():
|
'product_discount_slabs': product_discount_fields}.items():
|
||||||
@ -78,7 +80,9 @@ def get_pricing_rules(doc, rules = {}):
|
|||||||
|
|
||||||
return new_doc
|
return new_doc
|
||||||
|
|
||||||
def _get_pricing_rules(doc, child_doc, discount_fields, rules = {}):
|
def _get_pricing_rules(doc, child_doc, discount_fields, rules=None):
|
||||||
|
if rules is None:
|
||||||
|
rules = {}
|
||||||
new_doc = []
|
new_doc = []
|
||||||
args = get_args_for_pricing_rule(doc)
|
args = get_args_for_pricing_rule(doc)
|
||||||
applicable_for = frappe.scrub(doc.get('applicable_for'))
|
applicable_for = frappe.scrub(doc.get('applicable_for'))
|
||||||
|
@ -139,9 +139,9 @@ def get_account_type_based_data(company, account_type, period_list, accumulated_
|
|||||||
data["total"] = total
|
data["total"] = total
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def get_account_type_based_gl_data(company, start_date, end_date, account_type, filters={}):
|
def get_account_type_based_gl_data(company, start_date, end_date, account_type, filters=None):
|
||||||
cond = ""
|
cond = ""
|
||||||
filters = frappe._dict(filters)
|
filters = frappe._dict(filters or {})
|
||||||
|
|
||||||
if filters.include_default_book_entries:
|
if filters.include_default_book_entries:
|
||||||
company_fb = frappe.db.get_value("Company", company, 'default_finance_book')
|
company_fb = frappe.db.get_value("Company", company, 'default_finance_book')
|
||||||
|
@ -138,7 +138,9 @@ class Student(Document):
|
|||||||
enrollment.submit()
|
enrollment.submit()
|
||||||
return enrollment
|
return enrollment
|
||||||
|
|
||||||
def enroll_in_course(self, course_name, program_enrollment, enrollment_date=frappe.utils.datetime.datetime.now()):
|
def enroll_in_course(self, course_name, program_enrollment, enrollment_date=None):
|
||||||
|
if enrollment_date is None:
|
||||||
|
enrollment_date = frappe.utils.datetime.datetime.now()
|
||||||
try:
|
try:
|
||||||
enrollment = frappe.get_doc({
|
enrollment = frappe.get_doc({
|
||||||
"doctype": "Course Enrollment",
|
"doctype": "Course Enrollment",
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# License: GNU General Public License v3. See license.txt
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
@ -94,9 +93,11 @@ def get_events(start, end, filters=None):
|
|||||||
update={"allDay": 1})
|
update={"allDay": 1})
|
||||||
|
|
||||||
|
|
||||||
def is_holiday(holiday_list, date=today()):
|
def is_holiday(holiday_list, date=None):
|
||||||
"""Returns true if the given date is a holiday in the given holiday list
|
"""Returns true if the given date is a holiday in the given holiday list
|
||||||
"""
|
"""
|
||||||
|
if date is None:
|
||||||
|
date = today()
|
||||||
if holiday_list:
|
if holiday_list:
|
||||||
return bool(frappe.get_all('Holiday List',
|
return bool(frappe.get_all('Holiday List',
|
||||||
dict(name=holiday_list, holiday_date=date)))
|
dict(name=holiday_list, holiday_date=date)))
|
||||||
|
@ -139,7 +139,7 @@ def get_shift_type_timing(shift_types):
|
|||||||
return shift_timing_map
|
return shift_timing_map
|
||||||
|
|
||||||
|
|
||||||
def get_employee_shift(employee, for_date=nowdate(), consider_default_shift=False, next_shift_direction=None):
|
def get_employee_shift(employee, for_date=None, consider_default_shift=False, next_shift_direction=None):
|
||||||
"""Returns a Shift Type for the given employee on the given date. (excluding the holidays)
|
"""Returns a Shift Type for the given employee on the given date. (excluding the holidays)
|
||||||
|
|
||||||
:param employee: Employee for which shift is required.
|
:param employee: Employee for which shift is required.
|
||||||
@ -147,6 +147,8 @@ def get_employee_shift(employee, for_date=nowdate(), consider_default_shift=Fals
|
|||||||
:param consider_default_shift: If set to true, default shift is taken when no shift assignment is found.
|
:param consider_default_shift: If set to true, default shift is taken when no shift assignment is found.
|
||||||
:param next_shift_direction: One of: None, 'forward', 'reverse'. Direction to look for next shift if shift not found on given date.
|
:param next_shift_direction: One of: None, 'forward', 'reverse'. Direction to look for next shift if shift not found on given date.
|
||||||
"""
|
"""
|
||||||
|
if for_date is None:
|
||||||
|
for_date = nowdate()
|
||||||
default_shift = frappe.db.get_value('Employee', employee, 'default_shift')
|
default_shift = frappe.db.get_value('Employee', employee, 'default_shift')
|
||||||
shift_type_name = None
|
shift_type_name = None
|
||||||
shift_assignment_details = frappe.db.get_value('Shift Assignment', {'employee':employee, 'start_date':('<=', for_date), 'docstatus': '1', 'status': "Active"}, ['shift_type', 'end_date'])
|
shift_assignment_details = frappe.db.get_value('Shift Assignment', {'employee':employee, 'start_date':('<=', for_date), 'docstatus': '1', 'status': "Active"}, ['shift_type', 'end_date'])
|
||||||
@ -200,9 +202,11 @@ def get_employee_shift(employee, for_date=nowdate(), consider_default_shift=Fals
|
|||||||
return get_shift_details(shift_type_name, for_date)
|
return get_shift_details(shift_type_name, for_date)
|
||||||
|
|
||||||
|
|
||||||
def get_employee_shift_timings(employee, for_timestamp=now_datetime(), consider_default_shift=False):
|
def get_employee_shift_timings(employee, for_timestamp=None, consider_default_shift=False):
|
||||||
"""Returns previous shift, current/upcoming shift, next_shift for the given timestamp and employee
|
"""Returns previous shift, current/upcoming shift, next_shift for the given timestamp and employee
|
||||||
"""
|
"""
|
||||||
|
if for_timestamp is None:
|
||||||
|
for_timestamp = now_datetime()
|
||||||
# write and verify a test case for midnight shift.
|
# write and verify a test case for midnight shift.
|
||||||
prev_shift = curr_shift = next_shift = None
|
prev_shift = curr_shift = next_shift = None
|
||||||
curr_shift = get_employee_shift(employee, for_timestamp.date(), consider_default_shift, 'forward')
|
curr_shift = get_employee_shift(employee, for_timestamp.date(), consider_default_shift, 'forward')
|
||||||
@ -220,7 +224,7 @@ def get_employee_shift_timings(employee, for_timestamp=now_datetime(), consider_
|
|||||||
return prev_shift, curr_shift, next_shift
|
return prev_shift, curr_shift, next_shift
|
||||||
|
|
||||||
|
|
||||||
def get_shift_details(shift_type_name, for_date=nowdate()):
|
def get_shift_details(shift_type_name, for_date=None):
|
||||||
"""Returns Shift Details which contain some additional information as described below.
|
"""Returns Shift Details which contain some additional information as described below.
|
||||||
'shift_details' contains the following keys:
|
'shift_details' contains the following keys:
|
||||||
'shift_type' - Object of DocType Shift Type,
|
'shift_type' - Object of DocType Shift Type,
|
||||||
@ -234,6 +238,8 @@ def get_shift_details(shift_type_name, for_date=nowdate()):
|
|||||||
"""
|
"""
|
||||||
if not shift_type_name:
|
if not shift_type_name:
|
||||||
return None
|
return None
|
||||||
|
if not for_date:
|
||||||
|
for_date = nowdate()
|
||||||
shift_type = frappe.get_doc('Shift Type', shift_type_name)
|
shift_type = frappe.get_doc('Shift Type', shift_type_name)
|
||||||
start_datetime = datetime.combine(for_date, datetime.min.time()) + shift_type.start_time
|
start_datetime = datetime.combine(for_date, datetime.min.time()) + shift_type.start_time
|
||||||
for_date = for_date + timedelta(days=1) if shift_type.start_time > shift_type.end_time else for_date
|
for_date = for_date + timedelta(days=1) if shift_type.start_time > shift_type.end_time else for_date
|
||||||
|
@ -155,7 +155,11 @@ def get_designation_counts(designation, company):
|
|||||||
return employee_counts
|
return employee_counts
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_active_staffing_plan_details(company, designation, from_date=getdate(nowdate()), to_date=getdate(nowdate())):
|
def get_active_staffing_plan_details(company, designation, from_date=None, to_date=None):
|
||||||
|
if from_date is None:
|
||||||
|
from_date = getdate(nowdate())
|
||||||
|
if to_date is None:
|
||||||
|
to_date = getdate(nowdate())
|
||||||
if not company or not designation:
|
if not company or not designation:
|
||||||
frappe.throw(_("Please select Company and Designation"))
|
frappe.throw(_("Please select Company and Designation"))
|
||||||
|
|
||||||
|
@ -296,7 +296,7 @@ def make_purchase_order(source_name, target_doc=None, args=None):
|
|||||||
|
|
||||||
return d.ordered_qty < d.stock_qty and child_filter
|
return d.ordered_qty < d.stock_qty and child_filter
|
||||||
|
|
||||||
doclist = get_mapped_doc("Material Request", source_name, {
|
doclist = get_mapped_doc("Material Request", source_name, {
|
||||||
"Material Request": {
|
"Material Request": {
|
||||||
"doctype": "Purchase Order",
|
"doctype": "Purchase Order",
|
||||||
"validation": {
|
"validation": {
|
||||||
@ -323,7 +323,7 @@ def make_purchase_order(source_name, target_doc=None, args=None):
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def make_request_for_quotation(source_name, target_doc=None):
|
def make_request_for_quotation(source_name, target_doc=None):
|
||||||
doclist = get_mapped_doc("Material Request", source_name, {
|
doclist = get_mapped_doc("Material Request", source_name, {
|
||||||
"Material Request": {
|
"Material Request": {
|
||||||
"doctype": "Request for Quotation",
|
"doctype": "Request for Quotation",
|
||||||
"validation": {
|
"validation": {
|
||||||
|
@ -611,7 +611,9 @@ def get_pos_reserved_serial_nos(filters):
|
|||||||
|
|
||||||
return reserved_sr_nos
|
return reserved_sr_nos
|
||||||
|
|
||||||
def fetch_serial_numbers(filters, qty, do_not_include=[]):
|
def fetch_serial_numbers(filters, qty, do_not_include=None):
|
||||||
|
if do_not_include is None:
|
||||||
|
do_not_include = []
|
||||||
batch_join_selection = ""
|
batch_join_selection = ""
|
||||||
batch_no_condition = ""
|
batch_no_condition = ""
|
||||||
batch_nos = filters.get("batch_no")
|
batch_nos = filters.get("batch_no")
|
||||||
|
@ -382,7 +382,7 @@ def get_basic_details(args, item, overwrite_warehouse=True):
|
|||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def get_item_warehouse(item, args, overwrite_warehouse, defaults={}):
|
def get_item_warehouse(item, args, overwrite_warehouse, defaults=None):
|
||||||
if not defaults:
|
if not defaults:
|
||||||
defaults = frappe._dict({
|
defaults = frappe._dict({
|
||||||
'item_defaults' : get_item_defaults(item.name, args.company),
|
'item_defaults' : get_item_defaults(item.name, args.company),
|
||||||
|
Loading…
Reference in New Issue
Block a user