Migration to 5.0

This commit is contained in:
Javier Uribe 2019-02-26 11:03:16 +01:00
parent e4b107402c
commit ee670f62f9
13 changed files with 75 additions and 88 deletions

View File

@ -32,15 +32,15 @@ services:
matrix:
include:
- IMAGE: python:2.7
TOXENV: py27
DATABASE: sqlite
- IMAGE: python:2.7
TOXENV: py27
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

View File

@ -11,9 +11,8 @@ __all__ = ['Configuration', 'ConfigurationSequence',
'ConfigurationULProductionType']
class Configuration:
class Configuration(metaclass=PoolMeta):
__name__ = 'stock.configuration'
__metaclass__ = PoolMeta
unit_load_sequence = fields.MultiValue(
fields.Many2One('ir.sequence', 'Load unit Sequence', required=True,
@ -43,9 +42,8 @@ class Configuration:
'ul_production_type').default_ul_production_type()
class ConfigurationSequence:
class ConfigurationSequence(metaclass=PoolMeta):
__name__ = 'stock.configuration.sequence'
__metaclass__ = PoolMeta
unit_load_sequence = fields.Many2One('ir.sequence',
'Load unit Sequence', required=True,

3
res.py
View File

@ -6,9 +6,8 @@ from trytond.model import fields
__all__ = ['User']
class User:
class User(metaclass=PoolMeta):
__name__ = 'res.user'
__metaclass__ = PoolMeta
ul_drop_location = fields.Many2One('stock.location', 'UL drop location',
domain=[('type', 'in', ('production', 'drop'))])

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 = {
'stock_move_time': 'datalife'
@ -22,6 +19,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'
@ -32,6 +30,7 @@ def get_require_version(name):
return require
config = ConfigParser()
config.readfp(open('tryton.cfg'))
info = dict(config.items('tryton'))
@ -63,12 +62,15 @@ requires = []
for dep in info.get('depends', []):
if not re.match(r'(ir|res)(\W|$)', dep):
prefix = MODULE2PREFIX.get(dep, 'trytond')
req = get_require_version('%s_%s' % (prefix, dep))
if dep in dependency_links:
req = '%s_%s @ %s' % (prefix, dep, dependency_links[dep])
requires.append(req)
requires.append(get_require_version('trytond'))
tests_require = [get_require_version('proteus')]
if minor_version % 2:
@ -116,15 +118,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,
zip_safe=False,
entry_points="""
@ -134,11 +137,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_stock_unit_load.rst',
'tests/scenario_batch_drop.rst',
'tests/scenario_drop.rst',
'tests/scenario_shipment_internal.rst',
],
)

View File

@ -8,9 +8,8 @@ from trytond.pyson import Eval
__all__ = ['ShipmentOut', 'ShipmentInternal']
class ShipmentOut:
class ShipmentOut(metaclass=PoolMeta):
__name__ = 'stock.shipment.out'
__metaclass__ = PoolMeta
unit_loads = fields.Function(
fields.One2Many('stock.unit_load', None, 'Unit loads',
@ -72,9 +71,8 @@ class ShipmentOut:
return res
class ShipmentInternal:
class ShipmentInternal(metaclass=PoolMeta):
__name__ = 'stock.shipment.internal'
__metaclass__ = PoolMeta
ul_quantity = fields.Function(
fields.Float('ULs', digits=(16, 0)), 'get_ul_quantity')

View File

@ -11,9 +11,8 @@ __all__ = ['Move' 'UnitLoadsByLocationsStart',
'UnitLoadsByLocations']
class Move:
class Move(metaclass=PoolMeta):
__name__ = 'stock.move'
__metaclass__ = PoolMeta
unit_load = fields.Many2One('stock.unit_load', 'Unit load',
ondelete='RESTRICT', select=True,

View File

@ -164,7 +164,7 @@ Check moves::
>>> unit_load.reload()
>>> unit_load.state
u'done'
'done'
>>> bool(unit_load.dropped)
True
>>> bool(unit_load.available)

View File

@ -129,7 +129,7 @@ State error::
UserError: ...
>>> unit_load.click('do')
>>> unit_load.state
u'done'
'done'
Location error::
@ -163,7 +163,7 @@ Check moves::
>>> unit_load.reload()
>>> unit_load.state
u'draft'
'draft'
>>> len(unit_load.moves)
6
>>> len(unit_load.drop_moves)
@ -180,7 +180,7 @@ Cancel dropping::
>>> unit_load.click('cancel')
>>> unit_load.reload()
>>> unit_load.state
u'done'
'done'
Use default return location::
@ -192,7 +192,7 @@ Use default return location::
>>> drop_ul.execute('try_')
>>> unit_load.reload()
>>> unit_load.state
u'draft'
'draft'
>>> len(unit_load.moves)
6
>>> len(unit_load.drop_moves)
@ -280,14 +280,14 @@ Check default data and behavior on global drop wizard::
>>> unit_load.reload()
>>> move = unit_load.drop_moves[0]
>>> move.state
u'draft'
'draft'
>>> move.end_date == move.start_date
True
>>> time.sleep(1)
>>> drop_ul.execute('do_')
>>> move.reload()
>>> move.state
u'done'
'done'
>>> move.end_date > move.start_date
True

View File

@ -109,7 +109,7 @@ Add moves::
True
>>> unit_load.save()
>>> unit_load.state
u'draft'
'draft'
>>> unit_load.production_state
'running'
>>> len(unit_load.moves)
@ -117,7 +117,7 @@ Add moves::
>>> len(unit_load.production_moves)
1
>>> unit_load.production_moves[0].state
u'draft'
'draft'
>>> unit_load.internal_quantity
35.0
>>> unit_load.quantity_per_case
@ -126,20 +126,20 @@ Add moves::
Check computed fields::
>>> unit_load.location.code
u'STO'
'STO'
>>> len(unit_load.last_moves) == 1
True
>>> unit_load.click('assign')
>>> unit_load.state
u'assigned'
'assigned'
>>> unit_load.moves[0].state
u'assigned'
'assigned'
>>> unit_load.production_state
'running'
>>> len(unit_load.ul_moves)
1
>>> unit_load.uom.rec_name
u'Unit'
'Unit'
>>> unit_load.save()
>>> unit_load.click('do')
@ -175,7 +175,7 @@ Check unit load state::
>>> len(unit_load.ul_moves)
2
>>> unit_load.state
u'done'
'done'
>>> unit_load.location.id == wh2.storage_location.id
True

View File

@ -105,7 +105,7 @@ Add moves::
True
>>> unit_load.save()
>>> unit_load.state
u'draft'
'draft'
>>> unit_load.production_state
'running'
>>> len(unit_load.moves)
@ -113,7 +113,7 @@ Add moves::
>>> len(unit_load.production_moves)
1
>>> unit_load.production_moves[0].state
u'draft'
'draft'
>>> unit_load.internal_quantity
35.0
>>> unit_load.quantity_per_case
@ -122,20 +122,20 @@ Add moves::
Check computed fields::
>>> unit_load.location.code
u'STO'
'STO'
>>> len(unit_load.last_moves) == 1
True
>>> unit_load.click('assign')
>>> unit_load.state
u'assigned'
'assigned'
>>> unit_load.moves[0].state
u'assigned'
'assigned'
>>> unit_load.production_state
'running'
>>> len(unit_load.ul_moves)
1
>>> unit_load.uom.rec_name
u'Unit'
'Unit'
>>> unit_load.save()
Move wizard::
@ -152,7 +152,7 @@ State error::
UserError: ...
>>> unit_load.click('do')
>>> unit_load.state
u'done'
'done'
>>> unit_load.production_state
'done'
>>> unit_load.quantity
@ -178,7 +178,7 @@ Date error::
>>> move_ul.execute('move_')
>>> unit_load.reload()
>>> unit_load.state
u'draft'
'draft'
>>> len(unit_load.moves)
2
>>> unit_load.last_date == datetime.datetime.combine(tomorrow, time_)
@ -193,7 +193,7 @@ Cancel last move::
>>> unit_load.location.id == storage_loc.id
True
>>> unit_load.state
u'done'
'done'
Create customer::
@ -236,7 +236,7 @@ Check unit load state::
>>> len(unit_load.ul_moves)
3
>>> unit_load.state
u'done'
'done'
>>> unit_load.location.id == customer.customer_location.id
True
@ -245,6 +245,6 @@ Check report::
>>> label = Report('stock.unit_load.label')
>>> ext, _, _, name = label.execute([unit_load], {})
>>> ext
u'odt'
'odt'
>>> name
u'Label'
'Label'

13
tox.ini
View File

@ -1,18 +1,15 @@
[tox]
envlist = {py27,py36}-{sqlite,postgresql,mysql},pypy-{sqlite,postgresql}
envlist = {py36,py37}-{sqlite,postgresql},pypy3-{sqlite,postgresql}
[testenv]
commands = {envpython} setup.py test
deps =
{py27,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 {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:
ir
res

View File

@ -229,13 +229,13 @@ class UnitLoad(ModelSQL, ModelView):
})
cls._buttons.update({
'move_try': {
'icon': 'tryton-go-next',
'icon': 'tryton-forward',
'invisible': (Eval('state') != 'done') | (~Eval('available')) |
Eval('dropped'),
'depends': ['state', 'available', 'dropped']
},
'assign': {
'icon': 'tryton-go-next',
'icon': 'tryton-forward',
'invisible': (Eval('state') != 'draft'),
'depends': ['state']
},
@ -250,12 +250,12 @@ class UnitLoad(ModelSQL, ModelView):
'depends': ['state']
},
'draft': {
'icon': 'tryton-clear',
'icon': 'tryton-undo',
'invisible': ~Eval('state').in_(['assigned']),
'depends': ['state']
},
'drop_wizard': {
'icon': 'tryton-go-next',
'icon': 'tryton-forward',
'invisible': (Eval('state') != 'done') | (~Eval('available')) |
Eval('dropped'),
'depends': ['state', 'available', 'dropped']
@ -413,20 +413,20 @@ class UnitLoad(ModelSQL, ModelView):
location_ids, wh_to_add, storage_to_remove = \
cls._skip_warehouse_in_compute_quantities(location_ids)
uls = dict.fromkeys(map(int, records), 0)
uls = dict.fromkeys(list(map(int, records)), 0)
ul_products = {r.id: r.product.id for r in records}
quantities = cls._compute_quantities(records, location_ids)
if wh_to_add:
for wh, storage in wh_to_add.iteritems():
for wh, storage in wh_to_add.items():
for key in quantities:
if key[0] == storage:
quantities[(wh,) + key[1:]] = quantities[key]
if storage in storage_to_remove:
del quantities[key]
for key, quantity in quantities.iteritems():
for key, quantity in quantities.items():
if (key[-1] is not None and
key[-1] in uls and
key[1] == ul_products[key[-1]]):
@ -520,7 +520,7 @@ class UnitLoad(ModelSQL, ModelView):
grouping_filter=None)
record_ids = []
for key, quantity in quantities.iteritems():
for key, quantity in quantities.items():
# pbl could return None in some keys
if key[-1] is not None:
record_ids.append(key[-1])
@ -556,7 +556,7 @@ class UnitLoad(ModelSQL, ModelView):
pool = Pool()
Move = pool.get('stock.move')
value = dict.fromkeys(map(int, records), None)
value = dict.fromkeys(list(map(int, records)), None)
for record in records:
moves = record.get_last_moves(product_id=product_id,
@ -584,7 +584,7 @@ class UnitLoad(ModelSQL, ModelView):
quantities = cls._compute_quantities(records, location_ids,
product_id=product_id)
for key, quantity in quantities.iteritems():
for key, quantity in quantities.items():
if quantity <= 0:
continue
if key[1] == ul_products[key[-1]]:
@ -713,7 +713,7 @@ class UnitLoad(ModelSQL, ModelView):
to_create.extend(new_moves)
if to_create:
Move.save(to_create)
return Move.browse(map(int, to_create))
return Move.browse(list(map(int, to_create)))
def _move(self, to_location, at_date, from_location=None):
if not from_location:
@ -997,7 +997,7 @@ class UnitLoad(ModelSQL, ModelView):
elif qty < record.internal_quantity and record.dropped:
to_undrop.append(record)
for key, values in changes.iteritems():
for key, values in changes.items():
if values:
cls.write(values, {'dropped': key})
@ -1137,7 +1137,7 @@ class UnitLoad(ModelSQL, ModelView):
to_location = Location(to_location)
if not records:
return []
if isinstance(records, basestring):
if isinstance(records, str):
records = PYSONDecoder.decode(records)
if not isinstance(records[0], Model):
records = cls.search(records)
@ -1158,7 +1158,7 @@ class UnitLoad(ModelSQL, ModelView):
if values.get('done_moves', False):
Move.do(to_create)
cls.write(records, {'dropped': True})
return Move.browse(map(int, to_create))
return Move.browse(list(map(int, to_create)))
def _drop(self, to_location, start_date, **kwargs):
from_location = None
@ -1206,7 +1206,7 @@ class UnitLoad(ModelSQL, ModelView):
return []
if len(self.moves) == len(self.production_moves):
return []
production_ids = map(int, self.production_moves)
production_ids = list(map(int, self.production_moves))
return [m.id for m in self.moves
if m.to_location.type in ('production', 'drop') and
m.from_location.type not in ('production', 'drop') and
@ -1220,7 +1220,7 @@ class UnitLoad(ModelSQL, ModelView):
if not self.last_moves or not self.drop_moves:
return []
at_date = max(m.end_date for m in self.last_moves)
production_ids = map(int, self.production_moves)
production_ids = list(map(int, self.production_moves))
return [m.id for m in self.moves if m.from_location.type in (
'production', 'drop') and m.to_location.type == 'storage' and
m.id not in production_ids and m.start_date == at_date] or []
@ -1352,7 +1352,7 @@ class UnitLoadMove(ModelSQL, ModelView):
# Convert str start_date to datetime in sqlite
for values in res:
if 'start_date' in values:
if isinstance(values['start_date'], basestring):
if isinstance(values['start_date'], str):
values['start_date'] = datetime.datetime(
*time.strptime(values['start_date'],
'%Y-%m-%d %H:%M:%S')[:6])
@ -1459,12 +1459,12 @@ class DropUnitLoad(Wizard):
data = StateView('stock.unit_load.do_drop.data',
'stock_unit_load.unit_load_drop_data_view_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Set return locations', 'failed', 'tryton-go-next'),
Button('Set return locations', 'failed', 'tryton-forward'),
Button('OK', 'try_', 'tryton-ok', default=True)])
try_ = StateTransition()
end_date = StateView('stock.unit_load.do_drop.end_date',
'stock_unit_load.unit_load_drop_end_date_view_form', [
Button('Go back', 'go_back', 'tryton-go-previous'),
Button('Go back', 'go_back', 'tryton-back'),
Button('OK', 'do_', 'tryton-ok', default=True)])
do_ = StateTransition()
go_back = StateTransition()
@ -1716,7 +1716,7 @@ class BatchDropUnitLoad(Wizard):
return {}
def default_confirm(self, fields):
return {'unit_loads': map(int, self.data.unit_loads)}
return {'unit_loads': list(map(int, self.data.unit_loads))}
def transition_do_(self):
pool = Pool()
@ -1725,7 +1725,7 @@ class BatchDropUnitLoad(Wizard):
if not self.data.unit_loads:
return 'end'
uls = Unitload.browse(map(int, self.confirm.unit_loads))
uls = Unitload.browse(list(map(int, self.confirm.unit_loads)))
Unitload.drop(uls, self.data.location,
self.data.start_date, extra_params={
'delay': self.data.delay_,