Issue 10382

Title
Decimals of quantity move exceed the total digits when split move
Priority
bug
Status
need-eg
Nosy list
ced, resteve
Assigned to
Keywords

Created on 2021-05-03.19:14:28 by resteve, last changed 7 days ago by ced.

Messages

Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2021-05-03.19:34:34

The traceback is tainted with non standard module and the file lines clearly are not corresponding to last version.
Also I'm pretty sure it is a duplicate of issue10227.

Author: [hidden] (resteve)
Date: 2021-05-03.19:14:28

when try to split a move the number of decimals exceeds the total digits the quantity field [1].

>>> quantity = 317.52
>>> remainder = 589.68
>>> remainder -= quantity
>>> remainder
272.15999999999997

I think we need to round according the unit_digits from the stock.move, in out scenario, is 3.

>>> remainder = round(remainder, 3)
>>> remainder
272.16

[1] https://hg.tryton.org/modules/stock_split/file/tip/stock.py#l50

The traceback:

Traceback (most recent call last):
  File "/tryton/trytond/trytond/protocols/dispatcher.py", line 186, in _dispatch
    result = rpc.result(meth(*c_args, **c_kwargs))
  File "/tryton/trytond/trytond/wizard/wizard.py", line 290, in execute
    return wizard._execute(state_name)
  File "/tryton/trytond/trytond/wizard/wizard.py", line 321, in _execute
    result = self._execute(transition())
  File "/tryton/trytond/trytond/modules/stock_split/stock.py", line 128, in transition_split
    move.split(self.start.quantity, self.start.uom, self.start.count)
  File "/tryton/trytond/trytond/modules/stock_split/stock.py", line 73, in split
    'uom': uom.id,
  File "/tryton/trytond/trytond/modules/stock_scanner/stock.py", line 94, in copy
    return super(Move, cls).copy(moves, default=default)
  File "/tryton/trytond/trytond/modules/account_invoice_stock/stock.py", line 37, in copy
    return super(StockMove, cls).copy(moves, default=default)
  File "/tryton/trytond/trytond/modules/product_cost_fifo/move.py", line 158, in copy
    return super().copy(moves, default=default)
  File "/tryton/trytond/trytond/model/workflow.py", line 58, in copy
    return super().copy(records, default=default)
  File "/tryton/trytond/trytond/model/modelstorage.py", line 409, in copy
    new_records = cls.create(to_create)
  File "/tryton/trytond/trytond/modules/stock/move.py", line 727, in create
    moves = super(Move, cls).create(vlist)
  File "/tryton/trytond/trytond/model/modelsql.py", line 159, in wrapper
    return func(cls, *args, **kwargs)
  File "/tryton/trytond/trytond/model/modelsql.py", line 677, in create
    cls._validate(sub_records)
  File "/tryton/trytond/trytond/model/modelstorage.py", line 75, in wrapper
    return func(*args, **kwargs)
  File "/tryton/trytond/trytond/model/modelstorage.py", line 1257, in _validate
    field_name)
  File "/tryton/trytond/trytond/model/modelstorage.py", line 1248, in digits_test
    raise_error(value)
  File "/tryton/trytond/trytond/model/modelstorage.py", line 1237, in raise_error
    **error_args))
trytond.model.modelstorage.DigitsValidationError: El nombre de dígits del valor "272.15999999999997" del camp "Quantitat" de "Moviment d'existències" excedeix el seu límit de "3". - 
History
Date User Action Args
2021-05-03 19:34:34cedsetmessages: + msg67344
nosy: + ced
status: chatting -> need-eg
2021-05-03 19:14:28restevecreate