diff --git a/locale/es.po b/locale/es.po index 7853916..3752da8 100644 --- a/locale/es.po +++ b/locale/es.po @@ -2,21 +2,21 @@ msgid "" msgstr "Content-Type: text/plain; charset=utf-8\n" -msgctxt "error:stock.lot.replace:" +msgctxt "model:ir.message,text:msg_lot_period_cache" msgid "" -"Cannot replace lots with Period cache. Please go back period \"%s\" to Draft" +"Cannot replace lots with Period cache. Please go back period \"%(period)s\" to Draft" " first." -msgstr "No puede reemplazar lotes usados en Períodos. Ponga primero estado Borrador en período \"%s\"." +msgstr "No puede reemplazar lotes usados en Períodos. Ponga primero estado Borrador en período \"%(period)s\"." -msgctxt "error:stock.lot.replace:" +msgctxt "model:ir.message,text:msg_lot_different_name" msgid "Lots have different numbers: %(source_name)s vs %(destination_name)s." msgstr "Los lotes tienen números diferentes: %(source_name)s vs %(destination_name)s." -msgctxt "error:stock.lot.replace:" +msgctxt "model:ir.message,text:msg_lot_different_product" msgid "Lots have different product: %(source_code)s vs %(destination_code)s." msgstr "Los lotes tienen productos diferentes: %(source_code)s vs %(destination_code)s." -msgctxt "error:stock.lot:" +msgctxt "model:ir.message,text:msg_lot_uniq_by_product" msgid "Lot number must be unique by product." msgstr "Número de lote debe ser único por Producto." diff --git a/message.xml b/message.xml new file mode 100644 index 0000000..f12c3ee --- /dev/null +++ b/message.xml @@ -0,0 +1,19 @@ + + + + + + Lots have different numbers: %(source_name)s vs %(destination_name)s. + + + Lots have different product: %(source_code)s vs %(destination_code)s. + + + Cannot replace lots with Period cache. Please go back period "%(period)s" to Draft first. + + + Lot number must be unique by product. + + + \ No newline at end of file diff --git a/stock.py b/stock.py index ed3d9bf..bbf5ee0 100644 --- a/stock.py +++ b/stock.py @@ -6,8 +6,8 @@ from trytond.pool import PoolMeta, Pool from trytond.pyson import Eval from trytond.transaction import Transaction from trytond.wizard import Wizard, StateView, StateTransition, Button - -__all__ = ['Lot', 'LotReplace', 'LotReplaceAsk'] +from trytond.exceptions import UserError, UserWarning +from trytond.i18n import gettext class Lot(metaclass=PoolMeta): @@ -19,7 +19,7 @@ class Lot(metaclass=PoolMeta): t = cls.__table__() cls._sql_constraints += [ ('lot_uniq', Unique(t, t.number, t.product), - 'Lot number must be unique by product.'), + 'stock_lot_unique.msg_lot_uniq_by_product'), ] @@ -35,36 +35,26 @@ class LotReplace(Wizard): ]) replace = StateTransition() - @classmethod - def __setup__(cls): - super(LotReplace, cls).__setup__() - cls._error_messages.update({ - 'different_name': - 'Lots have different numbers: ' - '%(source_name)s vs %(destination_name)s.', - 'different_product': - 'Lots have different product: ' - '%(source_code)s vs %(destination_code)s.', - 'period_cache': 'Cannot replace lots with Period cache. ' - 'Please go back period "%s" to Draft first.' - }) - def check_similarity(self): + pool = Pool() + Warning = pool.get('res.user.warning') + sources = self.ask.sources destination = self.ask.destination for source in sources: if source.number != destination.number: key = 'stock.lot.replace number %s %s' % ( source.number, destination.number) - self.raise_user_warning(key, 'different_name', { - 'source_name': source.number, - 'destination_name': destination.number, - }) + if Warning.check(key): + raise UserWarning(key, gettext( + 'stock_lot_unique.msg_lot_different_name', + source_name=source.number, + destination_name=destination.number)) if source.product.id != destination.product.id: - self.raise_user_error('different_product', { - 'source_code': source.product.rec_name, - 'destination_code': destination.product.rec_name, - }) + raise UserError(gettext( + 'stock_lot_unique.msg_lot_different_product', + source_code=source.product.rec_name, + destination_code=destination.product.rec_name)) def check_period_cache(self): pool = Pool() @@ -73,7 +63,9 @@ class LotReplace(Wizard): lot_ids = [s.id for s in self.ask.sources] + [self.ask.destination.id] caches = Cache.search([('lot', 'in', lot_ids)], limit=1) if caches: - self.raise_user_error('period_cache', caches[0].period.rec_name) + raise UserError(gettext( + 'stock_lot_unique.msg_lot_period_cache', + period=caches[0].period.rec_name)) def transition_replace(self): pool = Pool() diff --git a/tests/scenario_lot_replace.rst b/tests/scenario_lot_replace.rst index 8f28946..93f266d 100644 --- a/tests/scenario_lot_replace.rst +++ b/tests/scenario_lot_replace.rst @@ -32,17 +32,15 @@ Create product:: >>> ProductUom = Model.get('product.uom') >>> ProductTemplate = Model.get('product.template') - >>> Product = Model.get('product.product') >>> unit, = ProductUom.find([('name', '=', 'Unit')]) - >>> product = Product() >>> template = ProductTemplate() >>> template.name = 'Product' >>> template.default_uom = unit >>> template.type = 'goods' >>> template.list_price = Decimal('20') - >>> template.cost_price = Decimal('8') >>> template.save() - >>> product.template = template + >>> product, = template.products + >>> product.cost_price = Decimal('8') >>> product.save() Get stock locations:: @@ -129,10 +127,10 @@ Replace the second by the first lot:: True >>> replace.form.destination == lot1 True - >>> replace.execute('replace') # doctest: +IGNORE_EXCEPTION_DETAIL + >>> replace.execute('replace') Traceback (most recent call last): ... - UserWarning: ('UserWarning', ('stock.lot.replace nmber 2 1', u'Lots have different numbers: L-1 vs L1.', '')) + trytond.exceptions.UserWarning: Lots have different numbers: L-1 vs L1. - >>> Model.get('res.user.warning')(user=config.user, ... name='stock.lot.replace number L-1 L1', always=True).save() diff --git a/tests/test_stock_lot_unique.py b/tests/test_stock_lot_unique.py index e33832f..5c13f80 100644 --- a/tests/test_stock_lot_unique.py +++ b/tests/test_stock_lot_unique.py @@ -30,7 +30,6 @@ class StockLotUniqueTestCase(ModuleTestCase): 'name': 'Test Move.internal_quantity', 'type': 'goods', 'list_price': Decimal(1), - 'cost_price': Decimal(0), 'cost_price_method': 'fixed', 'default_uom': kg.id, }]) diff --git a/tryton.cfg b/tryton.cfg index a4a6c43..d8b6a05 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -7,3 +7,4 @@ depends: xml: stock.xml + message.xml