mirror of
https://github.com/NaN-tic/trytond-stock_distribution_in.git
synced 2023-12-14 06:03:03 +01:00
parent
787a332965
commit
fd3fdb52e5
|
@ -92,6 +92,9 @@ class Distribution(Workflow, ModelSQL, ModelView):
|
|||
cls._transitions |= set((
|
||||
('draft', 'done'),
|
||||
))
|
||||
'not_assigned_quantities': ('Distribution "%(distribution)s" cannot be done '
|
||||
'because there is not enough stock. Please review the '
|
||||
'following quantites: %(quantities)s'),
|
||||
|
||||
@classmethod
|
||||
def validate(cls, distributions):
|
||||
|
@ -319,6 +322,7 @@ class Distribution(Workflow, ModelSQL, ModelView):
|
|||
productions = Production.browse(inputs.keys())
|
||||
Production.wait(productions)
|
||||
to_assign = []
|
||||
move_quantities = {}
|
||||
for production in productions:
|
||||
for input_ in production.inputs:
|
||||
if input_.state != 'draft':
|
||||
|
@ -337,6 +341,7 @@ class Distribution(Workflow, ModelSQL, ModelView):
|
|||
production.warehouse.input_location.id)
|
||||
move.save()
|
||||
to_assign.append(move)
|
||||
move_quantities[move.id] = move.quantity
|
||||
inputs[production.id][input_.product.id] -= quantity
|
||||
if to_assign:
|
||||
# By assigning move by move instead of using production's
|
||||
|
@ -349,7 +354,25 @@ class Distribution(Workflow, ModelSQL, ModelView):
|
|||
# assign_try on production A first, would probably mean that
|
||||
# production A also assigns product 2, which is wrong.
|
||||
Move.assign_try(to_assign)
|
||||
to_do = []
|
||||
not_assigned_quantities = ''
|
||||
for move in to_assign:
|
||||
if move.quantity == move_quantities[move.id]:
|
||||
to_do.append(move)
|
||||
else:
|
||||
not_assigned_quantities = ('\n' +
|
||||
move.from_location.rec_name + ': ' +
|
||||
move.product.rec_name + ': ' + str(
|
||||
move_quantities[move.id]))
|
||||
if not_assigned_quantities:
|
||||
cls.raise_user_error('not_assigned_quantities', {
|
||||
'distribution': distribution.rec_name,
|
||||
'quantities': not_assigned_quantities,
|
||||
})
|
||||
else:
|
||||
Move.do(to_do)
|
||||
|
||||
to_do = []
|
||||
# Once individual moves have been assigned, we can safely run
|
||||
# assign_try
|
||||
for production in productions:
|
||||
|
@ -358,6 +381,10 @@ class Distribution(Workflow, ModelSQL, ModelView):
|
|||
# productions are assigned
|
||||
# TODO: That should probably be fixed in core
|
||||
Production.assign_try([production])
|
||||
for input_ in production.inputs:
|
||||
if input_.state == 'assigned':
|
||||
to_do.append(input_)
|
||||
Move.do(to_do)
|
||||
|
||||
Purchase.process(Purchase.browse(purchase_ids))
|
||||
|
||||
|
|
|
@ -18,6 +18,14 @@ msgstr ""
|
|||
"La linia de repartiment \"%s\" ha de tenir el camp \"Producció\" o "
|
||||
"\"Ubicació\" buits."
|
||||
|
||||
msgctxt "error:stock.distribution.in:"
|
||||
msgid ""
|
||||
"Distribution \"%(distribution)s\" cannot be done because there is not enough"
|
||||
" stock. Please review the following quantites: %(quantities)s"
|
||||
msgstr ""
|
||||
"El repartiment \"%(distribution)s\" no es pot realitzar perquè no hi ha prou"
|
||||
" estoc. Si us plau, revisi les següents quantitats: %(quantities)s"
|
||||
|
||||
msgctxt "error:stock.distribution.in:"
|
||||
msgid "Distribution \"%s\" cannot be deleted because it is in \"Done\" state."
|
||||
msgstr "El repartiment \"%s\" no es pot eliminar perquè està en estat \"Finalitzat\"."
|
||||
|
|
|
@ -18,6 +18,15 @@ msgstr ""
|
|||
"La línea de reparto \"%s\" debe tener el campo \"Producción\" o "
|
||||
"\"Ubicación\" vacío."
|
||||
|
||||
msgctxt "error:stock.distribution.in:"
|
||||
msgid ""
|
||||
"Distribution \"%(distribution)s\" cannot be done because there is not enough"
|
||||
" stock. Please review the following quantites: %(quantities)s"
|
||||
msgstr ""
|
||||
"El reparto \"%(distribution)s\" no se puede realizar porque no hay "
|
||||
"suficiente stock. Por favor, revise las siguientes cantidades: "
|
||||
"%(quantities)s"
|
||||
|
||||
msgctxt "error:stock.distribution.in:"
|
||||
msgid "Distribution \"%s\" cannot be deleted because it is in \"Done\" state."
|
||||
msgstr "El reparto \"%s\" no se puede eliminar porqué está en estado \"Finalizado\"."
|
||||
|
|
|
@ -68,6 +68,7 @@ Get stock locations::
|
|||
>>> output_loc, = Location.find([('code', '=', 'OUT')])
|
||||
>>> storage_loc, = Location.find([('code', '=', 'STO')])
|
||||
>>> production_loc, = Location.find([('code', '=', 'PROD')])
|
||||
>>> input_loc, = Location.find([('code', '=', 'IN')])
|
||||
|
||||
Create account category::
|
||||
|
||||
|
@ -209,11 +210,30 @@ distribution lines::
|
|||
>>> incoming_move.distribution_lines
|
||||
[]
|
||||
>>> incoming_move = StockMove(incoming_move.id)
|
||||
>>> distribution.moves.append(incoming_move)
|
||||
>>> distribution.click('distribute')
|
||||
|
||||
Ensure that a distribution cannot be done if there is enough stock::
|
||||
|
||||
>>> move = StockMove()
|
||||
>>> move.product = product
|
||||
>>> move.from_location = input_loc
|
||||
>>> move.to_location = storage_loc
|
||||
>>> move.quantity = 5
|
||||
>>> move.click('do')
|
||||
>>> distribution.click('do') # doctest: +IGNORE_EXCEPTION_DETAIL
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
UserError: ...
|
||||
>>> move = StockMove()
|
||||
>>> move.product = product
|
||||
>>> move.from_location = storage_loc
|
||||
>>> move.to_location = input_loc
|
||||
>>> move.quantity = 5
|
||||
>>> move.click('do')
|
||||
|
||||
Check that when the distribution is done, everything is correct::
|
||||
|
||||
>>> distribution.moves.append(incoming_move)
|
||||
>>> distribution.click('distribute')
|
||||
>>> distribution.click('do')
|
||||
>>> distribution.state
|
||||
'done'
|
||||
|
@ -251,6 +271,10 @@ Check both productions have been reserved::
|
|||
>>> production1.reload()
|
||||
>>> production1.state
|
||||
'assigned'
|
||||
>>> production1.inputs[0].state
|
||||
u'done'
|
||||
>>> production2.reload()
|
||||
>>> production2.state
|
||||
'assigned'
|
||||
>>> production2.inputs[0].state
|
||||
u'done'
|
||||
|
|
Loading…
Reference in a new issue