Update to 4.7

This commit is contained in:
C?dric Krier 2018-03-19 16:28:08 +01:00
parent 0164320b6c
commit b2916abf44
15 changed files with 186 additions and 74 deletions

57
.drone.yml Normal file
View File

@ -0,0 +1,57 @@
clone:
hg:
image: plugins/hg
pipeline:
tox:
image: ${IMAGE}
environment:
- CFLAGS=-O0
- DB_CACHE=/cache
- TOX_TESTENV_PASSENV=CFLAGS DB_CACHE
- POSTGRESQL_URI=postgresql://postgres@postgresql:5432/
commands:
- pip install tox
- tox -e "${TOXENV}-${DATABASE}"
notify:
image: drillster/drone-email
from: drone@localhost
host: smtp
port: 25
skip_verify: true
when:
status: [ changed, failure ]
services:
postgresql:
image: postgres
when:
matrix:
DATABASE: postgresql
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

View File

@ -4,6 +4,7 @@ from trytond.pool import Pool
from . import operation
from . import configuration
def register():
Pool.register(
configuration.Configuration,

View File

@ -11,7 +11,7 @@ class Configuration:
(None, ''),
('user_warning', 'User Warning'),
('user_error', 'User Error'),
], 'Check State Operation',
], 'Check State Operation',
help='Check state operation when done a production')
@staticmethod

View File

@ -1,5 +1,6 @@
from decimal import Decimal
from trytond.model import fields, ModelSQL, ModelView, Workflow
from trytond.model import (fields, ModelSQL, ModelView, Workflow,
sequence_ordered)
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval, If, Id
from trytond.transaction import Transaction
@ -12,13 +13,12 @@ STATES = {
DEPENDS = ['state']
class Operation(Workflow, ModelSQL, ModelView):
class Operation(sequence_ordered(), Workflow, ModelSQL, ModelView):
'Operation'
__name__ = 'production.operation'
production = fields.Many2One('production', 'Production', required=True,
states=STATES, depends=DEPENDS, ondelete='CASCADE')
sequence = fields.Integer('Sequence', states=STATES, depends=DEPENDS)
work_center_category = fields.Many2One('production.work_center.category',
'Work Center Category', states=STATES, depends=DEPENDS, required=True)
work_center = fields.Many2One('production.work_center', 'Work Center',
@ -47,7 +47,6 @@ class Operation(Workflow, ModelSQL, ModelView):
@classmethod
def __setup__(cls):
super(Operation, cls).__setup__()
cls._order.insert(0, ('sequence', 'ASC'))
cls._invalid_production_states_on_create = ['done']
cls._error_messages.update({
'invalid_production_state': ('You can not create an operation'
@ -120,11 +119,6 @@ class Operation(Workflow, ModelSQL, ModelView):
default.setdefault('lines', [])
return super(Operation, cls).copy(operations, default)
@staticmethod
def order_sequence(tables):
table, _ = tables[None]
return [table.sequence == None, table.sequence]
def get_cost(self, name):
cost = Decimal('0.0')
for line in self.lines:
@ -299,10 +293,11 @@ class Production:
if pending_operations:
operation, = pending_operations
if config.check_state_operation == 'user_warning':
cls.raise_user_warning('pending_operation_%d' % operation.id,
'pending_operations', warning_args={
'production': operation.production.rec_name,
'operation': operation.rec_name,
cls.raise_user_warning(
'pending_operation_%d' % operation.id,
'pending_operations', warning_args={
'production': operation.production.rec_name,
'operation': operation.rec_name,
})
else:
cls.raise_user_error('pending_operations', error_args={

View File

@ -94,6 +94,22 @@
<field name="rule_group" ref="rule_group_production_operation"/>
</record>
<record model="ir.model.button" id="production_operation_wait_button">
<field name="name">wait</field>
<field name="string">Wait</field>
<field name="model" search="[('model', '=', 'production.operation')]"/>
</record>
<record model="ir.model.button" id="production_operation_run_button">
<field name="name">run</field>
<field name="string">Run</field>
<field name="model" search="[('model', '=', 'production.operation')]"/>
</record>
<record model="ir.model.button" id="production_operation_done_button">
<field name="name">done</field>
<field name="string">Done</field>
<field name="model" search="[('model', '=', 'production.operation')]"/>
</record>
<!-- production.operation.tracking -->
<record model="ir.ui.view" id="production_operation_tracking_view_form">
<field name="model">production.operation.tracking</field>

View File

@ -4,43 +4,74 @@
from setuptools import setup
import re
import os
import ConfigParser
import io
try:
from configparser import ConfigParser
except ImportError:
from ConfigParser import ConfigParser
MODULE = 'production_operation'
PREFIX = 'nantic'
MODULE2PREFIX = {
'production_route': 'nantic',
}
}
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
return io.open(
os.path.join(os.path.dirname(__file__), fname),
'r', encoding='utf-8').read()
config = ConfigParser.ConfigParser()
def get_require_version(name):
if minor_version % 2:
require = '%s >= %s.%s.dev0, < %s.%s'
else:
require = '%s >= %s.%s, < %s.%s'
require %= (name, major_version, minor_version,
major_version, minor_version + 1)
return require
config = ConfigParser()
config.readfp(open('tryton.cfg'))
info = dict(config.items('tryton'))
for key in ('depends', 'extras_depend', 'xml'):
if key in info:
info[key] = info[key].strip().splitlines()
major_version, minor_version, _ = info.get('version', '0.0.1').split('.', 2)
version = info.get('version', '0.0.1')
major_version, minor_version, _ = version.split('.', 2)
major_version = int(major_version)
minor_version = int(minor_version)
requires = []
for dep in info.get('depends', []):
if not re.match(r'(ir|res|webdav)(\W|$)', dep):
if not re.match(r'(ir|res)(\W|$)', dep):
prefix = MODULE2PREFIX.get(dep, 'trytond')
requires.append('%s_%s >= %s.%s, < %s.%s' %
(prefix, dep, major_version, minor_version,
major_version, minor_version + 1))
requires.append('trytond >= %s.%s, < %s.%s' %
(major_version, minor_version, major_version, minor_version + 1))
requires.append(get_require_version('%s_%s' % (prefix, dep)))
requires.append(get_require_version('trytond'))
tests_require = [get_require_version('proteus')]
series = '%s.%s' % (major_version, minor_version)
if minor_version % 2:
branch = 'default'
else:
branch = series
dependency_links = [
('hg+https://bitbucket.org/nantic/'
'trytond-production_route@%(branch)s'
'#egg=nantic-production_route-%(series)s' % {
'branch': branch,
'series': series,
}),
]
if minor_version % 2:
# Add development index for testing with proteus
dependency_links.append('https://trydevpi.tryton.org/')
tests_require = ['proteus >= %s.%s, < %s.%s' %
(major_version, minor_version, major_version, minor_version + 1)]
setup(name='%s_%s' % (PREFIX, MODULE),
version=info.get('version', '0.0.1'),
version=version,
description='',
long_description=read('README'),
author='NaN·tic',
@ -73,12 +104,17 @@ setup(name='%s_%s' % (PREFIX, MODULE),
'Natural Language :: Russian',
'Natural Language :: Spanish',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Office/Business',
],
license='GPL-3',
install_requires=requires,
dependency_links=dependency_links,
zip_safe=False,
entry_points="""
[trytond.modules]
@ -87,4 +123,8 @@ setup(name='%s_%s' % (PREFIX, MODULE),
test_suite='tests',
test_loader='trytond.test_loader:Loader',
tests_require=tests_require,
use_2to3=True,
convert_2to3_doctests=[
'tests/scenario_production_operation.rst',
]
)

View File

@ -1,6 +1,8 @@
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from .test_production_operation import suite
try:
from trytond.modules.production_operation.tests.test_production_operation import suite
except ImportError:
from .test_production_operation import suite
__all__ = ['suite']

View File

@ -1,10 +1,6 @@
===================
Production Scenario
===================
=============
General Setup
=============
=============================
Production Operation Scenario
=============================
Imports::
@ -12,32 +8,20 @@ Imports::
>>> from dateutil.relativedelta import relativedelta
>>> from decimal import Decimal
>>> from proteus import config, Model, Wizard
>>> from trytond.tests.tools import activate_modules
>>> from trytond.modules.company.tests.tools import create_company, \
... get_company
>>> today = datetime.date.today()
Create database::
>>> config = config.set_trytond()
>>> config.pool.test = True
Install production_operation Module::
>>> Module = Model.get('ir.module')
>>> modules = Module.find([('name', '=', 'production_operation')])
>>> Module.install([x.id for x in modules], config.context)
>>> Wizard('ir.module.install_upgrade').execute('upgrade')
>>> config = activate_modules('production_operation')
Create company::
>>> _ = create_company()
>>> company = get_company()
Reload the context::
>>> User = Model.get('res.user')
>>> config._context = User.get_preferences(True, config.context)
Configuration production location::
>>> Location = Model.get('stock.location')
@ -46,7 +30,7 @@ Configuration production location::
>>> warehouse.production_location = production_location
>>> warehouse.save()
Create a route with two operations on diferent work center::
Create a route with two operations on different work center::
>>> ProductUom = Model.get('product.uom')
>>> Route = Model.get('production.route')
@ -113,10 +97,11 @@ Create product::
>>> template.name = 'product'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.producible = True
>>> template.list_price = Decimal(30)
>>> template.cost_price = Decimal(20)
>>> template.save()
>>> product.template = template
>>> product.cost_price = Decimal(20)
>>> product.save()
Create Components::
@ -127,9 +112,9 @@ Create Components::
>>> template1.default_uom = unit
>>> template1.type = 'goods'
>>> template1.list_price = Decimal(5)
>>> template1.cost_price = Decimal(1)
>>> template1.save()
>>> component1.template = template1
>>> component1.cost_price = Decimal(1)
>>> component1.save()
>>> meter, = ProductUom.find([('name', '=', 'Meter')])
@ -140,9 +125,9 @@ Create Components::
>>> template2.default_uom = meter
>>> template2.type = 'goods'
>>> template2.list_price = Decimal(7)
>>> template2.cost_price = Decimal(5)
>>> template2.save()
>>> component2.template = template2
>>> component2.cost_price = Decimal(5)
>>> component2.save()
Create Bill of Material::
@ -230,10 +215,10 @@ Make a production::
True
>>> all(o.state == 'waiting' for o in production.operations)
True
>>> Production.done([production.id], config.context)
>>> Production.done([production.id], config.context) # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
UserError: ('UserError', (u'Production "1" can not be done because their operation "Assembly" is not done.', ''))
UserError: ...
>>> operation1, operation2 = production.operations
>>> tracking = OperationTracking()
>>> operation1.lines.append(tracking)
@ -255,5 +240,5 @@ Make a production::
>>> production.reload()
>>> production.state
u'done'
>>> production.cost == Decimal('100')
True
>>> production.cost
Decimal('100.0000')

View File

@ -5,7 +5,7 @@ import unittest
import doctest
import trytond.tests.test_tryton
from trytond.tests.test_tryton import ModuleTestCase
from trytond.tests.test_tryton import doctest_setup, doctest_teardown
from trytond.tests.test_tryton import doctest_teardown
from trytond.tests.test_tryton import doctest_checker
@ -19,7 +19,7 @@ def suite():
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
ProductionOperationTestCase))
suite.addTests(doctest.DocFileSuite('scenario_production_operation.rst',
setUp=doctest_setup, tearDown=doctest_teardown, encoding='utf-8',
tearDown=doctest_teardown, encoding='utf-8',
checker=doctest_checker,
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
return suite

18
tox.ini Normal file
View File

@ -0,0 +1,18 @@
[tox]
envlist = {py27,py34,py35,py36}-{sqlite,postgresql,mysql},pypy-{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
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 --find-links https://trydevpi.tryton.org/ --process-dependency-links {opts} {packages}

View File

@ -1,5 +1,5 @@
[tryton]
version=4.1.0
version=4.7.0
depends:
production_route
extras_depend:

View File

@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<form string="Operation">
<form>
<label name="operation_type"/>
<field name="operation_type"/>
<label name="production"/>
@ -21,11 +21,9 @@
<label name="state"/>
<field name="state"/>
<group col="6" colspan="2" id="buttons">
<button name="wait" string="Wait"/>
<button name="run" string="Run"
icon="tryton-go-next"/>
<button name="done" string="Done"
icon="tryton-go-next"/>
<button name="wait"/>
<button name="run" icon="tryton-go-next"/>
<button name="done" icon="tryton-go-next"/>
</group>
</group>
</form>

View File

@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<tree string="Operation" sequence="sequence">
<tree sequence="sequence">
<field name="production"/>
<field name="operation_type"/>
<field name="work_center"/>

View File

@ -1,9 +1,9 @@
<?xml version="1.0"?><!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<form string="Operation Tracking" col="4">
<form col="4">
<label name="quantity"/>
<field name="quantity"/>
<label name="uom"/>
<field name="uom"/>
</form>
</form>

View File

@ -2,8 +2,8 @@
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<tree string="Operation Tracking">
<tree>
<field name="operation"/>
<field name="quantity"/>
<field name="uom"/>
</tree>
</tree>