changeset 67ed1b394b6e in modules/stock:default
details: https://hg.tryton.org/modules/stock?cmd=changeset;node=67ed1b394b6e
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      |    4 +-
 configuration.py |    1 -
 location.py      |    3 -
 move.py          |  206 ++++++++++++++++++++++++++++--------------------------
 party.py         |   10 +-
 period.py        |    2 -
 product.py       |    6 +-
 setup.py         |    7 +-
 shipment.py      |   15 +---
 10 files changed, 123 insertions(+), 133 deletions(-)

diffs (486 lines):

diff -r d8626b61190e -r 67ed1b394b6e .flake8
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/.flake8   Sun Mar 01 12:33:54 2020 +0100
@@ -0,0 +1,2 @@
+[flake8]
+ignore=E123,E124,E126,E128,W503
diff -r d8626b61190e -r 67ed1b394b6e __init__.py
--- a/__init__.py       Sat Feb 15 01:41:47 2020 +0100
+++ b/__init__.py       Sun Mar 01 12:33:54 2020 +0100
@@ -63,8 +63,8 @@
         product.RecomputeCostPrice,
         product.ModifyCostPrice,
         inventory.Count,
-        party.PartyReplace,
-        party.PartyErase,
+        party.Replace,
+        party.Erase,
         module='stock', type_='wizard')
     Pool.register(
         shipment.DeliveryNote,
diff -r d8626b61190e -r 67ed1b394b6e configuration.py
--- a/configuration.py  Sat Feb 15 01:41:47 2020 +0100
+++ b/configuration.py  Sun Mar 01 12:33:54 2020 +0100
@@ -9,7 +9,6 @@
 from trytond.modules.company.model import (
     CompanyMultiValueMixin, CompanyValueMixin)
 
-__all__ = ['Configuration', 'ConfigurationSequence', 'ConfigurationLocation']
 sequences = ['shipment_in_sequence', 'shipment_in_return_sequence',
     'shipment_out_sequence', 'shipment_out_return_sequence',
     'shipment_internal_sequence', 'inventory_sequence']
diff -r d8626b61190e -r 67ed1b394b6e location.py
--- a/location.py       Sat Feb 15 01:41:47 2020 +0100
+++ b/location.py       Sun Mar 01 12:33:54 2020 +0100
@@ -18,9 +18,6 @@
 
 from .exceptions import LocationValidationError
 
-__all__ = ['Location', 'Party', 'PartyLocation', 'ProductsByLocationsContext',
-    'LocationLeadTime']
-
 STATES = {
     'readonly': ~Eval('active'),
 }
diff -r d8626b61190e -r 67ed1b394b6e move.py
--- a/move.py   Sat Feb 15 01:41:47 2020 +0100
+++ b/move.py   Sun Mar 01 12:33:54 2020 +0100
@@ -23,8 +23,6 @@
 
 from .exceptions import MoveOriginWarning
 
-__all__ = ['StockMixin', 'Move']
-
 STATES = {
     'readonly': Eval('state').in_(['cancel', 'assigned', 'done']),
 }
@@ -100,8 +98,8 @@
 
         for key, quantity in pbl.items():
             # pbl could return None in some keys
-            if (key[position] is not None and
-                    key[position] in quantities):
+            if (key[position] is not None
+                    and key[position] in quantities):
                 quantities[key[position]] += quantity
         return quantities
 
@@ -270,8 +268,8 @@
         super(Move, cls).__setup__()
         cls._deny_modify_assigned = set(['product', 'uom', 'quantity',
             'from_location', 'to_location', 'company', 'currency'])
-        cls._deny_modify_done_cancel = (cls._deny_modify_assigned |
-            set(['planned_date', 'effective_date', 'state']))
+        cls._deny_modify_done_cancel = (cls._deny_modify_assigned
+            | set(['planned_date', 'effective_date', 'state']))
         cls._allow_modify_closed_period = {'cost_price'}
 
         t = cls.__table__()
@@ -740,8 +738,8 @@
             return
 
         def no_origin(move):
-            return ((move.from_location.type in types) ^
-                (move.to_location.type in types)
+            return ((move.from_location.type in types)
+                ^ (move.to_location.type in types)
                 and not move.origin)
         moves = list(filter(no_origin, moves))
         if moves:
@@ -1061,9 +1059,9 @@
                     move.to_location.as_('to_location'),
                     *columns,
                     where=(Coalesce(from_parent_location.flat_childs, False)
-                        != True)
+                        != Literal(True))
                     & (Coalesce(to_parent_location.flat_childs, False)
-                        != True)),
+                        != Literal(True))),
                 # Append moves linked from/to flat locations to their parents
                 move_with_parent.select(
                     Case(
@@ -1075,8 +1073,8 @@
                             to_parent_location.id),
                         else_=move.to_location).as_('to_location'),
                     *columns,
-                    where=(from_parent_location.flat_childs == True)
-                    | (to_parent_location.flat_childs == True)),
+                    where=(from_parent_location.flat_childs == Literal(True))
+                    | (to_parent_location.flat_childs == Literal(True))),
                 # Append moves linked to from/to flat locations only
                 move_with_parent.select(
                     Case(
@@ -1088,8 +1086,8 @@
                             to_location.id),
                         else_=Null).as_('to_location'),
                     *columns,
-                    where=(from_parent_location.flat_childs == True)
-                    | (to_parent_location.flat_childs == True)),
+                    where=(from_parent_location.flat_childs == Literal(True))
+                    | (to_parent_location.flat_childs == Literal(True))),
                 all_=True)
 
             if PeriodCache:
@@ -1108,7 +1106,7 @@
                         ).select(
                         parent_location.id.as_('location'),
                         *columns,
-                        where=parent_location.flat_childs == True),
+                        where=parent_location.flat_childs == Literal(True)),
                     all_=True)
 
         if not context.get('stock_date_end'):
@@ -1118,20 +1116,21 @@
         if (context['stock_date_end'] < today
                 or (context['stock_date_end'] == today
                     and not context.get('forecast'))):
-            state_date_clause = lambda stock_assign: (
-                move.state.in_(['done',
+
+            def state_date_clause(stock_assign):
+                return (move.state.in_(['done',
                         'assigned' if stock_assign else 'done'])
-                & (
-                    (
-                        (move.effective_date == Null)
-                        & (move.planned_date <= context['stock_date_end'])
-                        )
-                    | (move.effective_date <= context['stock_date_end'])
-                    | (move.state == (
-                            'assigned' if not context.get('stock_date_start')
-                            else ''))
-                    )
-                )
+                    & (
+                        (
+                            (move.effective_date == Null)
+                            & (move.planned_date <= context['stock_date_end'])
+                            )
+                        | (move.effective_date <= context['stock_date_end'])
+                        | (move.state == (
+                                'assigned'
+                                if not context.get('stock_date_start')
+                                else ''))
+                        ))
             state_date_clause_in = state_date_clause(False)
             state_date_clause_out = state_date_clause(
                 context.get('stock_assign'))
@@ -1139,101 +1138,105 @@
         # before today, or on all state and date between today and
         # date_end.
         else:
-            state_date_clause = lambda stock_assign: (
-                (move.state.in_(['done',
-                            'assigned' if stock_assign else 'done'])
-                    & (
-                        (
-                            (move.effective_date == Null)
-                            & (move.planned_date <= today)
+            def state_date_clause(stock_assign):
+                return ((move.state.in_(['done',
+                                'assigned' if stock_assign else 'done'])
+                        & (
+                            (
+                                (move.effective_date == Null)
+                                & (move.planned_date <= today)
+                                )
+                            | (move.effective_date <= today)
+                            | (move.state == (
+                                    'assigned'
+                                    if not context.get('stock_date_start')
+                                    else ''))
                             )
-                        | (move.effective_date <= today)
-                        | (move.state == (
-                                'assigned'
-                                if not context.get('stock_date_start')
-                                else ''))
+                        )
+                    | (move.state.in_(['done', 'assigned', 'draft'])
+                        & (
+                            (
+                                (move.effective_date == Null)
+                                & (Coalesce(
+                                        move.planned_date, datetime.date.max)
+                                    <= context['stock_date_end'])
+                                & (Coalesce(
+                                        move.planned_date, datetime.date.max)
+                                    >= today)
+                                )
+                            | (
+                                (move.effective_date
+                                    <= context['stock_date_end'])
+                                & (move.effective_date >= today)
+                                )
+                            | (move.state == (
+                                    'assigned'
+                                    if not context.get('stock_date_start')
+                                    else ''))
+                            )
                         )
                     )
-                | (move.state.in_(['done', 'assigned', 'draft'])
-                    & (
-                        (
-                            (move.effective_date == Null)
-                            & (Coalesce(move.planned_date, datetime.date.max)
-                                <= context['stock_date_end'])
-                            & (Coalesce(move.planned_date, datetime.date.max)
-                                >= today)
-                            )
-                        | (
-                            (move.effective_date <= context['stock_date_end'])
-                            & (move.effective_date >= today)
-                            )
-                        | (move.state == (
-                                'assigned'
-                                if not context.get('stock_date_start')
-                                else ''))
-                        )
-                    )
-                )
             state_date_clause_in = state_date_clause(False)
             state_date_clause_out = state_date_clause(
                 context.get('stock_assign'))
 
         if context.get('stock_date_start'):
             if context['stock_date_start'] > today:
-                state_date_clause = lambda: (
-                    move.state.in_(['done', 'assigned', 'draft'])
-                    & (
-                        (
-                            (move.effective_date == Null)
-                            & (
-                                (move.planned_date >=
-                                    context['stock_date_start'])
-                                | (move.planned_date == Null)
-                                )
-                            )
-                        | (move.effective_date >= context['stock_date_start'])
-                        )
-                    )
-                state_date_clause_in &= state_date_clause()
-                state_date_clause_out &= state_date_clause()
-            else:
-                state_date_clause = lambda stock_assign: (
-                    (
-                        move.state.in_(['done', 'assigned', 'draft'])
+                def state_date_clause():
+                    return (move.state.in_(['done', 'assigned', 'draft'])
                         & (
                             (
                                 (move.effective_date == Null)
                                 & (
-                                    (move.planned_date >= today)
+                                    (move.planned_date
+                                        >= context['stock_date_start'])
                                     | (move.planned_date == Null)
                                     )
                                 )
-                            | (move.effective_date >= today)
+                            | (move.effective_date
+                                >= context['stock_date_start'])
                             )
                         )
-                    | (
-                        move.state.in_(['done',
-                                'assigned' if stock_assign else 'done'])
-                        & (
-                            (
-                                (move.effective_date == Null)
-                                & (
-                                    (
-                                        (move.planned_date >=
-                                            context['stock_date_start'])
-                                        & (move.planned_date < today)
+                state_date_clause_in &= state_date_clause()
+                state_date_clause_out &= state_date_clause()
+            else:
+                def state_date_clause(stock_assign):
+                    return ((
+                            move.state.in_(['done', 'assigned', 'draft'])
+                            & (
+                                (
+                                    (move.effective_date == Null)
+                                    & (
+                                        (move.planned_date >= today)
+                                        | (move.planned_date == Null)
                                         )
-                                    | (move.planned_date == Null)
                                     )
+                                | (move.effective_date >= today)
                                 )
-                            | (
-                                (move.effective_date >=
-                                    context['stock_date_start'])
-                                & (move.effective_date < today)
+                            )
+                        | (
+                            move.state.in_(['done',
+                                    'assigned' if stock_assign else 'done'])
+                            & (
+                                (
+                                    (move.effective_date == Null)
+                                    & (
+                                        (
+                                            (move.planned_date
+                                                >= context['stock_date_start'])
+                                            & (move.planned_date < today)
+                                            )
+                                        | (move.planned_date == Null)
+                                        )
+                                    )
+                                | (
+                                    (move.effective_date
+                                        >= context['stock_date_start'])
+                                    & (move.effective_date < today)
+                                    )
                                 )
                             )
                         )
-                    )
                 state_date_clause_in &= state_date_clause(False)
                 state_date_clause_out &= state_date_clause(
                     context.get('stock_assign'))
@@ -1245,8 +1248,9 @@
                     ], order=[('date', 'DESC')], limit=1)
             if periods:
                 period, = periods
-                state_date_clause = lambda: (
-                    Coalesce(move.effective_date, move.planned_date,
+
+                def state_date_clause():
+                    return (Coalesce(move.effective_date, move.planned_date,
                         datetime.date.max) > period.date)
                 state_date_clause_in &= state_date_clause()
                 state_date_clause_out &= state_date_clause()
diff -r d8626b61190e -r 67ed1b394b6e party.py
--- a/party.py  Sat Feb 15 01:41:47 2020 +0100
+++ b/party.py  Sun Mar 01 12:33:54 2020 +0100
@@ -5,15 +5,13 @@
 
 from trytond.modules.party.exceptions import EraseError
 
-__all__ = ['PartyReplace', 'PartyErase']
 
-
-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() + [
             ('stock.shipment.in', 'supplier'),
             ('stock.shipment.in.return', 'supplier'),
             ('stock.shipment.out', 'customer'),
@@ -21,7 +19,7 @@
             ]
 
 
-class PartyErase(metaclass=PoolMeta):
+class Erase(metaclass=PoolMeta):
     __name__ = 'party.erase'
 
     def check_erase_company(self, party, company):
@@ -30,7 +28,7 @@
         ShipmentInReturn = pool.get('stock.shipment.in.return')
         ShipmentOut = pool.get('stock.shipment.out')
         ShipmentOutReturn = pool.get('stock.shipment.out.return')
-        super(PartyErase, self).check_erase_company(party, company)
+        super().check_erase_company(party, company)
 
         for Shipment, field in [
                 (ShipmentIn, 'supplier'),
diff -r d8626b61190e -r 67ed1b394b6e period.py
--- a/period.py Sat Feb 15 01:41:47 2020 +0100
+++ b/period.py Sun Mar 01 12:33:54 2020 +0100
@@ -13,8 +13,6 @@
 
 from .exceptions import PeriodCloseError
 
-__all__ = ['Period', 'Cache']
-
 
 class Period(Workflow, ModelSQL, ModelView):
     'Stock Period'
diff -r d8626b61190e -r 67ed1b394b6e product.py
--- a/product.py        Sat Feb 15 01:41:47 2020 +0100
+++ b/product.py        Sun Mar 01 12:33:54 2020 +0100
@@ -715,7 +715,8 @@
                 revision.product = product
                 revision.template = product.template
                 revisions.append(revision)
-                if ((product.cost_price_method == 'fixed'
+                if ((
+                            product.cost_price_method == 'fixed'
                             and revision.date == today)
                         or product.type == 'service'):
                     cost = revision.get_cost_price(product.cost_price)
@@ -728,7 +729,8 @@
                 revision = self.get_revision(Revision)
                 revision.template = template
                 revisions.append(revision)
-                if ((template.cost_price_method == 'fixed'
+                if ((
+                            template.cost_price_method == 'fixed'
                             and revision.date == today)
                         or product.type == 'service'):
                     for product in template.products:
diff -r d8626b61190e -r 67ed1b394b6e setup.py
--- a/setup.py  Sat Feb 15 01:41:47 2020 +0100
+++ b/setup.py  Sun Mar 01 12:33:54 2020 +0100
@@ -79,8 +79,8 @@
     keywords='tryton stock',
     package_dir={'trytond.modules.stock': '.'},
     packages=(
-        ['trytond.modules.stock'] +
-        ['trytond.modules.stock.%s' % p for p in find_packages()]
+        ['trytond.modules.stock']
+        + ['trytond.modules.stock.%s' % p for p in find_packages()]
         ),
     package_data={
         'trytond.modules.stock': (info.get('xml', [])
@@ -95,7 +95,8 @@
         'Intended Audience :: Financial and Insurance Industry',
         'Intended Audience :: Legal Industry',
         'Intended Audience :: Manufacturing',
-        '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 -r d8626b61190e -r 67ed1b394b6e shipment.py
--- a/shipment.py       Sat Feb 15 01:41:47 2020 +0100
+++ b/shipment.py       Sun Mar 01 12:33:54 2020 +0100
@@ -16,17 +16,6 @@
 from trytond.transaction import Transaction
 from trytond.pool import Pool, PoolMeta
 
-__all__ = ['ShipmentIn', 'ShipmentInReturn',
-    'ShipmentOut', 'ShipmentOutReturn',
-    'AssignShipmentOutAssignFailed', 'AssignShipmentOut',
-    'ShipmentInternal',
-    'Address',
-    'AssignShipmentInternalAssignFailed', 'AssignShipmentInternal',
-    'AssignShipmentInReturnAssignFailed', 'AssignShipmentInReturn',
-    'DeliveryNote', 'PickingList',
-    'SupplierRestockingList', 'CustomerReturnRestockingList',
-    'InteralShipmentReport']
-
 
 def set_employee(field):
     def decorator(func):
@@ -2022,8 +2011,8 @@
                     'depends': ['state'],
                     },
                 'ship': {
-                    'invisible': ((Eval('state') != 'assigned') |
-                        ~Eval('transit_location')),
+                    'invisible': ((Eval('state') != 'assigned')
+                        | ~Eval('transit_location')),
                     'depends': ['state', 'transit_location'],
                     },
                 'done': {

Reply via email to