Migrate to 6.0

This commit is contained in:
José Miguel Pardo Salar 2022-11-29 19:31:34 +01:00
parent 5b09b7bac6
commit faeb7a2bfa
6 changed files with 48 additions and 39 deletions

View file

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

19
message.xml Normal file
View file

@ -0,0 +1,19 @@
<?xml version="1.0"?>
<!-- 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="msg_lot_different_name">
<field name="text">Lots have different numbers: %(source_name)s vs %(destination_name)s.</field>
</record>
<record model="ir.message" id="msg_lot_different_product">
<field name="text">Lots have different product: %(source_code)s vs %(destination_code)s.</field>
</record>
<record model="ir.message" id="msg_lot_period_cache">
<field name="text">Cannot replace lots with Period cache. Please go back period "%(period)s" to Draft first.</field>
</record>
<record model="ir.message" id="msg_lot_uniq_by_product">
<field name="text">Lot number must be unique by product.</field>
</record>
</data>
</tryton>

View file

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

View file

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

View file

@ -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,
}])

View file

@ -7,3 +7,4 @@ depends:
xml:
stock.xml
message.xml