diff --git a/locale/es.po b/locale/es.po index 524e198..7d2f8a8 100644 --- a/locale/es.po +++ b/locale/es.po @@ -2,7 +2,7 @@ msgid "" msgstr "Content-Type: text/plain; charset=utf-8\n" -msgctxt "error:stock.product.category.location:" +msgctxt "model:ir.message,text:msg_category_location_unique_key" msgid "Category and location must be unique." msgstr "Categoria y ubicación deben ser únicos." diff --git a/location.py b/location.py index f2e4a96..b3e9249 100644 --- a/location.py +++ b/location.py @@ -4,6 +4,8 @@ from trytond.model import ModelView, ModelSQL, fields from trytond.pyson import Eval, Bool, Not, Equal from trytond.pool import PoolMeta, Pool from trytond.transaction import Transaction +from trytond.exceptions import UserError +from trytond.i18n import gettext from sql.aggregate import Max @@ -34,16 +36,11 @@ class ProductCategoryLocation(ModelSQL, ModelView): ], depends=['warehouse']) sequence = fields.Integer('Sequence') - @classmethod - def __setup__(cls): - super(ProductCategoryLocation, cls).__setup__() - cls._error_messages.update({ - 'unique_key': 'Category and location must be unique.'}) - @staticmethod def _compute_sequence_where(table, record): - return ((table.category == record['category']) & - (table.warehouse == record['warehouse'])) + return ( + (table.category == record['category']) + & (table.warehouse == record['warehouse'])) @staticmethod def _compute_sequence(table, record): @@ -63,7 +60,7 @@ class ProductCategoryLocation(ModelSQL, ModelView): if not values.get('sequence', None): values['sequence'] = cls._compute_sequence( cls.__table__(), values) - return super(ProductCategoryLocation, cls).create(vlist) + return super().create(vlist) @classmethod def default_warehouse(cls): @@ -88,16 +85,20 @@ class ProductCategoryLocation(ModelSQL, ModelView): for record in records: _uq = record._get_unique_key() if values.get(_uq): - cls.raise_user_error('unique_key') + raise UserError(gettext( + 'stock_product_category_location.' + 'msg_category_location_unique_key')) values.setdefault(_uq, 1) others = cls.search([('id', 'not in', list(map(int, records)))]) for other in others: _uq = other._get_unique_key() if values.get(_uq): - cls.raise_user_error('unique_key') + raise UserError(gettext( + 'stock_product_category_location.' + 'msg_category_location_unique_key')) - super(ProductCategoryLocation, cls).validate(records) + super().validate(records) class Location(metaclass=PoolMeta): @@ -118,6 +119,6 @@ class Location(metaclass=PoolMeta): @classmethod def view_attributes(cls): - return super(Location, cls).view_attributes() + [ + return super().view_attributes() + [ ('//page[@id="categories"]', 'states', { 'invisible': ~Eval('type').in_(['warehouse', 'storage'])})] diff --git a/message.xml b/message.xml new file mode 100644 index 0000000..57ead0a --- /dev/null +++ b/message.xml @@ -0,0 +1,11 @@ + + + + + + + Category and location must be unique. + + + diff --git a/stock.py b/stock.py index 7b505ba..143dac2 100644 --- a/stock.py +++ b/stock.py @@ -9,7 +9,7 @@ class ShipmentOut(metaclass=PoolMeta): __name__ = 'stock.shipment.out' def _get_inventory_move(self, move): - res = super(ShipmentOut, self)._get_inventory_move(move) + res = super()._get_inventory_move(move) if not res or hasattr(res, 'unit_load'): return res for c in res.product.categories: @@ -27,14 +27,13 @@ class ShipmentOut(metaclass=PoolMeta): class ShipmentOutReturn(metaclass=PoolMeta): __name__ = 'stock.shipment.out.return' - @classmethod - def _get_inventory_moves(cls, incoming_move): - res = super(ShipmentOutReturn, cls)._get_inventory_moves(incoming_move) + def _get_inventory_move(self, incoming_move): + res = super()._get_inventory_move(incoming_move) if not res: return res for c in res.product.categories: _to_location = c.get_default_location( - **cls._get_default_location_params(incoming_move)) + **self._get_default_location_params(incoming_move)) if _to_location: res.to_location = _to_location break @@ -48,14 +47,13 @@ class ShipmentOutReturn(metaclass=PoolMeta): class ShipmentIn(metaclass=PoolMeta): __name__ = 'stock.shipment.in' - @classmethod - def _get_inventory_moves(cls, incoming_move): - res = super(ShipmentIn, cls)._get_inventory_moves(incoming_move) + def _get_inventory_move(self, incoming_move): + res = super()._get_inventory_move(incoming_move) if not res: return res for c in res.product.categories: _to_location = c.get_default_location( - **cls._get_default_location_params(incoming_move)) + **self._get_default_location_params(incoming_move)) if _to_location: res.to_location = _to_location break diff --git a/tryton.cfg b/tryton.cfg index 9620bee..06b63a1 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -11,3 +11,4 @@ extras_depend: xml: location.xml product.xml + message.xml \ No newline at end of file