Migrate to 6.0

This commit is contained in:
José Miguel Pardo Salar 2021-10-14 10:40:31 +02:00
parent 1152e25dd9
commit c0f83460e2
16 changed files with 355 additions and 249 deletions

View File

@ -2,8 +2,6 @@
# copyright notices and license terms.
from trytond.pool import PoolMeta
__all__ = ['Configuration', 'ConfigurationLoad']
class Configuration(metaclass=PoolMeta):
__name__ = 'party.configuration'

125
load.py
View File

@ -6,7 +6,6 @@ from decimal import Decimal
from trytond.rpc import RPC
from sql import Null
from sql.operators import Concat
from trytond import backend
from trytond.model import fields, ModelView, Model, ModelSQL, Unique, Workflow
from trytond.pool import PoolMeta, Pool
from trytond.pyson import Eval, Bool, Id
@ -14,18 +13,14 @@ from trytond.tools import reduce_ids
from trytond.transaction import Transaction
from trytond.wizard import Wizard, StateTransition, StateView, Button, \
StateAction
from trytond.exceptions import UserError, UserWarning
from trytond.i18n import gettext
try:
import phonenumbers
from phonenumbers import PhoneNumberFormat, NumberParseException
except ImportError:
phonenumbers = None
__all__ = ['Configuration', 'Load', 'LoadOrder', 'LoadOrderLine',
'LoadUnitLoad', 'LoadUnitLoadOrder', 'LoadUnitLoadData', 'DoLoadOrder',
'LoadSheet', 'CMR', 'RoadTransportNote', 'CreateLoadDataMixin',
'CreateLoadDataLineMixin', 'LoadUnitLoadFailed', 'LoadOrderLineUL',
'CarrierLoadPurchase']
class Configuration(metaclass=PoolMeta):
__name__ = 'carrier.configuration'
@ -87,27 +82,6 @@ class LoadOrder(metaclass=PoolMeta):
'depends': ['state']
},
})
cls._error_messages.update({
'cancel_ul': 'Cannot cancel load orders with loaded ULs',
'ul_state': 'UL "%s" must be in Done state.',
'ul_loaded': 'UL "%s" is already loaded.',
'ul_location': 'UL "%s" must be in a storage location.',
'ul_warehouse': 'UL "%s" must be in warehouse "%s" to be loaded '
'in order "%s".',
'ul_origin': 'UL "%s" does not belong to any origin of this '
'load order.',
'ul_overload': 'All valid lines of load order "%s" are complete. '
'Cannot load more ULs.',
'draft_ul': 'Cannot change state to Draft for load order "%s" '
'because it has loaded ULs.',
'pending_uls': 'You have loaded less ULs (%s) than expected (%s).',
'sale_confirmed': 'Cannot force loading ULs because sale "%s" is '
'confirmed.',
'no_uls': 'Load order "%s" must have some UL to be finished.',
'many_ul_locations': 'Cannot set "From location" in Internal '
'shipment of Load Order "%s" because Unit loads are in '
'different locations.'
})
@classmethod
def __register__(cls, module_name):
@ -177,7 +151,8 @@ class LoadOrder(metaclass=PoolMeta):
@classmethod
def cancel(cls, records):
if any(r.unit_loads for r in records):
cls.raise_user_error('cancel_ul')
raise UserError(gettext(
'carrier_load_ul.msg_carrier_load_order_cancel_ul'))
super(LoadOrder, cls).cancel(records)
def _get_load_sale(self, Sale):
@ -212,8 +187,9 @@ class LoadOrder(metaclass=PoolMeta):
if self.unit_loads:
from_locations = set([ul.location for ul in self.unit_loads])
if len(from_locations) > 1:
self.raise_user_error('many_ul_locations',
self.rec_name)
raise UserError(gettext(
'carrier_load_ul.msg_carrier_load_order_many_ul_locations',
order=self.rec_name))
shipment.from_location = from_locations.pop()
return shipment
@ -288,7 +264,9 @@ class LoadOrder(metaclass=PoolMeta):
if self.state != 'done':
return
elif self.sale.state not in ('draft', 'quotation'):
self.raise_user_error('sale_confirmed', self.sale.rec_name)
raise UserError(gettext(
'carrier_load_ul.msg_carrier_load_order_sale_confirmed',
sale=self.sale.rec_name))
keyfunc = partial(self._group_sale_line_key, uls)
items = sorted(uls, key=keyfunc)
@ -413,13 +391,21 @@ class LoadOrder(metaclass=PoolMeta):
@classmethod
def _check_loaded_quantity(cls, records):
pool = Pool()
Warning = pool.get('res.user.warning')
for record in records:
if not record.unit_loads:
cls.raise_user_error('no_uls', record.rec_name)
raise UserError(gettext(
'carrier_load_ul.msg_carrier_load_order_no_uls',
order=record.rec_name))
if record.ul_quantity > len(record.unit_loads):
cls.raise_user_warning('pending_uls_%s' % record.id,
'pending_uls', (len(record.unit_loads),
int(record.ul_quantity)))
warning_name = 'pending_uls_%s' % record.id
if Warning.check(warning_name):
raise UserWarning(warning_name, gettext(
'carrier_load_ul.msg_carrier_load_order_pending_uls',
uls=len(record.unit_loads),
ul_quantity=int(record.ul_quantity)))
@classmethod
def _set_loaded_unit_loads(cls, records, revert=False):
@ -449,7 +435,9 @@ class LoadOrder(metaclass=PoolMeta):
if record.state != 'waiting':
continue
if record.unit_loads:
cls.raise_user_error('draft_ul', record.rec_name)
raise UserError(gettext(
'carrier_load_ul.msg_carrier_load_order_draft_ul',
order=record.rec_name))
super(LoadOrder, cls).draft(records)
def _get_inventory_move(self, move):
@ -505,11 +493,15 @@ class LoadOrder(metaclass=PoolMeta):
# check it is not loaded yet
if unit_load.load_line:
self.raise_user_error('ul_loaded', unit_load.rec_name)
raise UserError(gettext(
'carrier_load_ul.msg_carrier_load_order_ul_loaded',
unit_load=unit_load.rec_name))
# check it is in storage location
if unit_load.location.type != 'storage':
self.raise_user_error('ul_location', unit_load.rec_name)
raise UserError(gettext(
'carrier_load_ul.msg_carrier_load_order_ul_location',
unit_load=unit_load.rec_name))
# check it is in warehouse
self.check_add_unit_load_warehouse(unit_load)
@ -535,7 +527,9 @@ class LoadOrder(metaclass=PoolMeta):
# load UL
unit_load.load_line = line
elif unit_load not in failed_uls:
self.raise_user_error('ul_overload', self.rec_name)
raise UserError(gettext(
'carrier_load_ul.msg_carrier_load_order_ul_overload',
order=self.rec_name))
if failed_uls:
return failed_uls
@ -551,14 +545,18 @@ class LoadOrder(metaclass=PoolMeta):
def check_add_unit_load_state(self, unit_load):
if unit_load.state != 'done':
self.raise_user_error('ul_state', unit_load.rec_name)
raise UserError(gettext(
'carrier_load_ul.msg_carrier_load_order_ul_state',
unit_load=unit_load.rec_name))
def check_add_unit_load_warehouse(self, unit_load):
wh = unit_load.location.warehouse
if not wh or wh.id != self.load.warehouse.id:
self.raise_user_error('ul_warehouse', (
unit_load.rec_name, self.load.warehouse.rec_name,
self.rec_name))
raise UserError(gettext(
'carrier_load_ul.msg_carrier_load_order_ul_warehouse',
unit_load=unit_load.rec_name,
warehouse=self.load.warehouse.rec_name,
order=self.rec_name))
def _choose_matched_line(self, lines, values, unit_load):
line = None
@ -575,6 +573,9 @@ class LoadOrder(metaclass=PoolMeta):
def check_origin_restrict(self, unit_load, origin_restrict,
origin_restrict_warn):
pool = Pool()
Warning = pool.get('res.user.warning')
lines = []
warn = False
for line in self.lines:
@ -584,13 +585,18 @@ class LoadOrder(metaclass=PoolMeta):
lines.append(line)
else:
if origin_restrict:
self.raise_user_error('ul_origin', unit_load.rec_name)
raise UserError(gettext(
'carrier_load_ul.msg_carrier_load_order_ul_origin',
unit_load=unit_load.rec_name))
if origin_restrict_warn:
warn = True
lines.append(line)
if warn:
self.raise_user_warning('loading_ul_origin_%s' %
unit_load.id, 'ul_origin', unit_load.rec_name)
warning_name = 'loading_ul_origin_%s' % unit_load.id
if Warning.check(warning_name):
raise UserWarning(warning_name, gettext(
'carrier_load_ul.msg_carrier_load_order_ul_origin',
unit_load=unit_load.rec_name))
return lines
@classmethod
@ -787,11 +793,6 @@ class LoadUnitLoad(Wizard):
'load': RPC(readonly=False),
'unload': RPC(readonly=False),
})
cls._error_messages.update({
'invalid_ul': 'Cannot find Unit load "%s".',
'ul_required': 'Must define an UL to load.',
'unload_any': 'Must select some Unit load from loaded ULs list '
'in order to unload them.'})
def transition_start(self):
pool = Pool()
@ -828,7 +829,8 @@ class LoadUnitLoad(Wizard):
if uls is not None:
uls = list(uls)
if not ul_code and not uls:
cls.raise_user_error('ul_required')
raise UserError(gettext(
'carrier_load_ul.msg_carrier_load_uls_ul_required'))
if isinstance(order_id, int):
order = Order(order_id)
else:
@ -913,7 +915,8 @@ class LoadUnitLoad(Wizard):
Order = pool.get('carrier.load.order')
if not uls:
cls.raise_user_error('unload_any')
raise UserError(gettext(
'carrier_load_ul.msg_carrier_load_uls_unload_any'))
if isinstance(order_id, int):
order = Order(order_id)
else:
@ -938,7 +941,9 @@ class LoadUnitLoad(Wizard):
UL = Pool().get('stock.unit_load')
uls = UL.search([('code', '=', code)])
if not uls:
cls.raise_user_error('invalid_ul', code)
raise UserError(gettext(
'carrier_load_ul.msg_carrier_load_uls_invalid_ul',
code=code))
return uls
@ -1102,14 +1107,6 @@ class CreateLoadDataMixin(object):
'invisible': Bool(Eval('load_order'))
}, depends=['load_order'])
@classmethod
def __setup__(cls):
super().__setup__()
cls._error_messages.update({
'invalid_phonenumber': ('The phone number "%(phone)s" '
'is not valid.'),
})
@classmethod
def default_load_purchasable(cls):
pool = Pool()
@ -1199,7 +1196,7 @@ class LoadOrderLineUL(ModelSQL):
t = cls.__table__()
cls._sql_constraints += [
('load_line_ul_uniq', Unique(t, t.load_line, t.unit_load),
'Load order line and unit load must be unique.')]
'carrier_load_ul.msg_carrier_load_order_line-stock_unit_load_load_line_ul_uniq')]
@classmethod
def __register__(cls, module_name):

View File

@ -629,7 +629,7 @@
<text:sequence-decl text:display-outline-level="0" text:name="Figure"/>
</text:sequence-decls>
<text:p text:style-name="P3"><text:placeholder text:placeholder-type="text">&lt;for each=&quot;load in records&quot;&gt;</text:placeholder></text:p>
<text:p text:style-name="P4"><text:placeholder text:placeholder-type="text">&lt;set_lang(load.company.party.lang and load.company.party.lang.code or &apos;en_US&apos;)&gt;</text:placeholder><text:placeholder text:placeholder-type="text">&lt;load.set_lang(load.company.party.lang and load.company.party.lang.code or &apos;en_US&apos;)&gt;</text:placeholder></text:p>
<text:p text:style-name="P4"><text:placeholder text:placeholder-type="text">&lt;set_lang(load.company.party.lang and load.company.party.lang.code or &apos;en&apos;)&gt;</text:placeholder><text:placeholder text:placeholder-type="text">&lt;load.set_lang(load.company.party.lang and load.company.party.lang.code or &apos;en&apos;)&gt;</text:placeholder></text:p>
<text:p text:style-name="P5"/>
<table:table table:name="Table1" table:style-name="Table1">
<table:table-column table:style-name="Table1.A"/>

View File

@ -2,143 +2,142 @@
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "error:carrier.load.create_wizard:"
msgid "Cannot use Load \"%s\" due to it is in Done state."
msgstr "No puede usar la Carga \"%s\" ya que está Finalizada."
msgctxt "model:ir.message,text:msg_carrier_load_create_wizard_load_done"
msgid "Cannot use Load \"%(load)s\" due to it is in Done state."
msgstr "No puede usar la Carga \"%(load)s\" ya que está Finalizada."
msgctxt "error:carrier.load.create_wizard:"
msgid "It is going to generate %s order loads."
msgstr "Se van a generar %s órdenes de carga."
msgctxt "error:carrier.load.create_wizard:"
msgid "Sale \"%s\" must be Confirmed or Processing to be loaded."
msgstr "La venta \"%s\" debe estar Confirmada o En proceso para cargarse."
msgctxt "error:carrier.load.create_wizard:"
msgid ""
"Cannot create load for Sale \"%s\" in \"Processing\" state and Shipment method \"On Order Processed\"."
msgctxt "model:ir.message,text:msg_carrier_load_create_wizard_wrong_load_order"
msgid "Cannot add all theses lines to load order \"%(order)s\"."
msgstr ""
"No puede crear carga para la venta \"%s\" en estado \"En proceso\" y método de envío \"Al procesar el pedido\"."
"No puede añadir todas estas líneas a la orden de carga \"%(order)s\"."
msgctxt "error:carrier.load.create_wizard:"
msgctxt "model:ir.message,text:msg_carrier_load_create_wizard_many_orders"
msgid "It is going to generate %(keys)s order loads."
msgstr "Se van a generar %(keys)s órdenes de carga."
msgctxt "model:ir.message,text:msg_carrier_load_create_wizard_sale_state"
msgid "Sale \"%(sale)s\" must be Confirmed or Processing to be loaded."
msgstr "La venta \"%(sale)s\" debe estar Confirmada o En proceso para cargarse."
msgctxt "model:ir.message,text:msg_carrier_load_create_wizard_wrong_shipment_method"
msgid ""
"Cannot create load for Sale \"%(sale)s\" in \"Processing\" state and Shipment method \"On Order Processed\"."
msgstr ""
"No puede crear carga para la venta \"%(sale)s\" en estado \"En proceso\" y método de envío \"Al procesar el pedido\"."
msgctxt "model:ir.message,text:msg_carrier_load_create_wizard_nothing_load"
msgid "There is nothing to load. Check if there are ULs pending to load."
msgstr "No hay nada que cargar. Revise si hay UdCs pendientes."
msgctxt "error:carrier.load.order:"
msgid "All valid lines of load order \"%s\" are complete. Cannot load more ULs."
msgctxt "model:ir.message,text:msg_carrier_load_order_ul_overload"
msgid "All valid lines of load order \"%(order)s\" are complete. Cannot load more ULs."
msgstr ""
"Todas las líneas válidas de la Orden de carga \"%s\" están completadas. No "
"Todas las líneas válidas de la Orden de carga \"%(order)s\" están completadas. No "
"puede cargar más UdCs."
msgctxt "error:carrier.load.order:"
msgctxt "model:ir.message,text:msg_carrier_load_order_cancel_ul"
msgid "Cannot cancel load orders with loaded ULs"
msgstr "No puede cancelar Ordenes de carga con UdCs."
msgctxt "error:carrier.load.order:"
msgctxt "model:ir.message,text:msg_carrier_load_order_draft_ul"
msgid ""
"Cannot change state to Draft for load order \"%s\" because it has loaded "
"Cannot change state to Draft for load order \"%(order)s\" because it has loaded "
"ULs."
msgstr ""
"No puede establecerse el estado Borrador para la orden \"%s\" porque tiene "
"No puede establecerse el estado Borrador para la orden \"%(order)s\" porque tiene "
"UdCs cargadas."
msgctxt "error:carrier.load.order:"
msgid "Cannot force loading ULs because sale \"%s\" is confirmed."
msgctxt "model:ir.message,text:msg_carrier_load_order_sale_confirmed"
msgid "Cannot force loading ULs because sale \"%(sale)s\" is confirmed."
msgstr ""
"No puede forzar la carga de UdCs porque la Venta asociada \"%s\" está "
"No puede forzar la carga de UdCs porque la Venta asociada \"%(sale)s\" está "
"confirmada."
msgctxt "error:carrier.load.order:"
msgid "Load order \"%s\" must have some UL to be finished."
msgstr "La Orden de carga \"%s\" debe contener alguna UdC para poder finalizarse."
msgctxt "model:ir.message,text:msg_carrier_load_order_no_uls"
msgid "Load order \"%(order)s\" must have some UL to be finished."
msgstr "La Orden de carga \"%(order)s\" debe contener alguna UdC para poder finalizarse."
msgctxt "error:carrier.load.order:"
msgid "Product data of UL \"%s\" does not match with any line of load order \"%s\"."
msgctxt "model:ir.message,text:msg_carrier_load_order_ul_origin"
msgid "UL \"%(unit_load)s\" does not belong to any origin of this load order."
msgstr "La UdC \"%(unit_load)s\" no pertenece a ningún origen de la Orden de carga actual."
msgctxt "model:ir.message,text:msg_carrier_load_order_ul_loaded"
msgid "UL \"%(unit_load)s\" is already loaded."
msgstr "La UdC \"%(unit_load)s\" ya ha sido cargada."
msgctxt "model:ir.message,text:msg_carrier_load_order_ul_state"
msgid "UL \"%(unit_load)s\" must be in Done state."
msgstr "La UdC \"%(unit_load)s\" debe estar Finalizada."
msgctxt "model:ir.message,text:msg_carrier_load_order_ul_location"
msgid "UL \"%(unit_load)s\" must be in a storage location."
msgstr "La UdC \"%(unit_load)s\" debe encontrarse en una ubicación de almacenamiento."
msgctxt "model:ir.message,text:msg_carrier_load_order_ul_warehouse"
msgid "UL \"%(unit_load)s\" must be in warehouse \"%(warehouse)s\" to be loaded in order \"%(order)s\"."
msgstr ""
"La información de producto de la UdC \"%s\" no coincide con ninguna línea de"
" la Orden de carga \"%s\"."
"La UdC \"%(unit_load)s\" debe encontrarse en el almacén \"%(warehouse)s\" para ser cargada en la "
"orden \"%(order)s\"."
msgctxt "error:carrier.load.order:"
msgid "UL \"%s\" does not belong to any origin of this load order."
msgstr "La UdC \"%s\" no pertenece a ningún origen de la Orden de carga actual."
msgctxt "model:ir.message,text:msg_carrier_load_order_pending_uls"
msgid "You have loaded less ULs (%(uls)s) than expected (%(ul_quantity)s)."
msgstr "Ha cargado menos UdCs (%(uls)s) de las esperadas (%(ul_quantity)s)."
msgctxt "error:carrier.load.order:"
msgid "UL \"%s\" is already loaded."
msgstr "La UdC \"%s\" ya ha sido cargada."
msgctxt "error:carrier.load.order:"
msgid "UL \"%s\" must be in Done state."
msgstr "La UdC \"%s\" debe estar Finalizada."
msgctxt "error:carrier.load.order:"
msgid "UL \"%s\" must be in a storage location."
msgstr "La UdC \"%s\" debe encontrarse en una ubicación de almacenamiento."
msgctxt "error:carrier.load.order:"
msgid "UL \"%s\" must be in warehouse \"%s\" to be loaded in order \"%s\"."
msgstr ""
"La UdC \"%s\" debe encontrarse en el almacén \"%s\" para ser cargada en la "
"orden \"%s\"."
msgctxt "error:carrier.load.order:"
msgid "You have loaded less ULs (%s) than expected (%s)."
msgstr "Ha cargado menos UdCs (%s) de las esperadas (%s)."
msgctxt "error:carrier.load.order:"
msgctxt "model:ir.message,text:msg_carrier_load_order_many_ul_locations"
msgid ""
"Cannot set \"From location\" in Internal shipment of Load Order \"%s\" because Unit loads are in different locations."
"Cannot set \"From location\" in Internal shipment of Load Order \"%(order)s\" because Unit loads are in different locations."
msgstr ""
"No puede establecerse \"Desde ubicación\" en el albarán interno de la orden de carga \"%s\" porque las Unidades de carga están ubicaciones diferentes."
"No puede establecerse \"Desde ubicación\" en el albarán interno de la orden de carga \"%(order)s\" porque las Unidades de carga están ubicaciones diferentes."
msgctxt "error:carrier.load_uls:"
msgid "Cannot find Unit load \"%s\"."
msgstr "No se ha podido encontrar la UdC \"%s\"."
msgctxt "model:ir.message,text:msg_carrier_load_uls_invalid_ul"
msgid "Cannot find Unit load \"%(code)s\"."
msgstr "No se ha podido encontrar la UdC \"%(code)s\"."
msgctxt "error:carrier.load_uls:"
msgctxt "model:ir.message,text:msg_carrier_load_uls_ul_required"
msgid "Must define an UL to load."
msgstr "Debe definir una UdC para cargarse."
msgctxt "error:carrier.load_uls:"
msgctxt "model:ir.message,text:msg_carrier_load_uls_unload_any"
msgid ""
"Must select some Unit load from loaded ULs list in order to unload them."
msgstr "Debe seleccionar alguna UdC de la lista para poder descargarlas."
msgctxt "error:sale.sale:"
msgid "Cannot Cancel Sale \"%s\" because it has loads."
msgstr "No puede cancelar la Venta \"%s\" porque tiene cargas asociadas."
msgctxt "model:ir.message,text:msg_sale_sale_cancel_loads"
msgid "Cannot Cancel Sale \"%(sale)s\" because it has loads."
msgstr "No puede cancelar la Venta \"%(sale)s\" porque tiene cargas asociadas."
msgctxt "error:sale.sale:"
msgid "Cannot Process Sale \"%s\" with ULs and undone loads."
msgctxt "model:ir.message,text:msg_sale_sale_process_undone_loads"
msgid "Cannot Process Sale \"%(sale)s\" with ULs and undone loads."
msgstr ""
"No puede procesar la Venta \"%s\" porque se han definido UdCs y hay cargas no finalizadas."
"No puede procesar la Venta \"%(sale)s\" porque se han definido UdCs y hay cargas no finalizadas."
msgctxt "error:sale.sale:"
msgid "The Sale \"%s\" has no loads."
msgstr "La Venta \"%s\" no tiene cargas."
msgctxt "model:ir.message,text:msg_sale_sale_process_noloads"
msgid "The Sale \"%(sale)s\" has no loads."
msgstr "La Venta \"%(sale)s\" no tiene cargas."
msgctxt "error:stock.unit_load:"
msgctxt "model:ir.message,text:msg_stock_unit_load_delete_load"
msgid "Cannot delete ULs that are already loaded."
msgstr "No es posible eliminar una UdC que ya está cargada."
msgctxt "error:stock.unit_load:"
msgctxt "model:ir.message,text:msg_stock_unit_load_unload"
msgid "Cannot unload an UL from a Load order in Done state."
msgstr "No es posible descargar una UdC de una Orden de carga Finalizada."
msgctxt "error:stock.unit_load:"
msgctxt "model:ir.message,text:msg_stock_unit_load_wrong_load_order"
msgid ""
"You are trying to unload the UL \"%s\" from the Load order \"%s\". This is not allowed, probably there are later loads. Please check its load orders."
"You are trying to unload the UL \"%(unit_load)s\" from the Load order \"%(order)s\". This is not allowed, probably there are later loads. Please check its load orders."
msgstr ""
"Está intentando descargar la UdC \"%s\" de la Orden de carga \"%s\". Esta operación no está permitida, es posible que existan cargas posteriores. Revise sus cargas asociadas."
"Está intentando descargar la UdC \"%(unit_load)s\" de la Orden de carga \"%(order)s\". Esta operación no está permitida, es posible que existan cargas posteriores. Revise sus cargas asociadas."
msgctxt "error:carrier.load.create_from_sale:"
msgctxt "model:ir.message,text:msg_carrier_load_create_from_sale_invalid_phonenumber"
msgid "The phone number \"%(phone)s\" is not valid."
msgstr "El número de teléfono \"%(phone)s\" no es válido."
msgctxt "error:sale.line:"
msgid "The line \"%s\" with unit load moves cannot be deleted."
msgstr "La línea \"%s\" con movimientos de unidad de carga no puede eliminarse."
msgctxt "model:ir.message,text:msg_sale_line_delete_unit_load"
msgid "The line \"%(sale_line)s\" with unit load moves cannot be deleted."
msgstr "La línea \"%(sale_line)s\" con movimientos de unidad de carga no puede eliminarse."
msgctxt "error:carrier.load.order.line-stock.unit_load:"
msgctxt "model:ir.message,text:msg_carrier_load_order_line-stock_unit_load_load_line_ul_uniq"
msgid "Load order line and unit load must be unique."
msgstr "La línea de la orden de carga y la unidad de carga deben ser únicas."

111
message.xml Normal file
View File

@ -0,0 +1,111 @@
<?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">
<!-- carrier.load.create_from_sale -->
<record model="ir.message" id="msg_carrier_load_create_from_sale_invalid_phonenumber">
<field name="text">The phone number "%(phone)s" is not valid.</field>
</record>
<!-- carrier.load.create_wizard -->
<record model="ir.message" id="msg_carrier_load_create_wizard_wrong_shipment_method">
<field name="text">Cannot create load for Sale "%(sale)s" in "Processing" state and Shipment method "On Order Processed".</field>
</record>
<record model="ir.message" id="msg_carrier_load_create_wizard_load_done">
<field name="text">Cannot use Load "%(load)s" due to it is in Done state.</field>
</record>
<record model="ir.message" id="msg_carrier_load_create_wizard_many_orders">
<field name="text">It is going to generate %(keys)s order loads.</field>
</record>
<record model="ir.message" id="msg_carrier_load_create_wizard_sale_state">
<field name="text">Sale "%(sale)s" must be Confirmed or Processing to be loaded.</field>
</record>
<record model="ir.message" id="msg_carrier_load_create_wizard_nothing_load">
<field name="text">There is nothing to load. Check if there are ULs pending to load.</field>
</record>
<record model="ir.message" id="msg_carrier_load_create_wizard_wrong_load_order">
<field name="text">Cannot add all theses lines to load order "%(order)s".</field>
</record>
<!-- carrier.load.order -->
<record model="ir.message" id="msg_carrier_load_order_ul_overload">
<field name="text">All valid lines of load order "%(order)s" are complete. Cannot load more ULs.</field>
</record>
<record model="ir.message" id="msg_carrier_load_order_cancel_ul">
<field name="text">Cannot cancel load orders with loaded ULs</field>
</record>
<record model="ir.message" id="msg_carrier_load_order_draft_ul">
<field name="text">Cannot change state to Draft for load order "%(order)s" because it has loaded ULs.</field>
</record>
<record model="ir.message" id="msg_carrier_load_order_sale_confirmed">
<field name="text">Cannot force loading ULs because sale "%(sale)s" is confirmed.</field>
</record>
<record model="ir.message" id="msg_carrier_load_order_many_ul_locations">
<field name="text">Cannot set "From location" in Internal shipment of Load Order "%(order)s" because Unit loads are in different locations.</field>
</record>
<record model="ir.message" id="msg_carrier_load_order_no_uls">
<field name="text">Load order "%(order)s" must have some UL to be finished.</field>
</record>
<record model="ir.message" id="msg_carrier_load_order_ul_origin">
<field name="text">UL "%(unit_load)s" does not belong to any origin of this load order.</field>
</record>
<record model="ir.message" id="msg_carrier_load_order_ul_loaded">
<field name="text">UL "%(unit_load)s" is already loaded.</field>
</record>
<record model="ir.message" id="msg_carrier_load_order_ul_state">
<field name="text">UL "%(unit_load)s" must be in Done state.</field>
</record>
<record model="ir.message" id="msg_carrier_load_order_ul_location">
<field name="text">UL "%(unit_load)s" must be in a storage location.</field>
</record>
<record model="ir.message" id="msg_carrier_load_order_ul_warehouse">
<field name="text">UL "%(unit_load)s" must be in warehouse "%(warehouse)s" to be loaded in order "%(order)s".</field>
</record>
<record model="ir.message" id="msg_carrier_load_order_pending_uls">
<field name="text">You have loaded less ULs (%(uls)s) than expected (%(ul_quantity)s).</field>
</record>
<!-- carrier.load.order.line-stock.unit_load -->
<record model="ir.message" id="msg_carrier_load_order_line-stock_unit_load_load_line_ul_uniq">
<field name="text">Load order line and unit load must be unique.</field>
</record>
<!-- carrier.load_uls -->
<record model="ir.message" id="msg_carrier_load_uls_invalid_ul">
<field name="text">Cannot find Unit load "%(code)s".</field>
</record>
<record model="ir.message" id="msg_carrier_load_uls_ul_required">
<field name="text">Must define an UL to load.</field>
</record>
<record model="ir.message" id="msg_carrier_load_uls_unload_any">
<field name="text">Must select some Unit load from loaded ULs list in order to unload them.</field>
</record>
<!-- sale.line -->
<record model="ir.message" id="msg_sale_line_delete_unit_load">
<field name="text">The line "%(sale_line)s" with unit load moves cannot be deleted.</field>
</record>
<!-- sale.sale -->
<record model="ir.message" id="msg_sale_sale_cancel_loads">
<field name="text">Cannot Cancel Sale "%(sale)s" because it has loads.</field>
</record>
<record model="ir.message" id="msg_sale_sale_process_undone_loads">
<field name="text">Cannot Process Sale "%(sale)s" with ULs and undone loads.</field>
</record>
<record model="ir.message" id="msg_sale_sale_process_noloads">
<field name="text">The Sale "%(sale)s" has no loads.</field>
</record>
<!-- stock.unit_load -->
<record model="ir.message" id="msg_stock_unit_load_delete_load">
<field name="text">Cannot delete ULs that are already loaded.</field>
</record>
<record model="ir.message" id="msg_stock_unit_load_wrong_load_order">
<field name="text">You are trying to unload the UL "%(unit_load)s" from the Load order "%(order)s". This is not allowed, probably there are later loads. Please check its load orders.</field>
</record>
<record model="ir.message" id="msg_stock_unit_load_unload">
<field name="text">Cannot unload an UL from a Load order in Done state.</field>
</record>
</data>
</tryton>

View File

@ -2,8 +2,6 @@
# copyright notices and license terms.
from trytond.pool import PoolMeta
__all__ = ['Party']
class Party(metaclass=PoolMeta):
__name__ = 'party.party'

122
sale.py
View File

@ -6,11 +6,10 @@ from trytond.pyson import Eval
from trytond.wizard import (Wizard, StateView, StateAction, StateTransition,
Button)
from trytond.transaction import Transaction
from trytond.exceptions import UserError, UserWarning
from trytond.i18n import gettext
from .load import CreateLoadDataMixin, CreateLoadDataLineMixin
__all__ = ['Sale', 'SaleLine', 'CreateLoadFromSale', 'CreateLoadLineFromSale',
'CreateLoad']
class Sale(metaclass=PoolMeta):
__name__ = 'sale.sale'
@ -33,13 +32,6 @@ class Sale(metaclass=PoolMeta):
_field = getattr(cls, _field_name, None)
_field.states['readonly'] |= Eval('loads', [])
_field.depends.append('load_lines')
cls._error_messages.update({
'cancel_loads': 'Cannot Cancel Sale "%s" because it has loads.',
'process_noloads':
'The Sale "%s" has no loads.',
'process_undone_loads':
'Cannot Process Sale "%s" with ULs and undone loads.',
})
def get_load_lines(self, name=None):
loads = []
@ -87,19 +79,25 @@ class Sale(metaclass=PoolMeta):
@classmethod
def cancel(cls, records):
for record in records:
if (record.loads and record.origin and
record.origin.__name__ != 'carrier.load.order'):
cls.raise_user_error('cancel_loads')
if (record.loads and record.origin
and record.origin.__name__ != 'carrier.load.order'):
raise UserError(gettext(
'carrier_load_ul.msg_sale_sale_cancel_loads',
sale=record.rec_name))
super(Sale, cls).cancel(records)
def check_method(self):
if not self.loads and (not self.origin or
self.origin.__name__ != 'carrier.load.order'):
if not self.loads and (not self.origin
or self.origin.__name__ != 'carrier.load.order'):
super(Sale, self).check_method()
return
if (self.shipment_method == 'invoice' and
self.invoice_method in ('shipment', 'manual')):
self.raise_user_error('invalid_method', (self.rec_name,))
if (self.shipment_method == 'invoice'
and self.invoice_method in ('shipment', 'manual')):
raise UserError(gettext(
'sale.msg_sale_invalid_method',
invoice_method=self.invoice_method,
shipment_method=self.shipment_method,
sale=self.rec_name))
@classmethod
def quote(cls, records):
@ -117,14 +115,23 @@ class Sale(metaclass=PoolMeta):
super(Sale, cls).process(sales)
def _check_loads(self):
pool = Pool()
Warning = pool.get('res.user.warning')
if self.state != 'confirmed':
return
if self.ul_quantity and not self.loads:
self.raise_user_warning('process_noloads_%s' % self.id,
'process_noloads', self.rec_name)
with Transaction().set_context(_skip_warnings=False):
warning_name = 'process_noloads_%s' % self.id
if Warning.check(warning_name):
raise UserWarning(warning_name, gettext(
'carrier_load_ul.msg_sale_sale_process_noloads',
sale=self.rec_name))
if self.ul_quantity and self.loads and any(
l.state not in ('cancelled', 'done') for l in self.loads):
self.raise_user_error('process_undone_loads', self.rec_name)
raise UserError(gettext(
'carrier_load_ul.msg_sale_sale_process_undone_loads',
sale=self.rec_name))
class SaleLine(metaclass=PoolMeta):
@ -140,14 +147,6 @@ class SaleLine(metaclass=PoolMeta):
help='Available UL quantity to be loaded'),
'get_ul_quantity_to_load')
@classmethod
def __setup__(cls):
super().__setup__()
cls._error_messages.update({
'delete_unit_load': ('The line "%s" with unit load moves '
'cannot be deleted.')
})
@classmethod
def copy(cls, records, default=None):
if default is None:
@ -173,7 +172,9 @@ class SaleLine(metaclass=PoolMeta):
def delete(cls, records):
for record in records:
if any(bool(m.unit_load) for m in record.moves):
cls.raise_user_error('delete_unit_load', record.rec_name)
raise UserError(gettext(
'carrier_load_ul.msg_sale_line_delete_unit_load',
sale_line=record.rec_name))
super().delete(records)
@ -206,22 +207,6 @@ class CreateLoad(Wizard):
Button('OK', 'load_', 'tryton-ok', default=True)])
load_ = StateAction('carrier_load.act_load_order')
@classmethod
def __setup__(cls):
super(CreateLoad, cls).__setup__()
cls._error_messages.update({
'nothing_load':
'There is nothing to load. Check if there are ULs '
'pending to load.',
'load_done': 'Cannot use Load "%s" due to it is in Done state.',
'many_orders': 'It is going to generate %s order loads.',
'sale_state': 'Sale "%s" must be Confirmed or Processing to '
'be loaded.',
'wrong_shipment_method':
'Cannot create load for Sale "%s" in "Processing" state and '
'Shipment method "On Order Processed".'
})
def transition_start(self):
pool = Pool()
Sale = pool.get('sale.sale')
@ -232,10 +217,14 @@ class CreateLoad(Wizard):
if Transaction().context['active_model'] == 'sale.sale':
sale = Sale(Transaction().context['active_id'])
if sale.state not in ('confirmed', 'processing'):
self.raise_user_error('sale_state', sale.rec_name)
raise UserError(gettext(
'carrier_load_ul.msg_carrier_load_create_wizard_sale_state',
sale=sale.rec_name))
elif sale.state == 'processing' and \
sale.shipment_method == 'order':
self.raise_user_error('wrong_shipment_method', sale.rec_name)
raise UserError(gettext(
'carrier_load_ul.msg_carrier_load_create_wizard_wrong_shipment_method',
sale=sale.rec_name))
return 'sale_data'
return 'end'
@ -253,7 +242,8 @@ class CreateLoad(Wizard):
}
sale = Sale(Transaction().context.get('active_id'))
if sale.ul_quantity_to_load <= 0:
self.raise_user_error('nothing_load')
raise UserError(gettext(
'carrier_load_ul.msg_carrier_load_create_wizard_nothing_load'))
if not res.get('warehouse', None):
res.update({'warehouse': sale.warehouse.id})
if len(sale.warehouse.docks) == 1:
@ -265,7 +255,8 @@ class CreateLoad(Wizard):
continue
res['lines'].append(self._get_sale_line_data(line))
if not res['lines']:
self.raise_user_error('nothing_load')
raise UserError(gettext(
'carrier_load_ul.msg_carrier_load_create_wizard_nothing_load'))
return res
def _get_sale_line_data(self, sale_line):
@ -283,7 +274,7 @@ class CreateLoad(Wizard):
def do_load_(self, action):
pool = Pool()
Load = pool.get('carrier.load')
Warning = pool.get('res.user.warning')
LoadOrder = pool.get('carrier.load.order')
Sale = pool.get('sale.sale')
@ -292,11 +283,15 @@ class CreateLoad(Wizard):
if getattr(_data_state, 'load_order', None):
_load = _data_state.load_order.load
if _load.state == 'done':
self.raise_user_error('load_done', _load.rec_name)
raise UserError(gettext(
'carrier_load_ul.msg_carrier_load_create_wizard_load_done',
load=_load.rec_name))
else:
_load = self._get_load()
if not _load.carrier and not _load.carrier_info:
Load.raise_user_error('missing_carrier_info', _load.rec_name)
raise UserError(gettext(
'carrier_load.msg_carrier_load_missing_carrier_info',
load=_load.rec_name))
order_lines = []
load_order_keys = {}
@ -324,8 +319,11 @@ class CreateLoad(Wizard):
for load_order, uls in load_order2uls.items():
load_order.add_ul(uls)
if len(load_order_keys) > 1:
self.raise_user_warning('many_orders_%s' % Transaction().user,
'many_orders', len(load_order_keys))
warning_name = 'many_orders_%s' % Transaction().user
if Warning.check(warning_name):
raise UserWarning(warning_name, gettext(
'carrier_load_ul.msg_carrier_load_create_wizard_many_orders',
keys=len(load_order_keys)))
order_ids = list(set([o.order.id for o in order_lines]))
data = {'res_id': order_ids}
if len(order_ids) == 1:
@ -382,14 +380,16 @@ class CreateLoad(Wizard):
Transaction().context['active_model']])
if getattr(_data_state, 'load_order', None):
if len(load_order_keys) > 1:
self.raise_user_error('wrong_load_order',
self.data.load_order.rec_name)
raise UserError(gettext(
'carrier_load_ul.msg_carrier_load_create_wizard_wrong_load_order',
order=self.data.load_order.rec_name))
_key = next(iter(load_order_keys.keys()))
if (_data_state.load_order.lines and
any(_key != self._get_grouping_load_order_key(l.origin)
if (_data_state.load_order.lines
and any(_key != self._get_grouping_load_order_key(l.origin)
for l in _data_state.load_order.lines)):
self.raise_user_error('wrong_load_order',
_data_state.load_order.rec_name)
raise UserError(gettext(
'carrier_load_ul.msg_carrier_load_create_wizard_wrong_load_order',
order=self.data.load_order.rec_name))
return _data_state.load_order
key = self._get_grouping_load_order_key(line.origin)

View File

@ -12,7 +12,6 @@ MODULE2PREFIX = {
'carrier_load': 'datalife',
'sale_unit_load': 'datalife',
'stock_unit_load': 'datalife',
'stock_move_done2cancel': 'datalife'
}

View File

@ -6,8 +6,6 @@ from sql import Null
from sql.operators import Concat
from sql.conditionals import Coalesce
__all__ = ['Move']
class Move(metaclass=PoolMeta):
__name__ = 'stock.move'

View File

@ -177,10 +177,10 @@ Add other products to unit load::
>>> template.type = 'goods'
>>> template.salable = True
>>> template.list_price = Decimal('10')
>>> template.cost_price = Decimal('5')
>>> template.account_category = account_category_tax
>>> template.save()
>>> product.template = template
>>> product, = template.products
>>> product.cost_price = Decimal('5')
>>> product.save()
>>> move = ul.moves.new()
>>> move.planned_date = today
@ -189,6 +189,7 @@ Add other products to unit load::
>>> move.from_location = ul.moves[0].from_location
>>> move.to_location = ul.moves[0].to_location
>>> move.currency = move.company.currency
>>> move.unit_price = product.cost_price
>>> ul.save()
Starting load wizard::
@ -315,6 +316,7 @@ Force load another UL::
>>> move.from_location = ul.moves[0].from_location
>>> move.to_location = ul.moves[0].to_location
>>> move.currency = move.company.currency
>>> move.unit_price = product.cost_price
>>> ul.save()
>>> ul.click('assign')
>>> ul.click('do')

View File

@ -15,6 +15,7 @@ Imports::
>>> from trytond.modules.account_invoice.tests.tools import \
... set_fiscalyear_invoice_sequences, create_payment_term
>>> from trytond.modules.stock_unit_load.tests.tools import create_unit_load
>>> from trytond.exceptions import UserWarning
>>> from proteus import Model, Wizard, Report
>>> today = datetime.date.today()
@ -120,10 +121,10 @@ Add other products to unit load::
>>> template.type = 'goods'
>>> template.salable = True
>>> template.list_price = Decimal('10')
>>> template.cost_price = Decimal('5')
>>> template.account_category = account_category_tax
>>> template.save()
>>> product.template = template
>>> product, = template.products
>>> product.cost_price = Decimal('5')
>>> product.save()
Create unit load::
@ -141,6 +142,7 @@ Create unit load::
... move.from_location = ul.moves[0].from_location
... move.to_location = ul.moves[0].to_location
... move.currency = move.company.currency
... move.unit_price = product.cost_price
... ul.save()
... uls.append(ul)
... if main_product is None:
@ -175,6 +177,7 @@ Create sale::
>>> sale_line.ul_quantity = 4.0
>>> sale_line.cases_quantity = 20
>>> sale.click('quote')
>>> import logging
>>> sale.click('confirm')
>>> sale.click('process')
Traceback (most recent call last):
@ -270,7 +273,7 @@ Check UL quantity control::
>>> loading.execute('load_')
Traceback (most recent call last):
...
trytond.exceptions.UserError: Cannot exceed quantity of "Product @ 1". -
trytond.exceptions.UserError: Cannot exceed quantity of "140u Product @ 1". -
Start loading ULs restrictions::
@ -408,4 +411,4 @@ Check report::
>>> ext
'odt'
>>> name
'Load sheet'
'Load sheet-1'

View File

@ -177,10 +177,10 @@ Add other products to unit load::
>>> template.type = 'goods'
>>> template.salable = True
>>> template.list_price = Decimal('10')
>>> template.cost_price = Decimal('5')
>>> template.account_category = account_category_tax
>>> template.save()
>>> product.template = template
>>> product, = template.products
>>> product.cost_price = Decimal('5')
>>> product.save()
>>> move = ul.moves.new()
>>> move.planned_date = today
@ -189,6 +189,7 @@ Add other products to unit load::
>>> move.from_location = ul.moves[0].from_location
>>> move.to_location = ul.moves[0].to_location
>>> move.currency = move.company.currency
>>> move.unit_price = product.cost_price
>>> ul.save()
Starting load wizard::
@ -393,6 +394,7 @@ Force load another UL::
>>> move.from_location = ul.moves[0].from_location
>>> move.to_location = ul.moves[0].to_location
>>> move.currency = move.company.currency
>>> move.unit_price = product.cost_price
>>> ul.save()
>>> ul.click('assign')
>>> ul.click('do')
@ -447,6 +449,7 @@ Add a third UL with done shipment::
>>> move.from_location = ul.moves[0].from_location
>>> move.to_location = ul.moves[0].to_location
>>> move.currency = move.company.currency
>>> move.unit_price = product.cost_price
>>> ul.save()
>>> ul.click('assign')
>>> ul.click('do')
@ -513,4 +516,4 @@ Check rerport carrier load purchase::
>>> ext
'odt'
>>> name
'Carrier load purchase'
'Carrier load purchase-1'

View File

@ -182,10 +182,10 @@ Add other products to unit load::
>>> template.type = 'goods'
>>> template.salable = True
>>> template.list_price = Decimal('10')
>>> template.cost_price = Decimal('5')
>>> template.account_category = account_category_tax
>>> template.save()
>>> product.template = template
>>> product, = template.products
>>> product.cost_price = Decimal('5')
>>> product.save()
>>> move = ul.moves.new()
>>> move.planned_date = today
@ -194,6 +194,7 @@ Add other products to unit load::
>>> move.from_location = ul.moves[0].from_location
>>> move.to_location = ul.moves[0].to_location
>>> move.currency = move.company.currency
>>> move.unit_price = product.cost_price
>>> ul.save()
Starting load wizard::
@ -387,6 +388,7 @@ Force load another UL::
>>> move.from_location = ul.moves[0].from_location
>>> move.to_location = ul.moves[0].to_location
>>> move.currency = move.company.currency
>>> move.unit_price = product.cost_price
>>> ul.save()
>>> ul.click('assign')
>>> ul.click('do')

View File

@ -216,4 +216,4 @@ Check restriction unloading::
>>> start_load.execute('unload_')
Traceback (most recent call last):
...
trytond.exceptions.UserError: You are trying to unload the UL "1" from the Load order "1". This is not allowed, probably there are later loads. Please check its load orders. -
trytond.exceptions.UserError: You are trying to unload the UL "1 - Product (5.0 Cases, 35.0 u)" from the Load order "1". This is not allowed, probably there are later loads. Please check its load orders. -

View File

@ -8,11 +8,10 @@ depends:
stock_unit_load
extras_depend:
stock_move_done2cancel
sale_confirmed2quotation
carrier_load_grouping_method
xml:
load.xml
unit_load.xml
sale.xml
message.xml

View File

@ -3,9 +3,8 @@
from trytond.model import fields, ModelView, Model
from trytond.pool import PoolMeta, Pool
from trytond.pyson import Eval, Bool
from trytond.transaction import Transaction
__all__ = ['UnitLoad', 'UnitLoadLabel']
from trytond.exceptions import UserError
from trytond.i18n import gettext
class UnitLoad(metaclass=PoolMeta):
@ -36,14 +35,6 @@ class UnitLoad(metaclass=PoolMeta):
cls._buttons['move_try'].setdefault('depends', [])
cls._buttons['move_try']['depends'].append('load_order')
cls._error_messages.update({
'unload': 'Cannot unload an UL from a Load order in Done state.',
'delete_load': 'Cannot delete ULs that are already loaded.',
'wrong_load_order': 'You are trying to unload the UL "%s" from '
'the Load order "%s". This is not allowed, probably there are '
'later loads. Please check its load orders.'
})
def get_load_order_state(self, name=None):
if self.load_order:
return self.load_order.state
@ -66,7 +57,8 @@ class UnitLoad(metaclass=PoolMeta):
@classmethod
def delete(cls, records):
if any(r.load_line for r in records):
cls.raise_user_error('delete_load')
raise UserError(gettext(
'carrier_load_ul.msg_stock_unit_load_delete_load'))
super(UnitLoad, cls).delete(records)
@classmethod
@ -115,18 +107,23 @@ class UnitLoad(metaclass=PoolMeta):
for record in records:
load_line = record.load_line
if load_line and load_order and load_line.order != load_order:
cls.raise_user_error('wrong_load_order', (
record.rec_name, load_order.rec_name))
raise UserError(gettext(
'carrier_load_ul.msg_stock_unit_load_wrong_load_order',
unit_load=record.rec_name,
order=load_order.rec_name))
if not load_line and record.load_lines:
load_line = record.load_lines[-1]
if load_order and load_line.order != load_order:
cls.raise_user_error('wrong_load_order', (
record.rec_name, load_order.rec_name))
raise UserError(gettext(
'carrier_load_ul.msg_stock_unit_load_wrong_load_order',
unit_load=record.rec_name,
order=load_order.rec_name))
if load_line and load_line.order.state == 'done' and \
load_line.order.sale.state not in ('draft', 'quotation'):
cls.raise_user_error('unload')
raise UserError(gettext(
'carrier_load_ul.msg_stock_unit_load_unload'))
return True
@classmethod