line: fix write() - dont rewrite values if not given
This commit is contained in:
parent
9d33086ff2
commit
f105e8bd6c
1 changed files with 11 additions and 3 deletions
14
line.py
14
line.py
|
@ -815,10 +815,10 @@ class Line(SecondCurrencyMixin, Workflow, ModelSQL, ModelView):
|
|||
""" compute debit/credit from amount
|
||||
"""
|
||||
if isinstance(values, dict):
|
||||
type_ = values.get('bookingtype', None)
|
||||
type_ = values.get('bookingtype', getattr(line, 'bookingtype', None))
|
||||
amount = values.get('amount', None)
|
||||
else :
|
||||
type_ = getattr(values, 'bookingtype', None)
|
||||
type_ = getattr(values, 'bookingtype', getattr(line, 'bookingtype', None))
|
||||
amount = getattr(values, 'amount', None)
|
||||
|
||||
result = {}
|
||||
|
@ -1040,12 +1040,20 @@ class Line(SecondCurrencyMixin, Workflow, ModelSQL, ModelView):
|
|||
values2 = {}
|
||||
values2.update(values)
|
||||
values2.update(cls.clear_by_bookingtype(values, line))
|
||||
|
||||
# select required fields in case on 'bookingtype'
|
||||
updt_fields = []
|
||||
updt_fields.extend(values.keys())
|
||||
if 'bookingtype' in values.keys():
|
||||
updt_fields.extend([x for x in fields_update if x not in values.keys()])
|
||||
|
||||
values2.update(cls.get_debit_credit({
|
||||
x:values.get(x, getattr(line, x)) for x in fields_update
|
||||
x:values.get(x, getattr(line, x)) for x in updt_fields
|
||||
}, line=line))
|
||||
to_write.extend([lines, values2])
|
||||
else :
|
||||
to_write.extend([lines, values])
|
||||
|
||||
super(Line, cls).write(*to_write)
|
||||
|
||||
@classmethod
|
||||
|
|
Loading…
Reference in a new issue