From b9368d886d49dca6f33e5532326367849eca6fd8 Mon Sep 17 00:00:00 2001 From: Juanjo Garcia Date: Fri, 2 Oct 2020 14:22:46 +0200 Subject: [PATCH] Adapt to python 3. Add message.xml. Delete unnecessary code (now in stock_sled). Delete unnecessary views (now in stock_sled). Add news depens. Fix version number. Adapt ca.po and es.po. 040479 --- __init__.py | 1 - locale/{ca_ES.po => ca.po} | 14 ++----- locale/{es_ES.po => es.po} | 14 ++----- message.xml | 13 ++++++ stock.py | 84 ++++++-------------------------------- stock.xml | 6 --- tryton.cfg | 3 +- view/lot_form.xml | 17 -------- view/lot_list.xml | 4 -- view/product_form.xml | 17 -------- view/product_list.xml | 8 ---- 11 files changed, 36 insertions(+), 145 deletions(-) rename locale/{ca_ES.po => ca.po} (88%) rename locale/{es_ES.po => es.po} (89%) create mode 100644 message.xml delete mode 100644 view/lot_form.xml delete mode 100644 view/product_form.xml delete mode 100644 view/product_list.xml diff --git a/__init__.py b/__init__.py index a7c4bf2..ceeb607 100644 --- a/__init__.py +++ b/__init__.py @@ -6,7 +6,6 @@ from . import stock def register(): Pool.register( - stock.Template, stock.Lot, stock.Location, stock.Move, diff --git a/locale/ca_ES.po b/locale/ca.po similarity index 88% rename from locale/ca_ES.po rename to locale/ca.po index 8840adc..f8a7118 100644 --- a/locale/ca_ES.po +++ b/locale/ca.po @@ -2,19 +2,13 @@ msgid "" msgstr "Content-Type: text/plain; charset=utf-8\n" -msgctxt "error:stock.lot:" +msgctxt "model:ir.message,text:expired" msgid "Expired" msgstr "Caducat" -msgctxt "error:stock.move:" -msgid "" -"You are trying to do the Stock Move \"%(move)s\" but its Lot \"%(lot)s\" is " -"expired and the Destination Location \"%(to_location)s\" doesn't accept " -"expired lots." -msgstr "" -"Està intentant realitzar el moviment d'estoc \"%(move)s\" però el seu lot " -"\"%(lot)s\" està caducat i la ubicació de destí \"%(to_location)s\" no " -"accepta lots caducats." +msgctxt "model:ir.message,text:expired_lot_invalid_destination" +msgid "You are trying to do the Stock Move \"%(move)s\" but its Lot \"%(lot)s\" is expired and the Destination Location \"%(to_location)s\" doesn't accept expired lots." +msgstr "Està intentant realitzar el moviment d'estoc \"%(move)s\" però el seu lot \"%(lot)s\" està caducat i la ubicació de destí \"%(to_location)s\" no accepta lots caducats." msgctxt "field:product.template,alert_time:" msgid "Alert Time" diff --git a/locale/es_ES.po b/locale/es.po similarity index 89% rename from locale/es_ES.po rename to locale/es.po index ad79415..fc83072 100644 --- a/locale/es_ES.po +++ b/locale/es.po @@ -2,19 +2,13 @@ msgid "" msgstr "Content-Type: text/plain; charset=utf-8\n" -msgctxt "error:stock.lot:" +msgctxt "model:ir.message,text:expired" msgid "Expired" msgstr "Caducado" -msgctxt "error:stock.move:" -msgid "" -"You are trying to do the Stock Move \"%(move)s\" but its Lot \"%(lot)s\" is " -"expired and the Destination Location \"%(to_location)s\" doesn't accept " -"expired lots." -msgstr "" -"Está intentando realizar el movimiento de estoc \"%(move)s\" pero su lote " -"\"%(lot)s\" está caducado y la bucación de destino \"%(to_location)s\" no " -"acepta lotes caducados." +msgctxt "model:ir.message,text:expired_lot_invalid_destination" +msgid "You are trying to do the Stock Move \"%(move)s\" but its Lot \"%(lot)s\" is expired and the Destination Location \"%(to_location)s\" doesn't accept expired lots." +msgstr "Está intentando realizar el movimiento de estoc \"%(move)s\" pero su lote \"%(lot)s\" está caducado y la bucación de destino \"%(to_location)s\" no acepta lotes caducados." msgctxt "field:product.template,alert_time:" msgid "Alert Time" diff --git a/message.xml b/message.xml new file mode 100644 index 0000000..1d7f248 --- /dev/null +++ b/message.xml @@ -0,0 +1,13 @@ + + + + + + Expired + + + You are trying to do the Stock Move "%(move)s" but its Lot "%(lot)s" is expired and the Destination Location "%(to_location)s" dosen't accept expired lots. + + + \ No newline at end of file diff --git a/stock.py b/stock.py index 425ba6c..ec9dff7 100644 --- a/stock.py +++ b/stock.py @@ -6,79 +6,29 @@ from trytond.model import Workflow, ModelView, fields from trytond.pool import Pool, PoolMeta from trytond.pyson import Bool, Eval, If from trytond.transaction import Transaction +from trytond.exceptions import UserError +from trytond.i18n import gettext -__all__ = ['Template', 'Lot', 'Location', 'Move'] +__all__ = ['Lot', 'Location', 'Move'] -class Template: - __metaclass__ = PoolMeta - __name__ = 'product.template' - - life_time = fields.Integer('Life Time', - help='The number of days before a lot may become dangerous and should ' - 'not be consumed.') - expiry_time = fields.Integer('Expiry Time', - help='The number of days before a lot starts deteriorating without ' - 'becoming dangerous.') - removal_time = fields.Integer('Removal Time', - help='The number of days before a lot should be removed.') - alert_time = fields.Integer('Alert Time', - help='The number of days after which an alert should be notified ' - 'about the lot.') - - -class Lot: - __metaclass__ = PoolMeta +class Lot(metaclass=PoolMeta): __name__ = 'stock.lot' - life_date = fields.Date('End of Life Date', - help='The date on which the lot may become dangerous and should not ' - 'be consumed.') - expiry_date = fields.Date('Expiry Date', - help='The date on which the lot starts deteriorating without becoming ' - 'dangerous.') - removal_date = fields.Date('Removal Date', - help='The date on which the lot should be removed.') - alert_date = fields.Date('Alert Date', - help='The date on which an alert should be notified about the lot.') expired = fields.Function(fields.Boolean('Expired'), 'get_expired', searcher='search_expired') - @classmethod - def __setup__(cls): - super(Lot, cls).__setup__() - cls._error_messages.update({ - 'Expired': 'Expired', - }) - def get_rec_name(self, name): rec_name = super(Lot, self).get_rec_name(name) if self.expired: - rec_name += ' (%s)' % self.raise_user_error('Expired', - raise_exception=False) + rec_name += ' (%s)' % gettext('stock_lot_expiry.expired') return rec_name - @fields.depends('product', 'life_date', 'expiry_date', 'removal_date', - 'alert_date') - def on_change_product(self): - try: - super(Lot, self).on_change_product() - except AttributeError: - pass - - if self.product: - for fname in ('life_date', 'expiry_date', 'removal_date', - 'alert_date'): - product_field = fname.replace('date', 'time') - margin = getattr(self.product.template, product_field) - setattr(self, fname, - margin and date.today() + timedelta(days=margin)) - def get_expired(self, name): pool = Pool() Date = pool.get('ir.date') - if not self.expiry_date: + if not self.expiration_date: return False context = Transaction().context @@ -87,7 +37,7 @@ class Lot: date = context['stock_move_date'] elif context.get('stock_date_end'): date = context['stock_date_end'] - return self.expiry_date <= date + return self.expiration_date <= date @classmethod def search_expired(cls, name, domain=None): @@ -108,20 +58,19 @@ class Lot: or op == '!=' and not operand) if search_expired: return [ - ('expiry_date', '!=', None), - ('expiry_date', '<=', date), + ('expiration_date', '!=', None), + ('expiration_date', '<=', date), ] else: return [ 'OR', [ - ('expiry_date', '=', None), + ('expiration_date', '=', None), ], [ - ('expiry_date', '>', date), + ('expiration_date', '>', date), ]] -class Location: - __metaclass__ = PoolMeta +class Location(metaclass=PoolMeta): __name__ = 'stock.location' expired = fields.Boolean('Expired Products\' Location', @@ -159,8 +108,7 @@ class Location: super(Location, cls).write(*args) -class Move: - __metaclass__ = PoolMeta +class Move(metaclass=PoolMeta): __name__ = 'stock.move' to_location_allow_expired = fields.Function( @@ -189,12 +137,6 @@ class Move: 'planned_date'): if fname not in cls.lot.depends: cls.lot.depends.append(fname) - cls._error_messages.update({ - 'expired_lot_invalid_destination': ('You are trying to do the ' - 'Stock Move "%(move)s" but its Lot "%(lot)s" is expired and ' - 'the Destination Location "%(to_location)s" doesn\'t accept ' - 'expired lots.'), - }) @fields.depends('to_location') def on_change_with_to_location_allow_expired(self, name=None): diff --git a/stock.xml b/stock.xml index 22c9dd0..6ab0276 100644 --- a/stock.xml +++ b/stock.xml @@ -17,12 +17,6 @@ - - stock.lot - - lot_form - - stock.lot diff --git a/tryton.cfg b/tryton.cfg index 75301f0..6cc6c4a 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -1,7 +1,8 @@ [tryton] -version=4.7.0 +version=5.4.0 depends: product stock_lot + stock_lot_sled xml: stock.xml diff --git a/view/lot_form.xml b/view/lot_form.xml deleted file mode 100644 index 2365559..0000000 --- a/view/lot_form.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - diff --git a/view/lot_list.xml b/view/lot_list.xml index 435a60d..bcbf023 100644 --- a/view/lot_list.xml +++ b/view/lot_list.xml @@ -4,9 +4,5 @@ - - - - diff --git a/view/product_form.xml b/view/product_form.xml deleted file mode 100644 index 9f59ce1..0000000 --- a/view/product_form.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - diff --git a/view/product_list.xml b/view/product_list.xml deleted file mode 100644 index 7f7a818..0000000 --- a/view/product_list.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - -