changeset 17118afaf240 in modules/commission:default
details: 
https://hg.tryton.org/modules/commission?cmd=changeset;node=17118afaf240
description:
        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
diffstat:

 .flake8       |   2 ++
 __init__.py   |   6 +++---
 account.py    |   2 --
 commission.py |  18 +++++++++---------
 invoice.py    |   2 --
 party.py      |   8 ++++----
 product.py    |   3 ---
 sale.py       |  11 ++++-------
 setup.py      |   7 ++++---
 9 files changed, 26 insertions(+), 33 deletions(-)

diffs (208 lines):

diff -r 575b2649d2ad -r 17118afaf240 .flake8
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/.flake8   Sun Mar 01 12:33:52 2020 +0100
@@ -0,0 +1,2 @@
+[flake8]
+ignore=E123,E124,E126,E128,W503
diff -r 575b2649d2ad -r 17118afaf240 __init__.py
--- a/__init__.py       Mon Feb 24 18:38:48 2020 +0100
+++ b/__init__.py       Sun Mar 01 12:33:52 2020 +0100
@@ -28,11 +28,11 @@
         module='commission', type_='model')
     Pool.register(
         sale.Sale,
-        sale.SaleLine,
+        sale.Line,
         module='commission', type_='model',
         depends=['sale'])
     Pool.register(
         commission.CreateInvoice,
-        party.PartyReplace,
-        party.PartyErase,
+        party.Replace,
+        party.Erase,
         module='commission', type_='wizard')
diff -r 575b2649d2ad -r 17118afaf240 account.py
--- a/account.py        Mon Feb 24 18:38:48 2020 +0100
+++ b/account.py        Sun Mar 01 12:33:52 2020 +0100
@@ -2,8 +2,6 @@
 # this repository contains the full copyright notices and license terms.
 from trytond.pool import PoolMeta
 
-__all__ = ['Journal']
-
 
 class Journal(metaclass=PoolMeta):
     __name__ = 'account.journal'
diff -r 575b2649d2ad -r 17118afaf240 commission.py
--- a/commission.py     Mon Feb 24 18:38:48 2020 +0100
+++ b/commission.py     Sun Mar 01 12:33:52 2020 +0100
@@ -24,9 +24,6 @@
 
 from .exceptions import FormulaError
 
-__all__ = ['Agent', 'Plan', 'PlanLines', 'Commission',
-    'CreateInvoice', 'CreateInvoiceAsk']
-
 
 class Agent(ModelSQL, ModelView):
     'Commission Agent'
@@ -363,20 +360,23 @@
         pool = Pool()
         Invoice = pool.get('account.invoice')
 
-        key = lambda c: c._group_to_invoice_key()
-        commissions.sort(key=key)
+        def invoice_key(c):
+            return c._group_to_invoice_key()
+
+        def line_key(c):
+            return c._group_to_invoice_line_key()
+        commissions.sort(key=invoice_key)
         invoices = []
         to_write = []
-        for key, commissions in groupby(commissions, key=key):
+        for key, commissions in groupby(commissions, key=invoice_key):
             commissions = list(commissions)
             key = dict(key)
             invoice = cls._get_invoice(key)
             invoice.save()
             invoices.append(invoice)
 
-            key = lambda c: c._group_to_invoice_line_key()
-            commissions.sort(key=key)
-            for key, commissions in groupby(commissions, key=key):
+            commissions.sort(key=line_key)
+            for key, commissions in groupby(commissions, key=line_key):
                 commissions = [c for c in commissions if not c.invoice_line]
                 key = dict(key)
                 invoice_line = cls._get_invoice_line(key, invoice, commissions)
diff -r 575b2649d2ad -r 17118afaf240 invoice.py
--- a/invoice.py        Mon Feb 24 18:38:48 2020 +0100
+++ b/invoice.py        Sun Mar 01 12:33:52 2020 +0100
@@ -9,8 +9,6 @@
 from trytond.transaction import Transaction
 from trytond.tools import grouped_slice
 
-__all__ = ['Invoice', 'InvoiceLine']
-
 
 class Invoice(metaclass=PoolMeta):
     __name__ = 'account.invoice'
diff -r 575b2649d2ad -r 17118afaf240 party.py
--- a/party.py  Mon Feb 24 18:38:48 2020 +0100
+++ b/party.py  Sun Mar 01 12:33:52 2020 +0100
@@ -12,23 +12,23 @@
     agents = fields.One2Many('commission.agent.selection', 'party', "Agents")
 
 
-class PartyReplace(metaclass=PoolMeta):
+class Replace(metaclass=PoolMeta):
     __name__ = 'party.replace'
 
     @classmethod
     def fields_to_replace(cls):
-        return super(PartyReplace, cls).fields_to_replace() + [
+        return super().fields_to_replace() + [
             ('commission.agent', 'party'),
             ]
 
 
-class PartyErase(metaclass=PoolMeta):
+class Erase(metaclass=PoolMeta):
     __name__ = 'party.erase'
 
     def check_erase_company(self, party, company):
         pool = Pool()
         Commission = pool.get('commission')
-        super(PartyErase, self).check_erase_company(party, company)
+        super().check_erase_company(party, company)
 
         commissions = Commission.search([
                 ('agent.party', '=', party.id),
diff -r 575b2649d2ad -r 17118afaf240 product.py
--- a/product.py        Mon Feb 24 18:38:48 2020 +0100
+++ b/product.py        Sun Mar 01 12:33:52 2020 +0100
@@ -5,9 +5,6 @@
 from trytond.model import ModelSQL, fields
 
 
-__all__ = ['Template', 'Template_Agent', 'Product']
-
-
 class Template(metaclass=PoolMeta):
     __name__ = 'product.template'
     principals = fields.Many2Many('product.template-commission.agent',
diff -r 575b2649d2ad -r 17118afaf240 sale.py
--- a/sale.py   Mon Feb 24 18:38:48 2020 +0100
+++ b/sale.py   Sun Mar 01 12:33:52 2020 +0100
@@ -7,9 +7,6 @@
 from trytond.pyson import Eval
 
 
-__all__ = ['Sale', 'SaleLine']
-
-
 class Sale(metaclass=PoolMeta):
     __name__ = 'sale.sale'
     agent = fields.Many2One('commission.agent', 'Commission Agent',
@@ -69,7 +66,7 @@
         cls.save(sales)
 
 
-class SaleLine(metaclass=PoolMeta):
+class Line(metaclass=PoolMeta):
     __name__ = 'sale.line'
     principal = fields.Many2One('commission.agent', 'Commission Principal',
         domain=[
@@ -78,7 +75,7 @@
             ])
 
     def get_invoice_line(self):
-        lines = super(SaleLine, self).get_invoice_line()
+        lines = super().get_invoice_line()
         if self.principal:
             for line in lines:
                 if line.product == self.product:
@@ -87,7 +84,7 @@
 
     @fields.depends('product', 'principal')
     def on_change_product(self):
-        super(SaleLine, self).on_change_product()
+        super().on_change_product()
         if self.product:
             if self.product.principals:
                 if self.principal not in self.product.principals:
@@ -97,7 +94,7 @@
 
     @classmethod
     def view_attributes(cls):
-        return super(SaleLine, cls).view_attributes() + [
+        return super().view_attributes() + [
             ('//page[@id="commissions"]', 'states', {
                     'invisible': Eval('type') != 'line',
                     })]
diff -r 575b2649d2ad -r 17118afaf240 setup.py
--- a/setup.py  Mon Feb 24 18:38:48 2020 +0100
+++ b/setup.py  Sun Mar 01 12:33:52 2020 +0100
@@ -80,8 +80,8 @@
     keywords='tryton commission',
     package_dir={'trytond.modules.commission': '.'},
     packages=(
-        ['trytond.modules.commission'] +
-        ['trytond.modules.commission.%s' % p for p in find_packages()]
+        ['trytond.modules.commission']
+        + ['trytond.modules.commission.%s' % p for p in find_packages()]
         ),
     package_data={
         'trytond.modules.commission': (info.get('xml', [])
@@ -95,7 +95,8 @@
         '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)',

Reply via email to