sell_to_buy/wizard/sell_to_buy_wizard.py
Function button_ok
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
Open
def button_ok(self):
'''生成按钮,复制销货订单行到购货订单中'''
for wizard in self:
if not wizard.sell_line_ids:
raise UserError(u'销货订单行不能为空')
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
At least two spaces before inline comment Open
Open
order_dict = {} # 用来判断勾选行是否来自同一张销货订单
- Read upRead up
- Exclude checks
Separate inline comments by at least two spaces.
An inline comment is a comment on the same line as a statement.
Inline comments should be separated by at least two spaces from the
statement. They should start with a # and a single space.
Each line of a block comment starts with a # and a single space
(unless it is indented text inside the comment).
Okay: x = x + 1 # Increment x
Okay: x = x + 1 # Increment x
Okay: # Block comment
E261: x = x + 1 # Increment x
E262: x = x + 1 #Increment x
E262: x = x + 1 # Increment x
E265: #Block comment
E266: ### Block comment
.has_key() is deprecated, use 'in' Open
Open
if not order_dict.has_key(line.order_id):
- Read upRead up
- Exclude checks
The {}.has_key() method is removed in Python 3: use the 'in' operator.
Okay: if "alph" in d:\n print d["alph"]
W601: assert d.has_key('alph')