Child's (One2Many) fields getting unintended modifications

Hi guys,
I have a strange behavior where some fields get random unintended modifications (copying values from sibling records in an One2Many relationship. A few details of the models…

class Loan(Workflow, ModelSQL, ModelView):
    """Loan"""
    __name__ = "innoproc.loan"
    _history = True
    number = fields.Char('Number', size=None, readonly=True, select=True)
...
    conditions = fields.One2Many('innoproc.loan_condition', 'loan', 'Conditions', loading='eager', states={
        'readonly': ~In(Eval('state', 'draft'), ['approved', 'conditions_loaded', 'conditions_doc_identified',
                                        'conditions_submission', 'title_requested', 'insurance_requested',
                                        'initial_submission', 'appraisal_requested'])

On the other hand the class Conditions…

class LoanCondition(ModelSQL, ModelView, LoanDemandMixin):
    """Loan Condition"""
    __name__ = 'innoproc.loan_condition'
    _history = True

    name = fields.Char('Name', depends=['locked'], states={
        'readonly': Eval('locked', False)
    })
    number = fields.Integer('Number', depends=['locked'], states={
        'readonly': Eval('locked', False)
    })
    detail = fields.Text('Detail', depends=['locked'], states={
        'readonly': Eval('locked', False)
    })
    documents = fields.One2Many('innoproc.condition_document', 'loan_condition', 'Documents', depends=['locked'],
        states={'readonly': Eval('locked', False)
    })

My problem is that sometimes “primitive” fields like name, number, and detail in some instances of LoanCondition get modified assuming values of other Condition instance (but I’ve never seen this behavior in One2Many fields like LoanCondition.documents in this case).

At some point, I thought that the problem was some kind of desynchronization between the backend and frontend (I’m using SAO), then I changed the conditions field to eager loading, but the problem remains.

My user interface is Loan-centric (meaning I do not have a Conditions window since all conditions are created/modified from the Loan window).

I suspect that the problem is somehow related to the concept of “active record” because I have the idea that the problem appears when I’m moving between the different Conditions in the loan (like if the frontend has an active record (Condition) different from the one that the backend “thinks” is the active one, triggering the change (but this is a theory only).

Have you ever faced a similar problem? Any clues on how to tackle this?

Hi,

If conditions are not displayed / modified by the user, what mechanism is used to actually create / modify them ?

You mention a notion of active record, but I do not see any reference to it in the code you posted.

Thank you, Jean!
Yes, conditions are created and modified by the user using the Loan form view (conditions are one of the fields on this model). The active record, is an internal construct in Tryton (part of the rpc protocol in my understanding), so no explicit reference to it exist in my models.

Check the JS console, there is probably an error.

I noted that I forgot to include the parent field (loan) in the LoanCondition view definition (XML view files). After the change (including the missing field), the event has not occurred again. I’m not sure if this is enough to explain the observed behaviour.

Probably as it is not in the view, it is not read but the One2Many on the client must set it to ensure the link. So this should trigger a change.
I think we should ensure that the parent field is always in the One2Many view.

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