From d04b101539046907f28647f7ac794ae4ebe977cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=C3=89vrard?= Date: Sun, 16 Mar 2014 21:01:02 +0100 Subject: [PATCH] Add index to one2many's on_change add review2061003 issue3539 --- tryton/gui/window/view_form/model/field.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tryton/gui/window/view_form/model/field.py b/tryton/gui/window/view_form/model/field.py index e5729afede..d5ed2d6d4f 100644 --- a/tryton/gui/window/view_form/model/field.py +++ b/tryton/gui/window/view_form/model/field.py @@ -1,6 +1,7 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. import os +from itertools import chain import tempfile import locale from tryton.common import datetime_strftime, \ @@ -669,8 +670,9 @@ class O2MField(CharField): if value and (value.get('add') or value.get('update')): context = self.context_get(record) fields = record.value[self.name].fields - field_names = set(f for v in ( - value.get('add', []) + value.get('update', [])) + values = chain(value.get('update', []), + (d for _, d in value.get('add', []))) + field_names = set(f for v in values for f in v if f not in fields and f != 'id') if field_names: try: @@ -696,9 +698,9 @@ class O2MField(CharField): if value and (value.get('add') or value.get('update', [])): record.value[self.name].add_fields(fields, signal=False) - for vals in value.get('add', []): + for index, vals in value.get('add', []): new_record = record.value[self.name].new(default=False) - record.value[self.name].add(new_record) + record.value[self.name].add(new_record, index) new_record.set_on_change(vals) for vals in value.get('update', []):