Proteus assert record._group is None in m2m field

When try in scenario RST to add a field in m2m with add_remove, I get the error:

Failed example:
    statement_line.counterpart_lines.append(line2)
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python3.7/doctest.py", line 1329, in __run
        compileflags, 1), test.globs)
      File "<doctest scenario_account_bank_statement_counterpart.rst[67]>", line 1, in <module>
        statement_line.counterpart_lines.append(line2)
      File "/home/raimon/projectes/nandev/xxxxx/proteus/proteus/__init__.py", line 578, in append
        self.__check([record])
      File "/home/raimon/projectes/nandev/xxxxx/proteus/proteus/__init__.py", line 564, in __check
        assert record._group is None
    AssertionError

I try to reload the record and continue the assert error [1].

  1. Field in trytond:
    counterpart_lines = fields.One2Many('account.move.line',
        'bank_statement_line_counterpart', 'Counterpart',
        states=POSTED_STATES, domain=[
            ('move.company', '=', Eval('company')),
            ('account.reconcile', '=', True),
            ('move_state', '=', 'posted'),
            ],
        add_remove=[
            ('reconciliation', '=', None),
            ('bank_statement_line_counterpart', '=', None),
            ('move_state', '=', 'posted'),
            ('account.reconcile', '=', True),
            ],
        depends=['company'])

and:

    bank_statement_line_counterpart = fields.Many2One(
        'account.bank.statement.line', 'Bank Statement Line Counterpart',
        readonly=True)
  1. Scenario RST:
    >>> statement_line, = statement.lines
    >>> statement_line.reload()
    >>> line2.reload()
    >>> statement_line.counterpart_lines.append(line2)
    >>> statement_line.save()
    >>> statement_line.click('post')

3- Debug record:

(Pdb) line2.move.company
proteus.Model.get('company.company')(1)
(Pdb) line2.account.reconcile
1
(Pdb) line2.move_state
'posted'
(Pdb) line2.reconciliation
(Pdb) line2.bank_statement_line_counterpart

4- Relate “statement line” in “account.move.line” record:

I can’t do:

line2.bank_statement_line_counterpart = statement_line
line2.save()

… because “bank_statement_line_counterpart” field has readonly attribute.

[1] Building a ProductCategory

1 Like

You should not reload the line but rebrowse it. Reload keeps the link with the parent record.

The following code should fix it.

>>> Line = Model.get('account.move.line')
>>> statement_line.counterpart_lines.append(Line(line2.id))

Note that I used Line(line_id) to rebrowse it.

Hope it helps!

2 Likes

Successfully. Thanks!