Error in rst scenario while clicking button

Generate Bill::

    >>> Bill = Model.get('account.bill.details')
    >>> bill = Bill()
    >>> bill = bill.find([('account_number', '=', '1234567899'),])
    >>> bill.click('submit')
File "/home/vam/workspace/tryton/tryton50/lib/python3.8/site-packages/trytond_pay_automation-5.0.0-py3.8.egg/trytond/modules/pay_automation/tests/pay.rst", line 75, in pay.rst
Failed example:
    bill.click('submit')
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python3.8/doctest.py", line 1336, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest pay.rst[33]>", line 1, in <module>
        bill.click('submit')
    AttributeError: 'list' object has no attribute 'click'

This is because the result of .find() call is a list of record.
So if you know that there will be only one result, you can expand the result like:

>>> bill, = Bill.find([('account_number', '=', '1234567899')])

be careful about the ,

But if you want to click on all the records in the list, then you must use the classmethod like:

>>> bills = Bill.find([('account_number', '=', '1234567899')])
>>> Bill.click('submit', bills)

Another remarks is that you must not instantiate the model to use the classmethod.

1 Like
Bill.click('submit' , bill)
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python3.8/doctest.py", line 1336, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest pay.rst[31]>", line 1, in <module>
        Bill.click('submit' , bill)
      File "/home/vam/workspace/tryton50/lib/python3.8/site-packages/proteus/__init__.py", line 104, in newfunc
        return self.func(owner, *args, **kwargs)
      File "/home/vam/workspace/tryton50/lib/python3.8/site-packages/proteus/__init__.py", line 897, in click
        proxy = records[0]._proxy
    AttributeError: 'str' object has no attribute '_proxy'

Now i’m getting this.

In my example I explained that you must pass a list of record if you use Bill.click.

1 Like