Box fixed/picking + assign a shipment in a box

This commit is contained in:
resteve 2015-10-22 10:30:31 +02:00
parent 7cee290abf
commit bcedd1a085
7 changed files with 189 additions and 62 deletions

View File

@ -1,14 +1,24 @@
#
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "error:stock.picking.box.out.assign:"
msgid ""
"Shipment \"%(shipment)s\" can not assign in box \"%(box)s\" because there is"
" another shipment assigned. Please select a new box."
msgstr ""
"L'albarà \"%(shipment)s\" no es pot assignar en el box \"%(box)s\" perque ja"
" existeix un altre albarà ja assignat. Seleccione un nou box."
msgctxt "error:stock.picking.box.out.assign:"
msgid "Shipment \"%(shipment)s\" is available in box \"%(box)s\"."
msgstr "L'albarà \"%(shipment)s\" ja es troba en el box \"%(box)s\"."
msgctxt "error:stock.picking.box.shipment.out:"
msgid ""
"Shipment\"%(shipment)s\" could not assign any box. Please try again or wait "
"to available new box."
msgstr ""
"L'albarà \"%(shipment)s\" no s'ha pogut assignar a cap box. Torni a provar-"
"ho o esperi que estigui disponible un box."
"Shipment \"%(shipment)s\" could not assign any box. Please try again or wait"
" to available new box."
msgstr "L'albarà \"%(shipment)s\" ja es troba en el box \"%(box)s\"."
msgctxt "field:stock.picking.box.out,active:"
msgid "Active"
@ -26,6 +36,10 @@ msgctxt "field:stock.picking.box.out,id:"
msgid "ID"
msgstr "ID"
msgctxt "field:stock.picking.box.out,location:"
msgid "Location"
msgstr "Ubicació"
msgctxt "field:stock.picking.box.out,name:"
msgid "Name"
msgstr "Nom"
@ -38,6 +52,10 @@ msgctxt "field:stock.picking.box.out,sequence:"
msgid "Sequence"
msgstr "Seqüència"
msgctxt "field:stock.picking.box.out,type:"
msgid "Type"
msgstr "Tipus"
msgctxt "field:stock.picking.box.out,warehouse:"
msgid "Warehouse"
msgstr "Magatzem"
@ -102,6 +120,10 @@ msgctxt "field:stock.picking.box.shipment.out.result,shipment:"
msgid "Shipment"
msgstr "Albarà client"
msgctxt "field:stock.picking.box.shipment.out.start,box:"
msgid "Box"
msgstr "Box"
msgctxt "field:stock.picking.box.shipment.out.start,id:"
msgid "ID"
msgstr "ID"
@ -112,15 +134,15 @@ msgstr "Albarà client"
msgctxt "model:ir.action,name:act_stock_picking_box_out"
msgid "Picking Boxes Out"
msgstr "Boxes d'empaquetament sortida"
msgstr "Boxes d'albarans de client"
msgctxt "model:ir.action,name:act_stock_picking_box_out_assign"
msgid "Picking Boxes Out Assign"
msgstr "Assignació box empaqueta sortida"
msgstr "Assigna box d'albarans de client"
msgctxt "model:ir.action,name:act_stock_picking_box_shipment_out"
msgid "Stock Picking Box Out"
msgstr "Box empaqueta sortida"
msgstr "Box albarans de client"
msgctxt ""
"model:ir.action.act_window.domain,name:act_stock_picking_box_out_assign_all"
@ -147,35 +169,43 @@ msgstr "Boxes d'empaquetament"
msgctxt "model:ir.ui.menu,name:menu_stock_picking_box_out"
msgid "Picking Box Out"
msgstr "Box empaqueta sortida"
msgstr "Box albarans de client"
msgctxt "model:ir.ui.menu,name:menu_stock_picking_box_out_assign"
msgid "Picking Box Out"
msgstr "Box empaqueta sortida"
msgstr "Box albarans de client"
msgctxt "model:ir.ui.menu,name:menu_stock_picking_box_shipment_out"
msgid "Picking Box Out"
msgstr "Box empaqueta sortida"
msgstr "Box albarans de client"
msgctxt "model:stock.picking.box.out,name:"
msgid "Stock Picking Box Out"
msgstr "Box empaqueta sortida"
msgstr "Box albarans de client"
msgctxt "model:stock.picking.box.out.assign,name:"
msgid "Stock Picking Box Out Assign"
msgstr "Assignació box empaqueta sortida"
msgstr "Assignar box albarans de client"
msgctxt "model:stock.picking.box.shipment.out.result,name:"
msgid "Shipment Picking Box Shipment Out Result"
msgstr "Resultat box empaquetament albarà sortida"
msgstr "Resultat box albarà de client"
msgctxt "model:stock.picking.box.shipment.out.start,name:"
msgid "Shipment Picking Box Shipment Out Start"
msgstr "Inici box empaquetament albarà sortida"
msgstr "Assignació box albarà de client"
msgctxt "selection:stock.picking.box.out,type:"
msgid "Fixed"
msgstr "Fix"
msgctxt "selection:stock.picking.box.out,type:"
msgid "Picking"
msgstr "Empaquetament"
msgctxt "selection:stock.picking.box.out.assign,state:"
msgid "Done"
msgstr "Finalitzat"
msgstr "Finalitza"
msgctxt "selection:stock.picking.box.out.assign,state:"
msgid "Waiting"
@ -191,11 +221,11 @@ msgstr "General"
msgctxt "view:stock.picking.box.out.assign:"
msgid "Picking Box Out Assign"
msgstr "Assigna box empaqueta sortida"
msgstr "Assigna box albarà de client"
msgctxt "view:stock.picking.box.out.assign:"
msgid "Picking Boxes Out Assign"
msgstr "Assigna box empaqueta sortida"
msgstr "Assignació box d'albarans de client"
msgctxt "view:stock.picking.box.out.assign:"
msgid "Waiting"
@ -203,15 +233,15 @@ msgstr "En espera"
msgctxt "view:stock.picking.box.out:"
msgid "Picking Box Out"
msgstr "Box empaqueta sortida"
msgstr "Box albarans de client"
msgctxt "view:stock.picking.box.out:"
msgid "Picking Boxes Out"
msgstr "Boxes d'empaquetament sortida"
msgstr "Boxes d'albarans de client"
msgctxt "view:stock.picking.box.shipment.out.result:"
msgid "Picking Box Shipment Out Result"
msgstr "Resultat box empaquetament sortida"
msgstr "Resultat box albarà de client"
msgctxt "view:stock.picking.box.shipment.out.result:"
msgid "Successfully shipment assigned. Leave the shipment on the box"
@ -219,7 +249,7 @@ msgstr "S'ha assignat l'albarà. Deixi l'albarà en el box."
msgctxt "view:stock.picking.box.shipment.out.start:"
msgid "Picking Box Shipment Out Start"
msgstr "Inici box empaquetament sortida"
msgstr "Assignació box albarà de client"
msgctxt "wizard_button:stock.picking.box.shipment.out,picking,assign:"
msgid "Assign"

View File

@ -1,14 +1,26 @@
#
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "error:stock.picking.box.out.assign:"
msgid ""
"Shipment \"%(shipment)s\" can not assign in box \"%(box)s\" because there is"
" another shipment assigned. Please select a new box."
msgstr ""
"El albarán \"%(shipment)s\" no se puede asignar en el box \"%(box)s\" porque"
" existe otro albarán ya asignado. Selecciona un nuevo box."
msgctxt "error:stock.picking.box.out.assign:"
msgid "Shipment \"%(shipment)s\" is available in box \"%(box)s\"."
msgstr "El albarán \"%(shipment)s\" ya se encuentra en el box \"%(box)s\"."
msgctxt "error:stock.picking.box.shipment.out:"
msgid ""
"Shipment\"%(shipment)s\" could not assign any box. Please try again or wait "
"to available new box."
"Shipment \"%(shipment)s\" could not assign any box. Please try again or wait"
" to available new box."
msgstr ""
"El albarán \"%(shipment)s\" no se ha podido asignar a ningún box. Vuelve a "
"probarlo o espere que esté disponible un box."
"El albarán \"%(shipment)s\" no se puede asignar en ningún box. Intente más "
"tarde o espere que se libre un box."
msgctxt "field:stock.picking.box.out,active:"
msgid "Active"
@ -26,6 +38,10 @@ msgctxt "field:stock.picking.box.out,id:"
msgid "ID"
msgstr "ID"
msgctxt "field:stock.picking.box.out,location:"
msgid "Location"
msgstr "Ubicación"
msgctxt "field:stock.picking.box.out,name:"
msgid "Name"
msgstr "Nombre"
@ -38,6 +54,10 @@ msgctxt "field:stock.picking.box.out,sequence:"
msgid "Sequence"
msgstr "Secuencia"
msgctxt "field:stock.picking.box.out,type:"
msgid "Type"
msgstr "Tipo"
msgctxt "field:stock.picking.box.out,warehouse:"
msgid "Warehouse"
msgstr "Almacén"
@ -102,6 +122,10 @@ msgctxt "field:stock.picking.box.shipment.out.result,shipment:"
msgid "Shipment"
msgstr "Albarán cliente"
msgctxt "field:stock.picking.box.shipment.out.start,box:"
msgid "Box"
msgstr "Box"
msgctxt "field:stock.picking.box.shipment.out.start,id:"
msgid "ID"
msgstr "ID"
@ -112,15 +136,15 @@ msgstr "Albarán cliente"
msgctxt "model:ir.action,name:act_stock_picking_box_out"
msgid "Picking Boxes Out"
msgstr "Boxes de empaquetamiento salida"
msgstr "Boxes de albaranes de cliente"
msgctxt "model:ir.action,name:act_stock_picking_box_out_assign"
msgid "Picking Boxes Out Assign"
msgstr "Asignación boxes de empaquetamiento salida"
msgstr "Asignar boxes de albaranes cliente"
msgctxt "model:ir.action,name:act_stock_picking_box_shipment_out"
msgid "Stock Picking Box Out"
msgstr "Box empaquetar salida"
msgstr "Box albaranes cliente"
msgctxt ""
"model:ir.action.act_window.domain,name:act_stock_picking_box_out_assign_all"
@ -147,35 +171,43 @@ msgstr "Boxes de empaquetamiento"
msgctxt "model:ir.ui.menu,name:menu_stock_picking_box_out"
msgid "Picking Box Out"
msgstr "Box empaquetar salida"
msgstr "Box albaranes de cliente"
msgctxt "model:ir.ui.menu,name:menu_stock_picking_box_out_assign"
msgid "Picking Box Out"
msgstr "Box empaquetar salida"
msgstr "Box albaranes de cliente"
msgctxt "model:ir.ui.menu,name:menu_stock_picking_box_shipment_out"
msgid "Picking Box Out"
msgstr "Box empaquetar salida"
msgstr "Box albaranes de cliente"
msgctxt "model:stock.picking.box.out,name:"
msgid "Stock Picking Box Out"
msgstr "Box empaquetar salida"
msgstr "Box albaranes cliente"
msgctxt "model:stock.picking.box.out.assign,name:"
msgid "Stock Picking Box Out Assign"
msgstr "Asignación box empaquetar salida"
msgstr "Asignar box albaranes cliente"
msgctxt "model:stock.picking.box.shipment.out.result,name:"
msgid "Shipment Picking Box Shipment Out Result"
msgstr "Resultado box empaquetamiento albaranes de salida"
msgstr "Resultado box albarán de salida"
msgctxt "model:stock.picking.box.shipment.out.start,name:"
msgid "Shipment Picking Box Shipment Out Start"
msgstr "Inicio box empaquetamiento albaranes de salida"
msgstr "Assignación box albarán de salida"
msgctxt "selection:stock.picking.box.out,type:"
msgid "Fixed"
msgstr "Fijo"
msgctxt "selection:stock.picking.box.out,type:"
msgid "Picking"
msgstr "Empaquetar"
msgctxt "selection:stock.picking.box.out.assign,state:"
msgid "Done"
msgstr "Realizado"
msgstr "Realizar"
msgctxt "selection:stock.picking.box.out.assign,state:"
msgid "Waiting"
@ -191,11 +223,11 @@ msgstr "General"
msgctxt "view:stock.picking.box.out.assign:"
msgid "Picking Box Out Assign"
msgstr "Asignación box empaquetar salida"
msgstr "Asignación box albaranes de salida"
msgctxt "view:stock.picking.box.out.assign:"
msgid "Picking Boxes Out Assign"
msgstr "Asignación boxes de empaquetamiento salida"
msgstr "Asignación boxes de albaranes cliente"
msgctxt "view:stock.picking.box.out.assign:"
msgid "Waiting"
@ -203,15 +235,15 @@ msgstr "En espera"
msgctxt "view:stock.picking.box.out:"
msgid "Picking Box Out"
msgstr "Box empaquetar salida"
msgstr "Box albaranes de cliente"
msgctxt "view:stock.picking.box.out:"
msgid "Picking Boxes Out"
msgstr "Boxes de empaquetamiento salida"
msgstr "Boxes de albaranes de cliente"
msgctxt "view:stock.picking.box.shipment.out.result:"
msgid "Picking Box Shipment Out Result"
msgstr "Resultado box empaquetamiento salida"
msgstr "Resultado box box albarán de salida"
msgctxt "view:stock.picking.box.shipment.out.result:"
msgid "Successfully shipment assigned. Leave the shipment on the box"
@ -219,7 +251,7 @@ msgstr "Se ha asignado el albarán. Deje el albarán en el box."
msgctxt "view:stock.picking.box.shipment.out.start:"
msgid "Picking Box Shipment Out Start"
msgstr "Inicio box empaquetamiento salida"
msgstr "Assignación box albarán de salida"
msgctxt "wizard_button:stock.picking.box.shipment.out,picking,assign:"
msgid "Assign"

View File

@ -3,7 +3,7 @@
#the full copyright notices and license terms.
from trytond.model import ModelView, ModelSQL, fields
from trytond.wizard import Wizard, StateTransition, StateView, Button
from trytond.pool import Pool, PoolMeta
from trytond.pool import Pool
from trytond.pyson import Eval, Equal, Not
from trytond.transaction import Transaction
import logging
@ -21,8 +21,14 @@ class StockPickingBoxOut(ModelSQL, ModelView):
name = fields.Char('Name', required=True)
warehouse = fields.Many2One('stock.location', 'Warehouse',
domain=[('type', '=', 'warehouse')], required=True)
location = fields.Many2One('stock.location', 'Location',
domain=[('type', '=', 'storage')])
sequence = fields.Integer('Sequence')
active = fields.Boolean('Active', select=True)
type = fields.Selection([
('fixed', 'Fixed'),
('picking', 'Picking'),
], 'Type')
@staticmethod
def default_sequence():
@ -32,6 +38,10 @@ class StockPickingBoxOut(ModelSQL, ModelView):
def default_active():
return True
@staticmethod
def default_type():
return 'fixed'
class StockPickingBoxOutAssign(ModelSQL, ModelView):
'Stock Picking Box Out Assign'
@ -56,6 +66,13 @@ class StockPickingBoxOutAssign(ModelSQL, ModelView):
@classmethod
def __setup__(cls):
super(StockPickingBoxOutAssign, cls).__setup__()
cls._error_messages.update({
'not_box_available': 'Shipment "%(shipment)s" can not assign '
'in box "%(box)s" because there is another shipment assigned. '
'Please select a new box.',
'not_reassign_shipment': 'Shipment "%(shipment)s" is available '
'in box "%(box)s".',
})
cls._buttons.update({
'done': {
'invisible': Eval('state') == 'done',
@ -88,26 +105,58 @@ class StockPickingBoxOutAssign(ModelSQL, ModelView):
})
@classmethod
def assign(cls, shipment, attempts=0, total_attempts=5):
def assign(cls, shipment, box=None, attempts=0, total_attempts=5):
'''Assign a shipment in a box
1. Reassign a shipment to other box
2. Assign a shipment to new box
3. Assign a shipment to new box (search a free box)'''
pool = Pool()
StockPickingBoxOut = pool.get('stock.picking.box.out')
User = pool.get('res.user')
# 1. Reassign a shipment to other box
assigned_boxes = cls.search([
('shipment', '=', shipment),
('state', '=', 'waiting'),
])
if assigned_boxes:
assigned_box, = assigned_boxes
if box:
# assign shipment to new box
cls.write([assigned_box], {'box': box})
return box
cls.raise_user_error('not_reassign_shipment', {
'shipment': shipment.rec_name,
'box': assigned_box.box.rec_name,
})
# 2. Assign a shipment to new box
if box:
assigned = cls.search([
('box', '=', box),
('state', '=', 'waiting'),
])
if assigned:
cls.raise_user_error('not_box_available', {
'shipment': shipment.rec_name,
'box': box.rec_name,
})
# assign shipment to box
cls.create([{
'shipment': shipment,
'box': box,
}])
return box
# 3. Assign a shipment to new box (search a free box)
transaction = Transaction()
user = User(transaction.user)
warehouse = None
locations = None
if hasattr(user, 'stock_warehouse'):
warehouse = user.stock_warehouse
# check if shipment is assigned in a waiting box
assigned = cls.search([
('shipment', '=', shipment),
('state', '=', 'waiting'),
])
if assigned:
return
locations = user.stock_locations
try:
# Locks transaction. Nobody can query this table
transaction.cursor.lock(cls._table)
@ -124,13 +173,17 @@ class StockPickingBoxOutAssign(ModelSQL, ModelView):
domain = [('state', '=', 'waiting')]
if warehouse:
domain.append(('box.warehouse', '=', warehouse))
if locations:
domain.append(('box.location', 'in', locations))
boxes_assigned = cls.search(domain)
domain = []
domain = [('type', '=', 'fixed')]
if boxes_assigned:
domain.append(('id', 'not in', [b.box.id for b in boxes_assigned]))
if warehouse:
domain.append(('warehouse', '=', warehouse))
if locations:
domain.append(('location', 'in', locations))
boxes = StockPickingBoxOut.search(domain, limit=1)
if not boxes:
@ -149,6 +202,7 @@ class StockPickingBoxShipmentOutStart(ModelView):
'Shipment Picking Box Shipment Out Start'
__name__ = 'stock.picking.box.shipment.out.start'
shipment = fields.Many2One('stock.shipment.out', 'Shipment', required=True)
box = fields.Many2One('stock.picking.box.out', 'Box')
class StockPickingBoxShipmentOutResult(ModelView):
@ -178,9 +232,9 @@ class StockPickingBoxShipmentOut(Wizard):
def __setup__(cls):
super(StockPickingBoxShipmentOut, cls).__setup__()
cls._error_messages.update({
'not_box': 'Shipment"%(shipment)s" could not assign any box. '
'not_box': 'Shipment "%(shipment)s" could not assign any box. '
'Please try again or wait to available new box.',
})
})
def transition_start(self):
return 'picking'
@ -190,15 +244,16 @@ class StockPickingBoxShipmentOut(Wizard):
StockPickingBoxOutAssign = pool.get('stock.picking.box.out.assign')
shipment = self.picking.shipment
box = self.picking.box
box = StockPickingBoxOutAssign.assign(shipment)
if not box:
box_assigned = StockPickingBoxOutAssign.assign(shipment, box)
if not box_assigned:
self.raise_user_error('not_box', {
'shipment': shipment.rec_name,
})
self.result.shipment = shipment
self.result.box = box
self.result.box = box_assigned
return 'result'
def default_result(self, fields):

View File

@ -7,4 +7,6 @@ copyright notices and license terms. -->
<field name="box"/>
<field name="user"/>
<field name="state"/>
<button name="done" string="Done" tree_invisible="1"/>
<button name="waiting" string="Waiting" tree_invisible="1"/>
</tree>

View File

@ -7,6 +7,10 @@ copyright notices and license terms. -->
<field name="name"/>
<label name="warehouse"/>
<field name="warehouse"/>
<label name="location"/>
<field name="location"/>
<label name="type"/>
<field name="type"/>
<label name="sequence"/>
<field name="sequence"/>
<label name="active"/>

View File

@ -5,6 +5,8 @@ copyright notices and license terms. -->
<tree string="Picking Boxes Out">
<field name="name"/>
<field name="warehouse"/>
<field name="location"/>
<field name="type"/>
<field name="sequence"/>
<field name="active"/>
</tree>

View File

@ -4,4 +4,6 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig
<form string="Picking Box Shipment Out Start">
<label name="shipment"/>
<field name="shipment"/>
<label name="box"/>
<field name="box"/>
</form>