Migration to 5.0

This commit is contained in:
Javier Uribe 2019-02-26 11:03:17 +01:00
parent e20921f9e0
commit 1c740b25d9
11 changed files with 83 additions and 113 deletions

View File

@ -32,27 +32,15 @@ services:
matrix:
include:
- IMAGE: python:2.7
TOXENV: py27
DATABASE: sqlite
- IMAGE: python:2.7
TOXENV: py27
DATABASE: postgresql
- IMAGE: python:3.4
TOXENV: py34
DATABASE: sqlite
- IMAGE: python:3.4
TOXENV: py34
DATABASE: postgresql
- IMAGE: python:3.5
TOXENV: py35
DATABASE: sqlite
- IMAGE: python:3.5
TOXENV: py35
DATABASE: postgresql
- IMAGE: python:3.6
TOXENV: py36
DATABASE: sqlite
- IMAGE: python:3.6
TOXENV: py36
DATABASE: postgresql
- IMAGE: python:3.7
TOXENV: py37
DATABASE: sqlite
- IMAGE: python:3.7
TOXENV: py37
DATABASE: postgresql

31
load.py
View File

@ -19,9 +19,8 @@ __all__ = ['Configuration', 'Load', 'LoadOrder', 'LoadOrderLine',
'CreateLoadDataLineMixin']
class Configuration:
class Configuration(metaclass=PoolMeta):
__name__ = 'carrier.configuration'
__metaclass__ = PoolMeta
ul_origin_restrict = fields.Boolean('Restrict UL origin',
help='Restricts origin of UL when loading in a Load order.')
@ -31,9 +30,8 @@ class Configuration:
return True
class Load:
class Load(metaclass=PoolMeta):
__name__ = 'carrier.load'
__metaclass__ = PoolMeta
unit_loads = fields.Function(
fields.One2Many('stock.unit_load', None, 'Unit loads'),
@ -50,9 +48,8 @@ class Load:
return [('orders.unit_loads', ) + tuple(clause[1:])]
class LoadOrder:
class LoadOrder(metaclass=PoolMeta):
__name__ = 'carrier.load.order'
__metaclass__ = PoolMeta
unit_loads = fields.Function(
fields.One2Many('stock.unit_load', None, 'Unit loads',
@ -71,7 +68,7 @@ class LoadOrder:
super(LoadOrder, cls).__setup__()
cls._buttons.update({
'run_try': {
'icon': 'tryton-go-next',
'icon': 'tryton-forward',
'invisible': ~Eval('state').in_(['waiting', 'running']),
'depends': ['state']},
})
@ -247,7 +244,7 @@ class LoadOrder:
for key, grouped_items in groupby(items, key=keyfunc):
_groupitems = list(grouped_items)
key_dict = dict(key)
_fields = key_dict.keys()
_fields = list(key_dict.keys())
def get_line_values(line):
line_values = []
@ -261,7 +258,7 @@ class LoadOrder:
sale_line = None
if self.sale:
sale_line = [l for l in self.sale.lines
if get_line_values(l) == key_dict.values()]
if get_line_values(l) == list(key_dict.values())]
if self.type == 'out':
if not sale_line:
@ -495,9 +492,8 @@ class LoadOrder:
return res
class LoadOrderLine:
class LoadOrderLine(metaclass=PoolMeta):
__name__ = 'carrier.load.order.line'
__metaclass__ = PoolMeta
ul_quantity = fields.Float('ULs', digits=(16, 0),
domain=[('ul_quantity', '>=', Eval('loaded_uls'))],
@ -580,7 +576,7 @@ class LoadUnitLoad(Wizard):
data = StateView('carrier.load_uls.data',
'carrier_load_ul.load_uls_data_view_form', [
Button('Exit', 'end', 'tryton-cancel'),
Button('Unload ULs', 'unload_', 'tryton-clear'),
Button('Unload ULs', 'unload_', 'tryton-undo'),
Button('Do', 'do_', 'tryton-ok', states={
'readonly': Eval('ul_code') | Eval('uls_to_load'),
'invisible': (Eval('order_state') == 'done')}),
@ -619,7 +615,7 @@ class LoadUnitLoad(Wizard):
res = {'load_order': order.id,
'loaded_uls': 0,
'standalone': standalone,
'uls_loaded_domain': map(int, order.unit_loads) or [],
'uls_loaded_domain': list(map(int, order.unit_loads)) or [],
'order_state': order.state}
if order.unit_loads:
res['loaded_uls'] = len(order.unit_loads)
@ -696,9 +692,8 @@ class LoadUnitLoad(Wizard):
return 'data'
class LoadSheet:
class LoadSheet(metaclass=PoolMeta):
__name__ = 'carrier.load.sheet'
__metaclass__ = PoolMeta
@classmethod
def get_context(cls, records, data):
@ -754,14 +749,12 @@ class TransportReportMixin(object):
if ul.product.id == product.id) or None
class CMR(TransportReportMixin):
class CMR(TransportReportMixin, metaclass=PoolMeta):
__name__ = 'carrier.load.order.cmr'
__metaclass__ = PoolMeta
class RoadTransportNote(TransportReportMixin):
class RoadTransportNote(TransportReportMixin, metaclass=PoolMeta):
__name__ = 'carrier.load.order.road_note'
__metaclass__ = PoolMeta
class CreateLoadDataMixin(object):

10
sale.py
View File

@ -12,9 +12,8 @@ __all__ = ['Sale', 'SaleLine', 'CreateLoadFromSale', 'CreateLoadLineFromSale',
'CreateLoad']
class Sale:
class Sale(metaclass=PoolMeta):
__name__ = 'sale.sale'
__metaclass__ = PoolMeta
load_lines = fields.Function(
fields.One2Many('carrier.load.order.line', None, 'Load lines'),
@ -45,7 +44,7 @@ class Sale:
loads = []
for line in self.lines:
if line.load_lines:
loads.extend(map(int, line.load_lines))
loads.extend(list(map(int, line.load_lines)))
return loads
def get_ul_loaded_quantity(self, name=None):
@ -122,9 +121,8 @@ class Sale:
super(Sale, cls).process(sales)
class SaleLine:
class SaleLine(metaclass=PoolMeta):
__name__ = 'sale.line'
__metaclass__ = PoolMeta
load_lines = fields.One2Many('carrier.load.order.line', 'origin',
'Load lines', readonly=True)
@ -338,7 +336,7 @@ class CreateLoad(Wizard):
if len(load_order_keys) > 1:
self.raise_user_error('wrong_load_order',
self.data.load_order.rec_name)
_key = load_order_keys.iterkeys().next()
_key = next(iter(load_order_keys.keys()))
if (_data_state.load_order.lines and
any(_key != self._get_grouping_load_order_key(l.origin)
for l in _data_state.load_order.lines)):

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms.
@ -6,10 +6,7 @@ from setuptools import setup
import re
import os
import io
try:
from configparser import ConfigParser
except ImportError:
from ConfigParser import ConfigParser
from configparser import ConfigParser
MODULE2PREFIX = {
'carrier_load': 'datalife',
@ -25,6 +22,7 @@ def read(fname):
'r', encoding='utf-8').read()
def get_require_version(name):
if minor_version % 2:
require = '%s >= %s.%s.dev0, < %s.%s'
@ -35,6 +33,7 @@ def get_require_version(name):
return require
config = ConfigParser()
config.readfp(open('tryton.cfg'))
info = dict(config.items('tryton'))
@ -52,10 +51,13 @@ requires = []
for dep in info.get('depends', []):
if not re.match(r'(ir|res)(\W|$)', dep):
prefix = MODULE2PREFIX.get(dep, 'trytond')
requires.append(get_require_version('%s_%s' % (prefix, dep)))
requires.append(get_require_version('trytond'))
tests_require = [
get_require_version('proteus'),
'datalife_stock_move_done2cancel'
]
@ -135,15 +137,16 @@ setup(name=name,
'Natural Language :: Slovenian',
'Natural Language :: Spanish',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Office/Business',
],
license='GPL-3',
python_requires='>=3.4',
install_requires=requires,
dependency_links=dependency_links,
zip_safe=False,
@ -154,11 +157,4 @@ setup(name=name,
test_suite='tests',
test_loader='trytond.test_loader:Loader',
tests_require=tests_require,
use_2to3=True,
convert_2to3_doctests=[
'tests/scenario_load_ul.rst',
'tests/scenario_load_ul_internal.rst',
'tests/scenario_force_unload.rst',
'tests/scenario_load_sale.rst',
],
)

View File

@ -160,7 +160,7 @@ Create load order::
True
>>> order.click('wait')
>>> order.state
u'waiting'
'waiting'
Create unit load::
@ -220,7 +220,7 @@ Starting load wizard::
1
>>> order.reload()
>>> order.state
u'running'
'running'
>>> order.start_date != None
True
>>> len(order.unit_loads)
@ -243,7 +243,7 @@ Add an invalid UL::
>>> start_load.execute('load_') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
UserError: ('UserError', (u'UL "2" must be in a storage location.', ''))
UserError: ('UserError', ('UL "2" must be in a storage location.', ''))
>>> move_ul = Wizard('stock.unit_load.do_move', [ul2])
>>> move_ul.form.location = ul.location
>>> move_ul.form.date = ul2.end_date + relativedelta(minutes=45)
@ -255,7 +255,7 @@ Add an invalid UL::
>>> start_load.execute('load_') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
UserError: ('UserError', (u'All valid lines of load order "1" are complete. Cannot load more ULs.', ''))
UserError: ('UserError', ('All valid lines of load order "1" are complete. Cannot load more ULs.', ''))
Unload UL::
@ -302,7 +302,7 @@ Finish loading::
>>> len(order.unit_loads)
1
>>> order.state
u'done'
'done'
Check sale::
@ -311,7 +311,7 @@ Check sale::
>>> order.sale != None
True
>>> order.sale.state
u'quotation'
'quotation'
>>> order.sale.number != None
True
>>> len(order.sale.lines)
@ -336,7 +336,7 @@ Check sale::
>>> len(order.inventory_moves)
1
>>> order.inventory_moves[0].product.rec_name
u'Plastic Case 30x30'
'Plastic Case 30x30'
>>> order.inventory_moves[0].quantity
2.0
>>> order.inventory_moves[0].start_date == order.start_date
@ -346,7 +346,7 @@ Check sale::
>>> len(order.outgoing_moves)
1
>>> order.outgoing_moves[0].product.rec_name
u'Plastic Case 30x30'
'Plastic Case 30x30'
>>> order.outgoing_moves[0].quantity
2.0
@ -390,9 +390,9 @@ Force load another UL::
>>> len(shipment.inventory_moves)
2
>>> list(set(m.state for m in shipment.outgoing_moves))
[u'assigned']
['assigned']
>>> list(set(m.state for m in shipment.inventory_moves))
[u'done']
['done']
>>> order.reload()
>>> len(order.inventory_moves)
2
@ -427,9 +427,9 @@ Force unload UL::
>>> len(shipment.inventory_moves)
1
>>> list(set(m.state for m in shipment.outgoing_moves))
[u'assigned']
['assigned']
>>> list(set(m.state for m in shipment.inventory_moves))
[u'done']
['done']
>>> order.reload()
>>> len(order.inventory_moves)
1

View File

@ -199,7 +199,7 @@ Start loading::
>>> start_load = Wizard('carrier.load.create_wizard', [sale]) # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
UserError: ('UserError', (u'Sale "1" must be Confirmed or Processing to be loaded.', ''))
UserError: ('UserError', ('Sale "1" must be Confirmed or Processing to be loaded.', ''))
>>> sale.click('confirm')
>>> start_load = Wizard('carrier.load.create_wizard', [sale])
>>> len(start_load.form.lines)
@ -230,7 +230,7 @@ Check load order::
>>> len(load_order.lines)
2
>>> load_order.state
u'draft'
'draft'
>>> load_order.sale.id == sale.id
True
>>> load_order.click('wait')
@ -252,9 +252,9 @@ Check sale::
>>> sale.reload()
>>> sale.shipment_method
u'manual'
'manual'
>>> sale.invoice_method
u'shipment'
'shipment'
>>> len(sale.loads)
1
>>> len(sale.load_lines)
@ -274,7 +274,7 @@ Check UL quantity control::
>>> loading.execute('load_') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
UserError: ('UserError', (u'Cannot exceed quantity of "Product".', ''))
UserError: ('UserError', ('Cannot exceed quantity of "Product".', ''))
Start loading ULs restrictions::
@ -305,7 +305,7 @@ Finish loading::
>>> len(load_order.unit_loads)
3
>>> load_order.state
u'done'
'done'
>>> sale.reload()
>>> len(sale.shipments)
1

View File

@ -160,7 +160,7 @@ Create load order::
True
>>> order.click('wait')
>>> order.state
u'waiting'
'waiting'
Create unit load::
@ -230,7 +230,7 @@ Check UL loading restrictions::
>>> start_load.execute('load_') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
UserError: ('UserError', (u'UL "1" must be in Done state.', ''))
UserError: ('UserError', ('UL "1" must be in Done state.', ''))
>>> ul.click('assign')
>>> ul.click('do')
>>> ul.available
@ -242,7 +242,7 @@ Check UL loading restrictions::
1
>>> order.reload()
>>> order.state
u'running'
'running'
>>> order.start_date != None
True
>>> len(order.unit_loads)
@ -255,7 +255,7 @@ Check UL loading restrictions::
>>> start_load.execute('load_') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
UserError: ('UserError', (u'UL "1" is already loaded.', ''))
UserError: ('UserError', ('UL "1" is already loaded.', ''))
Add an invalid UL::
@ -275,7 +275,7 @@ Add an invalid UL::
>>> start_load.execute('load_') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
UserError: ('UserError', (u'UL "2" must be in a storage location.', ''))
UserError: ('UserError', ('UL "2" must be in a storage location.', ''))
>>> move_ul = Wizard('stock.unit_load.do_move', [ul2])
>>> move_ul.form.location = ul.location
>>> move_ul.form.date = ul2.end_date + relativedelta(minutes=45)
@ -287,7 +287,7 @@ Add an invalid UL::
>>> start_load.execute('load_') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
UserError: ('UserError', (u'All valid lines of load order "1" are complete. Cannot load more ULs.', ''))
UserError: ('UserError', ('All valid lines of load order "1" are complete. Cannot load more ULs.', ''))
Unload UL::
@ -334,7 +334,7 @@ Finish loading::
>>> len(order.unit_loads)
1
>>> order.state
u'done'
'done'
Check sale::
@ -343,7 +343,7 @@ Check sale::
>>> order.sale != None
True
>>> order.sale.state
u'quotation'
'quotation'
>>> order.sale.number != None
True
>>> len(order.sale.lines)
@ -368,7 +368,7 @@ Check sale::
>>> len(order.inventory_moves)
1
>>> order.inventory_moves[0].product.rec_name
u'Plastic Case 30x30'
'Plastic Case 30x30'
>>> order.inventory_moves[0].quantity
2.0
>>> order.inventory_moves[0].start_date == order.start_date
@ -378,7 +378,7 @@ Check sale::
>>> len(order.outgoing_moves)
1
>>> order.outgoing_moves[0].product.rec_name
u'Plastic Case 30x30'
'Plastic Case 30x30'
>>> order.outgoing_moves[0].quantity
2.0
>>> order.shipment == shipment
@ -424,9 +424,9 @@ Force load another UL::
>>> len(shipment.inventory_moves)
2
>>> list(set(m.state for m in shipment.outgoing_moves))
[u'assigned']
['assigned']
>>> list(set(m.state for m in shipment.inventory_moves))
[u'done']
['done']
>>> order.reload()
>>> len(order.inventory_moves)
2
@ -442,7 +442,7 @@ Confirm load::
>>> load.click('confirm')
>>> load.reload()
>>> load.state
u'confirmed'
'confirmed'
Create purchase::
@ -467,11 +467,11 @@ Create purchase::
>>> load.click('do')
>>> load.reload()
>>> load.state
u'done'
'done'
>>> load.purchase != None
True
>>> load.purchase_state
u'quotation'
'quotation'
>>> order.reload()
>>> order.carrier_amount
Decimal('300.00')

View File

@ -167,7 +167,7 @@ Create load order::
True
>>> order.click('wait')
>>> order.state
u'waiting'
'waiting'
Create unit load::
@ -237,7 +237,7 @@ Check UL loading restrictions::
>>> start_load.execute('load_') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
UserError: ('UserError', (u'UL "1" must be in Done state.', ''))
UserError: ('UserError', ('UL "1" must be in Done state.', ''))
>>> ul.click('assign')
>>> ul.click('do')
>>> bool(ul.available)
@ -249,7 +249,7 @@ Check UL loading restrictions::
1
>>> order.reload()
>>> order.state
u'running'
'running'
>>> order.start_date != None
True
>>> len(order.unit_loads)
@ -262,7 +262,7 @@ Check UL loading restrictions::
>>> start_load.execute('load_') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
UserError: ('UserError', (u'UL "1" is already loaded.', ''))
UserError: ('UserError', ('UL "1" is already loaded.', ''))
Add an invalid UL::
@ -282,7 +282,7 @@ Add an invalid UL::
>>> start_load.execute('load_') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
UserError: ('UserError', (u'UL "2" must be in a storage location.', ''))
UserError: ('UserError', ('UL "2" must be in a storage location.', ''))
>>> move_ul = Wizard('stock.unit_load.do_move', [ul2])
>>> move_ul.form.location = ul.location
>>> move_ul.form.date = ul2.end_date + relativedelta(minutes=45)
@ -294,7 +294,7 @@ Add an invalid UL::
>>> start_load.execute('load_') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
UserError: ('UserError', (u'All valid lines of load order "1" are complete. Cannot load more ULs.', ''))
UserError: ('UserError', ('All valid lines of load order "1" are complete. Cannot load more ULs.', ''))
Unload UL::
@ -342,7 +342,7 @@ Finish loading::
>>> len(order.unit_loads)
1
>>> order.state
u'done'
'done'
Check internal shipment::
@ -350,7 +350,7 @@ Check internal shipment::
>>> not shipment
False
>>> shipment.state
u'assigned'
'assigned'
>>> shipment.planned_date == order.end_date.date()
True
>>> shipment.effective_date == order.end_date.date()
@ -358,7 +358,7 @@ Check internal shipment::
>>> len(shipment.moves)
2
>>> list(set(m.state for m in shipment.moves))
[u'assigned']
['assigned']
>>> shipment.moves[0].unit_load.id == ul.id
True
>>> not order.inventory_moves
@ -396,7 +396,7 @@ Force load another UL::
>>> len(shipment.moves)
4
>>> list(set(m.state for m in shipment.moves))
[u'assigned']
['assigned']
>>> order.reload()
>>> not order.inventory_moves
True

13
tox.ini
View File

@ -1,18 +1,15 @@
[tox]
envlist = {py27,py34,py35,py36}-{sqlite,postgresql,mysql},pypy-{sqlite,postgresql}
envlist = {py36,py37}-{sqlite,postgresql},pypy3-{sqlite,postgresql}
[testenv]
commands = {envpython} setup.py test
deps =
{py27,py34,py35,py36}-postgresql: psycopg2 >= 2.5
pypy-postgresql: psycopg2cffi >= 2.5
mysql: MySQL-python
sqlite: sqlitebck
{py36,py37}-postgresql: psycopg2 >= 2.5
pypy3-postgresql: psycopg2cffi >= 2.5
{py36}-sqlite: sqlitebck
setenv =
sqlite: TRYTOND_DATABASE_URI={env:SQLITE_URI:sqlite://}
postgresql: TRYTOND_DATABASE_URI={env:POSTGRESQL_URI:postgresql://}
mysql: TRYTOND_DATABASE_URI={env:MYSQL_URI:mysql://}
sqlite: DB_NAME={env:SQLITE_NAME::memory:}
postgresql: DB_NAME={env:POSTGRESQL_NAME:test}
mysql: DB_NAME={env:MYSQL_NAME:test}
install_command = pip install --pre --process-dependency-links {opts} {packages}
install_command = pip install --pre --find-links https://trydevpi.tryton.org/ {opts} {packages}

View File

@ -1,5 +1,5 @@
[tryton]
version=4.8.0
version=5.0
depends:
carrier_load
ir

View File

@ -8,9 +8,8 @@ from trytond.transaction import Transaction
__all__ = ['UnitLoad', 'UnitLoadLabel']
class UnitLoad:
class UnitLoad(metaclass=PoolMeta):
__name__ = 'stock.unit_load'
__metaclass__ = PoolMeta
load_line = fields.Many2One('carrier.load.order.line', 'Load line',
select=True, readonly=True,
@ -119,8 +118,7 @@ class UnitLoad:
return res
class UnitLoadLabel:
__metaclass__ = PoolMeta
class UnitLoadLabel(metaclass=PoolMeta):
__name__ = 'stock.unit_load.label'
@classmethod