Can not recumpute cost price in case stock move has not currency
Example stock move:
>>> move = Move(101551)
>>> move.cost_price_required
True
>>> move.unit_price_required
False
>>> move.cost_price
Decimal('0.6300')
>>> move.currency
>>> move.from_location.type
'storage'
>>> move.to_location.type
'production'
When try to recompute cost price, the traceback:
Traceback (most recent call last):
File "/tryton/trytond/trytond/worker.py", line 144, in run_task
task.run()
File "/tryton/trytond/trytond/ir/queue_.py", line 177, in run
getattr(Model, self.data['method'])(
File "/tryton/trytond/trytond/modules/stock/product.py", line 333, in recompute_cost_price
cost = getattr(
^^^^^^^^
File "/tryton/trytond/trytond/modules/stock/product.py", line 494, in recompute_cost_price_average
unit_price = move.get_cost_price(product_cost_price=cost_price)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tryton/trytond/trytond/modules/sale/stock.py", line 191, in get_cost_price
return super().get_cost_price(product_cost_price=product_cost_price)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tryton/trytond/trytond/modules/stock_lot_cost/stock.py", line 112, in get_cost_price
cost_price = super().get_cost_price(product_cost_price=None)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tryton/trytond/trytond/modules/stock/move.py", line 759, in get_cost_price
return self.unit_price_company
^^^^^^^^^^^^^^^^^^^^^^^
File "/tryton/trytond/trytond/model/fields/function.py", line 160, in __get__
return super().__get__(inst, cls)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tryton/trytond/trytond/model/fields/field.py", line 391, in __get__
return inst.__getattr__(self.name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tryton/trytond/trytond/model/modelstorage.py", line 1781, in __getattr__
read_data = self.read(list(index.keys()), list(ffields.keys()))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tryton/trytond/trytond/model/modelsql.py", line 1153, in read
getter_results = field.get(
^^^^^^^^^^
File "/tryton/trytond/trytond/model/fields/function.py", line 27, in wrapper
return func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tryton/trytond/trytond/transaction.py", line 50, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/tryton/trytond/trytond/model/fields/function.py", line 136, in get
return dict((name, call(name)) for name in names)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tryton/trytond/trytond/model/fields/function.py", line 136, in <genexpr>
return dict((name, call(name)) for name in names)
^^^^^^^^^^
File "/tryton/trytond/trytond/model/fields/function.py", line 127, in call
return on_change_with_result(self, method(records, name))
^^^^^^^^^^^^^^^^^^^^^
File "/tryton/trytond/trytond/modules/stock/move.py", line 444, in get_unit_price_company
unit_price = Currency.compute(
^^^^^^^^^^^^^^^^^
File "/tryton/trytond/trytond/modules/currency/currency.py", line 198, in compute
from_currency = cls(int(from_currency))
^^^^^^^^^^^^^^^^^^
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'
See that stock move, currency is null.