From f5d1d549d7a3f5b40ec73a43c3d8cf2e4a249a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 1 Mar 2020 12:33:50 +0100 Subject: [PATCH] Fix flake8 errors and warnings We add the flake8 configuration used so we ensure everyone uses the same. We remove the usage of __all__ for non public API. When possible, we rationalize the class name according to its __name__ and module. issue9082 review297061002 --- .flake8 | 2 ++ account.py | 25 ++++++------------------- fiscalyear.py | 4 ++-- journal.py | 4 ---- move.py | 36 ++++++++++++++---------------------- move_template.py | 4 ---- party.py | 1 - period.py | 9 ++++----- setup.py | 7 ++++--- tax.py | 37 +++++++++++++++---------------------- 10 files changed, 47 insertions(+), 82 deletions(-) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000000..bb03d08a82 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +ignore=E123,E124,E126,E128,W503 diff --git a/account.py b/account.py index 2ca7f1ece1..cda91ca2e2 100644 --- a/account.py +++ b/account.py @@ -25,19 +25,6 @@ from trytond.pool import Pool from .common import PeriodMixin, ActivePeriodMixin from .exceptions import SecondCurrencyError, ChartWarning -__all__ = ['TypeTemplate', 'Type', 'OpenType', - 'AccountTemplate', 'AccountTemplateTaxTemplate', - 'Account', 'AccountDeferral', 'AccountTax', - 'OpenChartAccountStart', 'OpenChartAccount', - 'GeneralLedgerAccount', 'GeneralLedgerAccountContext', - 'GeneralLedgerLine', 'GeneralLedgerLineContext', - 'GeneralLedger', 'TrialBalance', - 'BalanceSheetContext', 'BalanceSheetComparisionContext', - 'IncomeStatementContext', - 'AgedBalanceContext', 'AgedBalance', 'AgedBalanceReport', - 'CreateChartStart', 'CreateChartAccount', 'CreateChartProperties', - 'CreateChart', 'UpdateChartStart', 'UpdateChartSucceed', 'UpdateChart'] - def inactive_records(func): @wraps(func) @@ -231,8 +218,8 @@ class Type( parent = fields.Many2One('account.account.type', 'Parent', ondelete="RESTRICT", states={ - 'readonly': (Bool(Eval('template', -1)) & - ~Eval('template_override', False)), + 'readonly': (Bool(Eval('template', -1)) + & ~Eval('template_override', False)), }, domain=[ ('company', '=', Eval('company')), @@ -591,8 +578,8 @@ class AccountTemplate( if not account or account.party_required != self.party_required: res['party_required'] = self.party_required if (not account - or account.general_ledger_balance != - self.general_ledger_balance): + or account.general_ledger_balance + != self.general_ledger_balance): res['general_ledger_balance'] = self.general_ledger_balance if not account or account.template != self: res['template'] = self.id @@ -706,8 +693,8 @@ class Account(AccountMixin(), ActivePeriodMixin, tree(), ModelSQL, ModelView): 'Account' __name__ = 'account.account' _states = { - 'readonly': (Bool(Eval('template', -1)) & - ~Eval('template_override', False)), + 'readonly': (Bool(Eval('template', -1)) + & ~Eval('template_override', False)), } company = fields.Many2One('company.company', 'Company', required=True, ondelete="RESTRICT") diff --git a/fiscalyear.py b/fiscalyear.py index 69b11043f5..d2d2063c5c 100644 --- a/fiscalyear.py +++ b/fiscalyear.py @@ -158,8 +158,8 @@ class FiscalYear(Workflow, ModelSQL, ModelView): if values.get('post_move_sequence'): for fiscalyear in fiscalyears: if (fiscalyear.post_move_sequence - and fiscalyear.post_move_sequence.id != - values['post_move_sequence']): + and fiscalyear.post_move_sequence.id + != values['post_move_sequence']): if Move.search([ ('period.fiscalyear', '=', fiscalyear.id), ('state', '=', 'posted'), diff --git a/journal.py b/journal.py index 2557ab1cf2..e85b607751 100644 --- a/journal.py +++ b/journal.py @@ -17,10 +17,6 @@ from trytond.tools.multivalue import migrate_property from trytond.modules.company.model import ( CompanyMultiValueMixin, CompanyValueMixin) -__all__ = ['Journal', 'JournalSequence', - 'JournalCashContext', - 'JournalPeriod'] - STATES = { 'readonly': Eval('state') == 'close', } diff --git a/move.py b/move.py index 8a3a59d16c..e59b3c971a 100644 --- a/move.py +++ b/move.py @@ -30,15 +30,6 @@ from .exceptions import (PostError, MoveDatesError, CancelWarning, ReconciliationError, DeleteDelegatedWarning, GroupLineError, CancelDelegatedWarning) -__all__ = ['Move', 'Reconciliation', 'Line', 'WriteOff', 'OpenJournalAsk', - 'OpenJournal', 'OpenAccount', - 'ReconcileLinesWriteOff', 'ReconcileLines', - 'UnreconcileLines', - 'Reconcile', 'ReconcileShow', - 'CancelMoves', 'CancelMovesDefault', - 'GroupLines', 'GroupLinesStart', - 'PrintGeneralJournalStart', 'PrintGeneralJournal', 'GeneralJournal'] - _MOVE_STATES = { 'readonly': Eval('state') == 'posted', } @@ -85,10 +76,10 @@ class Move(ModelSQL, ModelView): ('account.company', '=', Eval('company', -1)), ], states=_MOVE_STATES, depends=_MOVE_DEPENDS + ['company'], - context={ - 'journal': Eval('journal'), - 'period': Eval('period'), - 'date': Eval('date'), + context={ + 'journal': Eval('journal'), + 'period': Eval('period'), + 'date': Eval('date'), }) @classmethod @@ -443,7 +434,8 @@ class Move(ModelSQL, ModelView): move.post_number = Sequence.get_id( move.period.post_move_sequence_used.id) - keyfunc = lambda l: (l.party, l.account) + def keyfunc(l): + return l.party, l.account to_reconcile = [l for l in move.lines if ((l.debit == l.credit == Decimal('0')) and l.account.reconcile)] @@ -586,12 +578,12 @@ class Line(ModelSQL, ModelView): debit = fields.Numeric('Debit', digits=(16, Eval('currency_digits', 2)), required=True, states=_states, - depends=['currency_digits', 'credit', 'tax_lines', 'journal'] + - _depends) + depends=['currency_digits', 'credit', 'tax_lines', 'journal'] + + _depends) credit = fields.Numeric('Credit', digits=(16, Eval('currency_digits', 2)), required=True, states=_states, - depends=['currency_digits', 'debit', 'tax_lines', 'journal'] + - _depends) + depends=['currency_digits', 'debit', 'tax_lines', 'journal'] + + _depends) account = fields.Many2One('account.account', 'Account', required=True, domain=[ ('type', '!=', None), @@ -1375,8 +1367,8 @@ class OpenJournal(Wizard): def default_ask(self, fields): JournalPeriod = Pool().get('account.journal.period') - if (Transaction().context.get('active_model', '') == - 'account.journal.period' + if (Transaction().context.get('active_model', '') + == 'account.journal.period' and Transaction().context.get('active_id')): journal_period = JournalPeriod(Transaction().context['active_id']) return { @@ -1388,8 +1380,8 @@ class OpenJournal(Wizard): def do_open_(self, action): JournalPeriod = Pool().get('account.journal.period') - if (Transaction().context.get('active_model', '') == - 'account.journal.period' + if (Transaction().context.get('active_model', '') + == 'account.journal.period' and Transaction().context.get('active_id')): journal_period = JournalPeriod(Transaction().context['active_id']) journal = journal_period.journal diff --git a/move_template.py b/move_template.py index 0f1ca1c01f..0ea92397fc 100644 --- a/move_template.py +++ b/move_template.py @@ -14,10 +14,6 @@ from trytond.transaction import Transaction from trytond.pool import Pool from trytond.tools import decistmt -__all__ = ['MoveTemplate', 'MoveTemplateKeyword', - 'MoveLineTemplate', 'TaxLineTemplate', - 'CreateMove', 'CreateMoveTemplate', 'CreateMoveKeywords'] - class MoveTemplate(DeactivableMixin, ModelSQL, ModelView): 'Account Move Template' diff --git a/party.py b/party.py index ce3c463110..178b5e9098 100644 --- a/party.py +++ b/party.py @@ -20,7 +20,6 @@ from trytond.modules.party.exceptions import EraseError from .exceptions import AccountMissing -__all__ = ['Party', 'PartyAccount', 'PartyReplace', 'PartyErase'] account_names = [ 'account_payable', 'account_receivable', 'customer_tax_rule', 'supplier_tax_rule'] diff --git a/period.py b/period.py index 25182cfd4d..da437848a5 100644 --- a/period.py +++ b/period.py @@ -12,8 +12,6 @@ from trytond.const import OPERATORS from .exceptions import (PeriodNotFoundError, ClosePeriodError, PeriodDatesError, PeriodSequenceError) -__all__ = ['Period'] - _STATES = { 'readonly': Eval('state') != 'open', } @@ -212,7 +210,8 @@ class Period(Workflow, ModelSQL, ModelView): i = 0 while i < len(args): # add test for xmlrpc and pyson that doesn't handle tuple - if ((isinstance(args[i], tuple) + if (( + isinstance(args[i], tuple) or (isinstance(args[i], list) and len(args[i]) > 2 and args[i][1] in OPERATORS)) and args[i][0] in ('start_date', 'end_date') @@ -272,8 +271,8 @@ class Period(Workflow, ModelSQL, ModelView): if values.get('post_move_sequence'): for period in periods: if (period.post_move_sequence - and period.post_move_sequence.id != - values['post_move_sequence']): + and period.post_move_sequence.id + != values['post_move_sequence']): if Move.search([ ('period', '=', period.id), ('state', '=', 'posted'), diff --git a/setup.py b/setup.py index 3473440780..69e544c27f 100755 --- a/setup.py +++ b/setup.py @@ -79,8 +79,8 @@ setup(name=name, keywords='tryton account', package_dir={'trytond.modules.account': '.'}, packages=( - ['trytond.modules.account'] + - ['trytond.modules.account.%s' % p for p in find_packages()] + ['trytond.modules.account'] + + ['trytond.modules.account.%s' % p for p in find_packages()] ), package_data={ 'trytond.modules.account': (info.get('xml', []) @@ -94,7 +94,8 @@ setup(name=name, 'Intended Audience :: Developers', 'Intended Audience :: Financial and Insurance Industry', 'Intended Audience :: Legal Industry', - 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', + 'License :: OSI Approved :: ' + 'GNU General Public License v3 or later (GPLv3+)', 'Natural Language :: Bulgarian', 'Natural Language :: Catalan', 'Natural Language :: Chinese (Simplified)', diff --git a/tax.py b/tax.py index 89c301f170..c99e87c3f6 100644 --- a/tax.py +++ b/tax.py @@ -23,14 +23,6 @@ from trytond.pool import Pool from .common import PeriodMixin, ActivePeriodMixin -__all__ = ['TaxGroup', 'TaxCodeTemplate', 'TaxCode', - 'TaxCodeLineTemplate', 'TaxCodeLine', - 'OpenChartTaxCodeStart', 'OpenChartTaxCode', - 'TaxTemplate', 'Tax', 'TaxLine', 'TaxRuleTemplate', 'TaxRule', - 'TaxRuleLineTemplate', 'TaxRuleLine', - 'OpenTaxCode', - 'TestTax', 'TestTaxView', 'TestTaxViewResult'] - KINDS = [ ('sale', 'Sale'), ('purchase', 'Purchase'), @@ -1026,8 +1018,8 @@ class Tax(sequence_ordered(), ModelSQL, ModelView, DeactivableMixin): vals = child.template._get_tax_value(tax=child) invoice_account_id = (child.invoice_account.id if child.invoice_account else None) - if (child.template.invoice_account and - invoice_account_id != template2account.get( + if (child.template.invoice_account + and invoice_account_id != template2account.get( child.template.invoice_account.id)): vals['invoice_account'] = template2account.get( child.template.invoice_account.id) @@ -1036,8 +1028,9 @@ class Tax(sequence_ordered(), ModelSQL, ModelView, DeactivableMixin): vals['invoice_account'] = None credit_note_account_id = (child.credit_note_account.id if child.credit_note_account else None) - if (child.template.credit_note_account and - credit_note_account_id != template2account.get( + if (child.template.credit_note_account + and credit_note_account_id + != template2account.get( child.template.credit_note_account.id)): vals['credit_note_account'] = template2account.get( child.template.credit_note_account.id) @@ -1431,8 +1424,8 @@ class TaxRuleLineTemplate(sequence_ordered(), ModelSQL, ModelView): ('group', '=', None), If(Eval('_parent_rule', {}).get('kind', 'both') == 'sale', ('group.kind', 'in', ['sale', 'both']), - If(Eval('_parent_rule', {}).get('kind', 'both') == - 'purchase', + If(Eval('_parent_rule', {}).get('kind', 'both') + == 'purchase', ('group.kind', 'in', ['purchase', 'both']), ('group.kind', 'in', ['sale', 'purchase', 'both']))), ], @@ -1452,8 +1445,8 @@ class TaxRuleLineTemplate(sequence_ordered(), ModelSQL, ModelView): ('group', '=', None), If(Eval('_parent_rule', {}).get('kind', 'both') == 'sale', ('group.kind', 'in', ['sale', 'both']), - If(Eval('_parent_rule', {}).get('kind', 'both') == - 'purchase', + If(Eval('_parent_rule', {}).get('kind', 'both') + == 'purchase', ('group.kind', 'in', ['purchase', 'both']), ('group.kind', 'in', ['sale', 'purchase', 'both']))), ], @@ -1545,8 +1538,8 @@ class TaxRuleLine(sequence_ordered(), ModelSQL, ModelView, MatchMixin): ('group', '=', None), If(Eval('_parent_rule', {}).get('kind', 'both') == 'sale', ('group.kind', 'in', ['sale', 'both']), - If(Eval('_parent_rule', {}).get('kind', 'both') == - 'purchase', + If(Eval('_parent_rule', {}).get('kind', 'both') + == 'purchase', ('group.kind', 'in', ['purchase', 'both']), ('group.kind', 'in', ['sale', 'purchase', 'both']))), ], @@ -1566,8 +1559,8 @@ class TaxRuleLine(sequence_ordered(), ModelSQL, ModelView, MatchMixin): ('group', '=', None), If(Eval('_parent_rule', {}).get('kind', 'both') == 'sale', ('group.kind', 'in', ['sale', 'both']), - If(Eval('_parent_rule', {}).get('kind', 'both') == - 'purchase', + If(Eval('_parent_rule', {}).get('kind', 'both') + == 'purchase', ('group.kind', 'in', ['purchase', 'both']), ('group.kind', 'in', ['sale', 'purchase', 'both']))), ], @@ -1645,8 +1638,8 @@ class TaxRuleLine(sequence_ordered(), ModelSQL, ModelView, MatchMixin): vals['rule'] = template2rule[line.template.rule.id] if line.origin_tax: if line.template.origin_tax: - if (line.origin_tax.id != - template2tax[line.template.origin_tax.id]): + if (line.origin_tax.id + != template2tax[line.template.origin_tax.id]): vals['origin_tax'] = template2tax[ line.template.origin_tax.id] else: