Set the default accounts in the financial configuration with Proteus

Hi everybody,

I am currently working on a testing setup for a chart of accounts. I am stuck at a point with proteus, where I request some help. I try to set the default accounts in the financial configuration with Proteus, but keep getting the following error, but in every object involved the missing field is set (from my point of view).

>>>Config = Model.get(‘account.configuration’)
>>>Defaultaccount = Model.get(‘account.configuration.default_account’)
>>>Account = Model.get(‘account.account’)
>>>config, = Config.find()
>>>recdef = Defaultaccount()
>>>recdef.company = get_company()
>>>account = Account.find([(‘code’, ‘=’, ‘1200’)], limit=1)[0]
>>>recdef.default_account_receivable = account
>>>account.company
proteus.Model.get(‘company.company’)(1)
>>>get_cfg().context[‘company’]
1
>>>config.default_account_receivable = recdef
>>>config.save()


Traceback (most recent call last):
  File "/Users/jakobfischer/Entwicklung/gf_verification_database/populate_veridb.py", line 550, in start_console
    from IPython import embed  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'IPython'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/jakobfischer/Entwicklung/tryton74/lib/python3.13/site-packages/proteus/__init__.py", line 102, in newfunc
    return self.func(owner, [instance], *args, **kwargs)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jakobfischer/Entwicklung/tryton74/lib/python3.13/site-packages/proteus/__init__.py", line 866, in save
    proxy.write(*values)
    ~~~~~~~~~~~^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.13/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/xmlrpc/client.py", line 1096, in __call__
    return self.__send(self.__name, args)
           ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.13/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/xmlrpc/client.py", line 1435, in __request
    response = self.__transport.request(
        self.__host,
    ...<2 lines>...
        verbose=self.__verbose
        )
  File "/opt/homebrew/Cellar/python@3.13/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/xmlrpc/client.py", line 1140, in request
    return self.single_request(host, handler, request_body, verbose)
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.13/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/xmlrpc/client.py", line 1156, in single_request
    return self.parse_response(resp)
           ~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/opt/homebrew/Cellar/python@3.13/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/xmlrpc/client.py", line 1325, in parse_response
    return u.close()
           ~~~~~~~^^
  File "/opt/homebrew/Cellar/python@3.13/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/xmlrpc/client.py", line 642, in close
    raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault 1: 'A value is required for field "Company" in "Account". - '>

I can configure this very account by hand in the client, but get the error when using Proteus. As you can see, the company of each object is set, but I still get the error.

Thanks for your help Jakob

account.configuration.default_account is not supposed to be accessed directly but through the account.configuration instance.

Thanks @ced for you help. I managed to solve the “Missing company”. It was due to a messed up context.

But when I access the model throught the account.configuration I get the error,

Config = Model.get(‘account.configuration’)
Account = Model.get(‘account.account’)
config, = Config().find()
config
proteus.Model.get(‘account.configuration’)(1)
config.default_account_receivable = Account.find([(‘code’, ‘=’, ‘1200’)], limit=1)[0]
config.save()

xmlrpc.client.Fault: <Fault 1: 'You are trying to read records “1” of “Account Configuration Default Account” that don't exist. - '>

Via Proteus, it seems the underlying Mulitvalue is not created when the Many2One is linked and the config is saved.
Do I have to trigger the creation somehow “by hand”?

Full Stack:

>>> Config = Model.get('account.configuration')
>>> Account = Model.get('account.account')
>>> config, = Config().find()
>>> config
proteus.Model.get('account.configuration')(1)
>>> config.default_account_receivable = Account.find([('code', '=', '1200')], limit=1)[0]
>>> config.save()
Traceback (most recent call last):
  File "/Users/jakobfischer/Entwicklung/gf_verification_database/populate_veridb.py", line 573, in start_console
    from IPython import embed  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'IPython'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/jakobfischer/Entwicklung/tryton74/lib/python3.13/site-packages/proteus/__init__.py", line 102, in newfunc
    return self.func(owner, [instance], *args, **kwargs)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jakobfischer/Entwicklung/tryton74/lib/python3.13/site-packages/proteus/__init__.py", line 866, in save
    proxy.write(*values)
    ~~~~~~~~~~~^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.13/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/xmlrpc/client.py", line 1096, in __call__
    return self.__send(self.__name, args)
           ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.13/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/xmlrpc/client.py", line 1435, in __request
    response = self.__transport.request(
        self.__host,
    ...<2 lines>...
        verbose=self.__verbose
        )
  File "/opt/homebrew/Cellar/python@3.13/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/xmlrpc/client.py", line 1140, in request
    return self.single_request(host, handler, request_body, verbose)
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.13/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/xmlrpc/client.py", line 1156, in single_request
    return self.parse_response(resp)
           ~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/opt/homebrew/Cellar/python@3.13/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/xmlrpc/client.py", line 1325, in parse_response
    return u.close()
           ~~~~~~~^^
  File "/opt/homebrew/Cellar/python@3.13/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/xmlrpc/client.py", line 642, in close
    raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault 1: 'You are trying to read records "1" of "Account Configuration Default Account" that don\'t exist. - '>
>>>

Thanks for your help

It will be easier to understand the problem with the traceback from the server log (with debug level).

it looks like you re-define the config variable from proteus, if you call proteus like this:

config = config.set_trytond('…')

S.a. Tryton Scripting Client — Library to access Tryton server as a client

1 Like

The cause of the error is the name of the variable config. But actually I did not redefine config, since I called it prconfig.
It seems like somewhere in the code the string ‘config’ is used, maybe when calling the config dynamically per getattr()…

Takeaway for other readers:

  • do not mess up your context :slight_smile:
  • do not useconfig, or other trytonic terms as local variable.

Thanks for your help.

but even when you use prconfig, you redefine the imported config:

from proteus import config, …

prconfig = config.set_trytond('…')

…when you later call:

Config = Model.get(‘account.configuration’)
config, = Config().find()

This way you can import in another namespace:

from proteus import config as prconfig

prconfig = prconfig.set_trytond('…')
1 Like

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