diff --git a/delivery_note.fodt b/delivery_note.fodt index 5fa103b..a2f586e 100644 --- a/delivery_note.fodt +++ b/delivery_note.fodt @@ -587,7 +587,7 @@ <for each="shipment in records"> - <set_lang(shipment.delivery_address.party.lang and shipment.delivery_address.party.lang.code or 'en_US')><shipment.set_lang(shipment.delivery_address.party.lang and shipment.delivery_address.party.lang.code or 'en_US')><shipment.delivery_address.party.full_name> + <set_lang(shipment.delivery_address.party.lang and shipment.delivery_address.party.lang.code or 'en')><shipment.set_lang(shipment.delivery_address.party.lang and shipment.delivery_address.party.lang.code or 'en')><shipment.delivery_address.party.full_name> <for each="line in shipment.delivery_address.full_address.split('\n')"> <line> </for> diff --git a/limit_note.fodt b/limit_note.fodt index eed93d2..d8c991b 100644 --- a/limit_note.fodt +++ b/limit_note.fodt @@ -810,7 +810,7 @@ - <set_lang(company.party.lang and company.party.lang.code or 'en_US')> + <set_lang(company.party.lang and company.party.lang.code or 'en')> Product limit note <product.rec_name> diff --git a/locale/es.po b/locale/es.po index 94c859e..8537dc0 100644 --- a/locale/es.po +++ b/locale/es.po @@ -2,17 +2,13 @@ msgid "" msgstr "Content-Type: text/plain; charset=utf-8\n" -msgctxt "error:stock.location.product_limit:" +msgctxt "model:ir.message,text:msg_stock_location_product_limit_location_product_uniq" msgid "The pair location, product must be unique." msgstr "La pareja ubicación, producto debe ser única." -msgctxt "error:stock.shipment.out:" -msgid "The limit of the product %s is exceeded." -msgstr "El límite para el producto %s ha sido superado." - -msgctxt "error:stock.shipment.internal:" -msgid "The limit of the product %s is exceeded." -msgstr "El límite para el producto %s ha sido superado." +msgctxt "model:ir.message,text:msg_stock_shipment_out_product_limit_exceeded" +msgid "The limit of the product %(product)s is exceeded." +msgstr "El límite para el producto %(product)s ha sido superado." msgctxt "field:stock.location,diff_quantity:" msgid "Diff. quantity" diff --git a/message.xml b/message.xml new file mode 100644 index 0000000..df82089 --- /dev/null +++ b/message.xml @@ -0,0 +1,15 @@ + + + + + + + The pair location, product must be unique. + + + + The limit of the product %(product)s is exceeded. + + + diff --git a/product_limit.py b/product_limit.py index 048c797..7c442d9 100644 --- a/product_limit.py +++ b/product_limit.py @@ -1,5 +1,6 @@ # The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. +from datetime import date from dateutil.relativedelta import relativedelta from trytond.model import Unique from trytond.report import Report @@ -7,6 +8,8 @@ from trytond.transaction import Transaction from trytond.model import ModelSQL, ModelView, fields from trytond.pyson import Eval from trytond.pool import Pool, PoolMeta +from trytond.i18n import gettext +from trytond.exceptions import UserWarning from trytond.wizard import StateReport from trytond.wizard import Wizard, StateTransition, StateView, Button @@ -41,8 +44,8 @@ class ProductLimit(ModelSQL, ModelView): t = cls.__table__() cls._sql_constraints = [ ('location_product_uniq', Unique(t, t.location, t.product), - 'The pair location, product must be unique.') - ] + 'stock_location_product_limit.' + 'msg_stock_location_product_limit_location_product_uniq')] @fields.depends('product') def on_change_product(self): @@ -109,14 +112,6 @@ class ProductLimit(ModelSQL, ModelView): class ShipmentOut(metaclass=PoolMeta): __name__ = 'stock.shipment.out' - @classmethod - def __setup__(cls): - super(ShipmentOut, cls).__setup__() - cls._error_messages.update({ - 'product_limit_exceeded': - 'The limit of the product %s is exceeded.' - }) - def product_limits_by_location(self): ProductLimit = Pool().get('stock.location.product_limit') return ProductLimit.product_limits_by_location( @@ -128,8 +123,10 @@ class ShipmentOut(metaclass=PoolMeta): # similar to 'assign_try'. super().wait(shipments) - ProductLimit = Pool().get('stock.location.product_limit') - Uom = Pool().get('product.uom') + pool = Pool() + ProductLimit = pool.get('stock.location.product_limit') + Uom = pool.get('product.uom') + Warning = pool.get('res.user.warning') cache = set() @@ -157,10 +154,13 @@ class ShipmentOut(metaclass=PoolMeta): ) if forecast_qty > Uom.compute_qty( uom, limit, move.product.default_uom): - cls.raise_user_warning( - 'product_limit_exceeded_%s_%s' % ( - shipment.id, move.product.id), - 'product_limit_exceeded', move.product.name) + warning_name = 'product_limit_exceeded_%s_%s' % ( + shipment.id, move.product.id) + if Warning.check(warning_name): + raise UserWarning(warning_name, gettext( + 'stock_location_product_limit.' + 'msg_stock_shipment_out_product_limit_exceeded', + product=move.product.name)) cache.add((move.product, move.quantity)) @@ -176,14 +176,6 @@ class ShipmentOutReturn(metaclass=PoolMeta): class ShipmentInternal(metaclass=PoolMeta): __name__ = 'stock.shipment.internal' - @classmethod - def __setup__(cls): - super().__setup__() - cls._error_messages.update({ - 'product_limit_exceeded': - 'The limit of the product %s is exceeded.' - }) - def product_limits_by_location(self): ProductLimit = Pool().get('stock.location.product_limit') if not self.party or not self.party.warehouse: @@ -195,9 +187,10 @@ class ShipmentInternal(metaclass=PoolMeta): def wait(cls, shipments): super().wait(shipments) - ProductLimit = Pool().get('stock.location.product_limit') - Uom = Pool().get('product.uom') - + pool = Pool() + ProductLimit = pool.get('stock.location.product_limit') + Uom = pool.get('product.uom') + Warning = pool.get('res.user.warning') cache = set() for shipment in shipments: @@ -226,10 +219,13 @@ class ShipmentInternal(metaclass=PoolMeta): ) if forecast_qty > Uom.compute_qty( uom, limit, move.product.default_uom): - cls.raise_user_warning( - 'product_limit_exceeded_%s_%s' % ( - shipment.id, move.product.id), - 'product_limit_exceeded', move.product.name) + warning_name = 'product_limit_exceeded_%s_%s' % ( + shipment.id, move.product.id) + if Warning.check(warning_name): + raise UserWarning(warning_name, gettext( + 'stock_location_product_limit.' + 'msg_stock_shipment_out_product_limit_exceeded', + product=move.product.name)) cache.add((move.product, move.quantity)) @@ -265,8 +261,8 @@ class Location(metaclass=PoolMeta): @classmethod def get_diff_quantity(cls, locations, name): - return dict([(l.id, l.limit_quantity - - (l.quantity or 0)) for l in locations]) + return dict([(l.id, l.limit_quantity + - (l.quantity or 0)) for l in locations]) class ProductLimitNote(Report): @@ -280,9 +276,7 @@ class ProductLimitNote(Report): Company = pool.get('company.company') Location = pool.get('stock.location') ProductLimit = pool.get('stock.location.product_limit') - - report_context = super(ProductLimitNote, cls).get_context(records, - data) + report_context = super().get_context(records, header, data) report_context['company'] = Company(data['company']) report_context['product'] = Product(data['product']) @@ -331,13 +325,13 @@ class ProductLimitNote(Report): cumulate_moves[k[0]] += v cumulate += v report_context['cumulate'] = sorted([(k, v) for k, v in - cumulate_moves.items()], key=lambda x: x[0]) + cumulate_moves.items()], key=lambda x: x[0] or date.min) return report_context @classmethod def _get_sorted_moves(cls, moves): new_moves = [(k, v) for k, v in moves.items()] - new_moves = sorted(new_moves, key=lambda x: x[0][0]) + new_moves = sorted(new_moves, key=lambda x: x[0][0] or date.min) return new_moves @classmethod diff --git a/tests/scenario_stock_shipment_out.rst b/tests/scenario_stock_shipment_out.rst index 302f96f..b339d2c 100644 --- a/tests/scenario_stock_shipment_out.rst +++ b/tests/scenario_stock_shipment_out.rst @@ -111,10 +111,10 @@ Add two shipment lines of same product:: Set the shipment state to waiting:: - >>> shipment_out.click('wait') # doctest: +IGNORE_EXCEPTION_DETAIL + >>> shipment_out.click('wait') Traceback (most recent call last): ... - UserWarning: ... + trytond.exceptions.UserWarning: The limit of the product Product is exceeded. - >>> len(shipment_out.outgoing_moves) 2 >>> len(shipment_out.inventory_moves) @@ -143,7 +143,7 @@ Testing the reports:: >>> ext, _, _, name = delivery_note.execute([shipment_out], {}) >>> ext 'odt' - >>> name + >>> name.split('-')[0] 'Delivery Note' >>> conf = Model.get('stock.configuration')(1) >>> conf.show_limit = False @@ -179,10 +179,10 @@ Create Shipment Internal:: >>> move.company = company >>> move.unit_price = Decimal('1') >>> move.currency = company.currency - >>> shipment_internal.click('wait') # doctest: +IGNORE_EXCEPTION_DETAIL + >>> shipment_internal.click('wait') Traceback (most recent call last): ... - UserWarning: ... + trytond.exceptions.UserWarning: The limit of the product Product is exceeded. - >>> pl.quantity = 10 >>> pl.save() >>> shipment_internal.click('wait') \ No newline at end of file diff --git a/tryton.cfg b/tryton.cfg index 9634afe..db5f28b 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -10,3 +10,4 @@ extras_depend: xml: product_limit.xml + message.xml \ No newline at end of file