Migrate to 6.0

This commit is contained in:
Sergio Morillo 2021-09-24 10:02:16 +02:00
parent f01afd72de
commit 2133a3ca94
5 changed files with 34 additions and 23 deletions

View file

@ -2,7 +2,7 @@
msgid "" msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n" msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "error:stock.product.category.location:" msgctxt "model:ir.message,text:msg_category_location_unique_key"
msgid "Category and location must be unique." msgid "Category and location must be unique."
msgstr "Categoria y ubicación deben ser únicos." msgstr "Categoria y ubicación deben ser únicos."

View file

@ -4,6 +4,8 @@ from trytond.model import ModelView, ModelSQL, fields
from trytond.pyson import Eval, Bool, Not, Equal from trytond.pyson import Eval, Bool, Not, Equal
from trytond.pool import PoolMeta, Pool from trytond.pool import PoolMeta, Pool
from trytond.transaction import Transaction from trytond.transaction import Transaction
from trytond.exceptions import UserError
from trytond.i18n import gettext
from sql.aggregate import Max from sql.aggregate import Max
@ -34,16 +36,11 @@ class ProductCategoryLocation(ModelSQL, ModelView):
], depends=['warehouse']) ], depends=['warehouse'])
sequence = fields.Integer('Sequence') sequence = fields.Integer('Sequence')
@classmethod
def __setup__(cls):
super(ProductCategoryLocation, cls).__setup__()
cls._error_messages.update({
'unique_key': 'Category and location must be unique.'})
@staticmethod @staticmethod
def _compute_sequence_where(table, record): def _compute_sequence_where(table, record):
return ((table.category == record['category']) & return (
(table.warehouse == record['warehouse'])) (table.category == record['category'])
& (table.warehouse == record['warehouse']))
@staticmethod @staticmethod
def _compute_sequence(table, record): def _compute_sequence(table, record):
@ -63,7 +60,7 @@ class ProductCategoryLocation(ModelSQL, ModelView):
if not values.get('sequence', None): if not values.get('sequence', None):
values['sequence'] = cls._compute_sequence( values['sequence'] = cls._compute_sequence(
cls.__table__(), values) cls.__table__(), values)
return super(ProductCategoryLocation, cls).create(vlist) return super().create(vlist)
@classmethod @classmethod
def default_warehouse(cls): def default_warehouse(cls):
@ -88,16 +85,20 @@ class ProductCategoryLocation(ModelSQL, ModelView):
for record in records: for record in records:
_uq = record._get_unique_key() _uq = record._get_unique_key()
if values.get(_uq): if values.get(_uq):
cls.raise_user_error('unique_key') raise UserError(gettext(
'stock_product_category_location.'
'msg_category_location_unique_key'))
values.setdefault(_uq, 1) values.setdefault(_uq, 1)
others = cls.search([('id', 'not in', list(map(int, records)))]) others = cls.search([('id', 'not in', list(map(int, records)))])
for other in others: for other in others:
_uq = other._get_unique_key() _uq = other._get_unique_key()
if values.get(_uq): if values.get(_uq):
cls.raise_user_error('unique_key') raise UserError(gettext(
'stock_product_category_location.'
'msg_category_location_unique_key'))
super(ProductCategoryLocation, cls).validate(records) super().validate(records)
class Location(metaclass=PoolMeta): class Location(metaclass=PoolMeta):
@ -118,6 +119,6 @@ class Location(metaclass=PoolMeta):
@classmethod @classmethod
def view_attributes(cls): def view_attributes(cls):
return super(Location, cls).view_attributes() + [ return super().view_attributes() + [
('//page[@id="categories"]', 'states', { ('//page[@id="categories"]', 'states', {
'invisible': ~Eval('type').in_(['warehouse', 'storage'])})] 'invisible': ~Eval('type').in_(['warehouse', 'storage'])})]

11
message.xml Normal file
View file

@ -0,0 +1,11 @@
<?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">
<!-- stock.product.category.location -->
<record model="ir.message" id="msg_category_location_unique_key">
<field name="text">Category and location must be unique.</field>
</record>
</data>
</tryton>

View file

@ -9,7 +9,7 @@ class ShipmentOut(metaclass=PoolMeta):
__name__ = 'stock.shipment.out' __name__ = 'stock.shipment.out'
def _get_inventory_move(self, move): def _get_inventory_move(self, move):
res = super(ShipmentOut, self)._get_inventory_move(move) res = super()._get_inventory_move(move)
if not res or hasattr(res, 'unit_load'): if not res or hasattr(res, 'unit_load'):
return res return res
for c in res.product.categories: for c in res.product.categories:
@ -27,14 +27,13 @@ class ShipmentOut(metaclass=PoolMeta):
class ShipmentOutReturn(metaclass=PoolMeta): class ShipmentOutReturn(metaclass=PoolMeta):
__name__ = 'stock.shipment.out.return' __name__ = 'stock.shipment.out.return'
@classmethod def _get_inventory_move(self, incoming_move):
def _get_inventory_moves(cls, incoming_move): res = super()._get_inventory_move(incoming_move)
res = super(ShipmentOutReturn, cls)._get_inventory_moves(incoming_move)
if not res: if not res:
return res return res
for c in res.product.categories: for c in res.product.categories:
_to_location = c.get_default_location( _to_location = c.get_default_location(
**cls._get_default_location_params(incoming_move)) **self._get_default_location_params(incoming_move))
if _to_location: if _to_location:
res.to_location = _to_location res.to_location = _to_location
break break
@ -48,14 +47,13 @@ class ShipmentOutReturn(metaclass=PoolMeta):
class ShipmentIn(metaclass=PoolMeta): class ShipmentIn(metaclass=PoolMeta):
__name__ = 'stock.shipment.in' __name__ = 'stock.shipment.in'
@classmethod def _get_inventory_move(self, incoming_move):
def _get_inventory_moves(cls, incoming_move): res = super()._get_inventory_move(incoming_move)
res = super(ShipmentIn, cls)._get_inventory_moves(incoming_move)
if not res: if not res:
return res return res
for c in res.product.categories: for c in res.product.categories:
_to_location = c.get_default_location( _to_location = c.get_default_location(
**cls._get_default_location_params(incoming_move)) **self._get_default_location_params(incoming_move))
if _to_location: if _to_location:
res.to_location = _to_location res.to_location = _to_location
break break

View file

@ -11,3 +11,4 @@ extras_depend:
xml: xml:
location.xml location.xml
product.xml product.xml
message.xml