How to use proteus with stock.move

Hello i am trying to use proteus to create stock_move, but i may do some things wrong

stmove=Model.get('stock.move')
the_move=stmove();
the_move.product=product;
p_date=date(2025,9,11)
the_move.planned_date=p_date
the_move.effective_date=p_date
Mfrom=Model.get('stock.location')
mfrom,=Mfrom.find([('code', '=', 'SUP')])
the_move.from_location=mfrom
tfrom,=Mfrom.find([('code', '=', 'STK')])
the_move.to_location=tfrom
the_move.quantity=20
getcontext().prec = 4
the_move.cost_price=Decimal(1.34)#the same with Decimal('1.34')
the_move.save() 

it says

File “/usr/lib/python3/dist-packages/trytond/model/modelstorage.py”, line 1326, in _validate
else:

File “/usr/lib/python3/dist-packages/trytond/model/modelstorage.py”, line 1310, in digits_test
if isinstance(value, Decimal):
^^^^^^^^^^^^^^^^^^^
decimal.InvalidOperation: [<class ‘decimal.InvalidOperation’>]

i do not know how to debug il i write in digits_test

print(value, digits, field_name)

nothing appears in python3 interpreter

i read Create initial stock moves with proteus on a remote server

but did not understand how to succed or how to debug

move.cost_price is a readonly field.
Maybe you should try to define move.unit_price and move.currency…

thanks a lot, but same punition

>>> print(the_move.unit_price)
12.23
>>> print(the_move.currency)
currency.currency,1
>>> the_move.save()

  File "/usr/lib/python3/dist-packages/trytond/model/modelstorage.py", line 1326, in _validate
    else:
         
  File "/usr/lib/python3/dist-packages/trytond/model/modelstorage.py", line 1310, in digits_test
    if isinstance(value, Decimal):
           ^^^^^^^^^^^^^^^^^^^
decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]

i’ll test with a new “test” with no cost_price.

is there a way to do the change cost_price with proteus, where to look for ?

cost_price should be defined on your product

Give the full proteus script to understand the problem.

And the traceback makes no sense. It looks like the line number and the code shown do not match the actual byte-code executed.

i just copy what it spits

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/proteus/__init__.py", line 102, in newfunc
    return self.func(owner, [instance], *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/proteus/__init__.py", line 847, in save
    ids = proxy.create(values, context)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/proteus/config.py", line 202, in __call__
    result = rpc.result(meth(*args, **kwargs))
                        ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/trytond/modules/stock/move.py", line 815, in create
    moves = super(Move, cls).create(vlist)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/trytond/model/modelsql.py", line 159, in wrapper
    return func(cls, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/trytond/model/modelsql.py", line 679, in create
    cls._validate(sub_records)
  File "/usr/lib/python3/dist-packages/trytond/model/modelstorage.py", line 79, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/trytond/model/modelstorage.py", line 1328, in _validate
    digits_test(getattr(record, field_name),
  File "/usr/lib/python3/dist-packages/trytond/model/modelstorage.py", line 1312, in digits_test
    if value.quantize(exp) != value:
       ^^^^^^^^^^^^^^^^^^^
decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]

i do not understand what is happening

when i do debug

def digits_test(value, digits, field_name):
    print(value, digits, field_name) # My debug line
    def raise_error(value):
         error_args = cls.__names__(field_name)
         error_args['digits'] = digits[1]
          error_args['value'] = repr(value)
           raise DigitsValidationError(
                 gettext('ir.msg_digits_validation_record',
                        **error_args))
    if (value is None
         or not digits
         or any(d is None for d in digits)):
         return
    if isinstance(value, Decimal):
         exp = Decimal('.'.join(['0', '0' * digits[1]]))
         print(exp,value,digits) #my 2nd debug linze
         if value.quantize(exp) != value:
               raise_error(value)

i get

1st line debug

None (16, 4) cost_price
20.0 [16, 0] quantity
12 (16, 4) unit_price

2nd line debug

0.0000 12 (16, 4)

the full script:

#!/usr/bin/env python3
import warnings ; warnings.warn = lambda *args,**kwargs: None
from proteus import config, Model, Wizard, Report
from decimal import *
from datetime import date, datetime
import argparse
my_config = config.set_trytond('postgresql:///tryton',config_file='/etc/tryton/trytond.conf')
stmove=Model.get('stock.move')
the_move=stmove();
Company = Model.get('company.company')
company, = Company.find([('id','=','2')])
the_move.company=company
Product = Model.get('product.product')
product, = Product.find([('code', '=', '12ERT56')])
the_move.product=product;
Location=Model.get('stock.location')
Mfrom,=Location.find([('code', '=', 'SUP')])
the_move.from_location=Mfrom
Mto,=Location.find([('code', '=', 'STK')])
the_move.to_location=Mto
uom=Model.get('product.uom')
Puom,=uom.find([('symbol', '=', 'u')])
the_move.uom=Puom
p_date=date(2025,9,23)
the_move.planned_date=p_date
the_move.effective_date=p_date
the_move.quantity=20
the_move.internal_quantity=20
getcontext().prec = 4
the_move.unit_price=Decimal('12')
currency=Model.get('currency.currency')
cu,=currency.find([('code','=','EU')])
the_move.save()

First you do not seem to be up to date as you are missing the fix of Sepa payments rejected because of exagerated decimal values (#12587) · Issues · Tryton / Tryton · GitLab

As explained in decimal — Decimal fixed-point and floating-point arithmetic — Python 3.13.7 documentation

Unlike other operations, if the length of the coefficient after the quantize operation would be greater than precision, then an InvalidOperation is signaled.

Any way I do not see any reason to set a global precision so low on decimal. Tryton is expected to run with the default decimal context.

i run with the version given by my distro.

and proteus is like another client and the operation works well in SAO.

event with no getcontext().prec

the situation is the same. i am trying to understand what is happening.

Then use an up to date distribution.

sao does not set the decimal context

I doubt.

you have the right to doubt in your reality, but in my reality of work it is the case.

i kow why that situation happens and i know how to by pass but there might be some problems elsewhere.

if i do

val=value.quantize(Decimal(“0.000”))
with 12.123456
>>> decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]

val=value.quantize(Decimal(“0.00”))
with 12.123456

val => 12.12

this happens because we decide to have 4 decimals because we have tva 5.5 and having a rounded TTC price with 1.055 is some time complicated

no the subjet was not resolve and i doubt that someone wanting to use proteus with move will face the same problem. in that script Create initial stock moves with proteus on a remote server the price was not used. and with the price it would not work.

the workaround is to use

getcontext().prec = 12

and suddenly it works. doubt or not

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.