How to reload m2m function field when on_change from o2m?

Example models:

1.- model with “m2o” field and “m2m” function field.

class ModelDemo(ModelSQL, ModelView):
    "Demo"
    __name__ = 'model.demo'
    lines = fields.One2Many('model.demo.line', 'demo',
        "Lines", readonly=True)
    summary = fields.Function(fields.Many2Many('model.demo.by.date',
        None, None, "Summary"), 'on_change_with_summary')

Example “m2m” model:

class ModelDemoByDate(ModelView):
    "Demo by Date"
    __name__ = 'model.demo.by.date'
    pdate = fields.Date("Date", readonly=True)
    ptime = fields.TimeDelta("Time", readonly=True)

I try on_change_with_summary() to reload values at ModelDemoByDate. In case I change a record from o2m field, create new records at “m2m” (duplicate records; no remove existing records at m2m function field)

It will be great to see the on_change_with_summary code.

But if you are doing something line:

lines = []
# Code to compute lines
self.lines = lines

It is expected that the client will add the new lines and mark the previous one as to deleted.
This is the right behaviour as the lines won’t be deleted until the user saves the record, so we show them the right values. Same happens on production module, when you use a bom an update the quantities the previous inputs and outputs are marked as to delete and the new ones are added.

Once the record is saved just the new lines are added.