From e950148addd66055b6316721015a054b1586f7e7 Mon Sep 17 00:00:00 2001 From: Carlos G?lvez Date: Fri, 13 Sep 2019 10:44:21 +0200 Subject: [PATCH] Migrate to 5.3 --- message.xml | 10 ++++++++++ product_oneclick.py | 30 +++++++++++++----------------- tox.ini | 13 +++++-------- tryton.cfg | 3 ++- 4 files changed, 30 insertions(+), 26 deletions(-) create mode 100644 message.xml diff --git a/message.xml b/message.xml new file mode 100644 index 0000000..0c88849 --- /dev/null +++ b/message.xml @@ -0,0 +1,10 @@ + + + + + + Product %(name)s (%(code)s) already exist. + + + diff --git a/product_oneclick.py b/product_oneclick.py index 29ef9e5..232bcc5 100644 --- a/product_oneclick.py +++ b/product_oneclick.py @@ -7,6 +7,8 @@ from trytond.pyson import Eval, Not, Bool, PYSONEncoder from trytond.wizard import Wizard, StateView, StateAction, StateTransition, \ Button from trytond.config import config as config_ +from trytond.i18n import gettext +from trytond.exceptions import UserError __all__ = ['ProductOneClickView', 'ProductOneClick'] @@ -120,14 +122,6 @@ class ProductOneClick(Wizard): create_ = StateTransition() open_ = StateAction('product.act_product_form') - @classmethod - def __setup__(cls): - super(ProductOneClick, cls).__setup__() - cls._error_messages.update({ - 'warning': 'Warning', - 'product_exist': 'Product %s (%s) already exist.', - }) - @classmethod def get_template_values(self, vals): values = { @@ -168,15 +162,17 @@ class ProductOneClick(Wizard): name = self.view.name code = self.view.code - products = None - if name: - products = Template.search([('name', '=', name)]) - if code: - products = Product.search([('code', '=', code)]) - if products: - self.raise_user_error(error="warning", - error_description="product_exist", - error_description_args=(name, code)) + product = None + if name and not code: + product, = (Template.search([('name', '=', name)], limit=1) + or [None]) + else: + product, = Product.search([('code', '=', code)], limit=1) or [None] + if product: + raise UserError(gettext('product_exist', + name=product.rec_name, + code=product.code, + )) vals = self.view tpl_values = self.get_template_values(vals) diff --git a/tox.ini b/tox.ini index ad44320..a7b706b 100644 --- a/tox.ini +++ b/tox.ini @@ -1,18 +1,15 @@ [tox] -envlist = {py27,py34,py35,py36}-{sqlite,postgresql,mysql},pypy-{sqlite,postgresql} +envlist = {py35,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 + {py35,py36,py37}-postgresql: psycopg2 >= 2.5 + pypy3-postgresql: psycopg2cffi >= 2.5 + {py35,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 --find-links https://trydevpi.tryton.org/ --process-dependency-links {opts} {packages} +install_command = pip install --pre --find-links https://trydevpi.tryton.org/ {opts} {packages} diff --git a/tryton.cfg b/tryton.cfg index 18c63e7..26cb56f 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -1,5 +1,5 @@ [tryton] -version=5.1.0 +version=5.3.0 depends: ir res @@ -8,3 +8,4 @@ depends: account_product xml: product_oneclick.xml + message.xml