Why does test_missing_parent fail here?

Hi,
I’m trying to port a module from 4.8 to 7.0. When running the test-suite via tox, one of the classes fails with

  File "/home/hartmut/devel/tryton/community/modules/bank_fints/.tox/py-sqlite/lib/python3.10/site-packages/trytond/tests/test_tryton.py", line 491, in test_missing_parent
    self.assertIn('_parent_%s' % depend, parent_depends,
AssertionError: '_parent_account' not found in {'account'} : Missing "_parent_account" in "bank.account.number"."fints_company"."on_change_with"

The code of that class is quite simple:

class BankAccountNumber2(ModelSQL, ModelView):
    'Bank Account Number'
    __name__ = 'bank.account.number'

    fints_company = fields.Function(fields.One2Many('party.party', None,
            'Owner', states={'invisible': True}), 'on_change_with_fints_company')

    @fields.depends('account')
    def on_change_with_fints_company(self, name=None):
        if self.account is None:
            return []
        return [x.id for x in self.account.owners]

Model bank.account.number is defined in official trytond_bank and contains the account field:

        if self.account is None:
            return []
        return [x.id for x in self.account.owners]

bank is declared as depends in tryton.cfg and the module is installed in the virtual environment created by tox.

What piece I’m missing?

Probably try this as depends:

@fields.depends('account', '_parent_account.owners')

Thanks this did the trick. Anyhow I’d like to understand what this does and where I can find this in the documentation. Any hits?

Answering myself: The answer is hidden in Fields — Tryton server

PYSON statement or Field.depends of target records can access value of the parent record fields by prepending _parent_ to the opposite field name and followed by the dotted notation.

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