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
This commit is contained in:
Juanjo Garcia 2020-10-02 14:22:46 +02:00
parent e6e5848629
commit b9368d886d
11 changed files with 36 additions and 145 deletions

View File

@ -6,7 +6,6 @@ from . import stock
def register():
Pool.register(
stock.Template,
stock.Lot,
stock.Location,
stock.Move,

View File

@ -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"

View File

@ -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"

13
message.xml Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tryton>
<data grouped="1">
<record model="ir.message" id="expired">
<field name="text">Expired</field>
</record>
<record model="ir.message" id="expired_lot_invalid_destination">
<field name="text">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.</field>
</record>
</data>
</tryton>

View File

@ -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):

View File

@ -17,12 +17,6 @@
</record>
<!-- stock.lot -->
<record model="ir.ui.view" id="lot_view_form">
<field name="model">stock.lot</field>
<field name="inherit" ref="stock_lot.lot_view_form"/>
<field name="name">lot_form</field>
</record>
<record model="ir.ui.view" id="lot_view_list">
<field name="model">stock.lot</field>
<field name="inherit" ref="stock_lot.lot_view_tree"/>

View File

@ -1,7 +1,8 @@
[tryton]
version=4.7.0
version=5.4.0
depends:
product
stock_lot
stock_lot_sled
xml:
stock.xml

View File

@ -1,17 +0,0 @@
<?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<data>
<xpath expr="/form/field[@name='product']" position="after">
<group id="expiry_fields" colspan="4" col="8">
<label name="life_date"/>
<field name="life_date"/>
<label name="expiry_date"/>
<field name="expiry_date"/>
<label name="removal_date"/>
<field name="removal_date"/>
<label name="alert_date"/>
<field name="alert_date"/>
</group>
</xpath>
</data>

View File

@ -4,9 +4,5 @@
<data>
<xpath expr="/tree/field[@name='product']" position="after">
<field name="expired"/>
<field name="life_date"/>
<field name="expiry_date"/>
<field name="removal_date"/>
<field name="alert_date"/>
</xpath>
</data>

View File

@ -1,17 +0,0 @@
<?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<data>
<xpath expr="/form/notebook" position="inside">
<page id="expiry_times" string="Expiry Times">
<label name="life_time"/>
<field name="life_time"/>
<label name="expiry_time"/>
<field name="expiry_time"/>
<label name="removal_time"/>
<field name="removal_time"/>
<label name="alert_time"/>
<field name="alert_time"/>
</page>
</xpath>
</data>

View File

@ -1,8 +0,0 @@
<?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<data>
<xpath expr="/tree/field[@name='default_uom']" position="after">
<field name="expiry_time"/>
</xpath>
</data>