add splitline
This commit is contained in:
parent
90fbfa3fde
commit
b9b500624e
13 changed files with 299 additions and 27 deletions
59
line.py
59
line.py
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# This file is part of the cashbook-module from m-ds for Tryton.
|
||||
# This file is part of the cashbook-module from m-ds.de for Tryton.
|
||||
# The COPYRIGHT file at the top level of this repository contains the
|
||||
# full copyright notices and license terms.
|
||||
|
||||
|
@ -78,6 +78,14 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
}
|
||||
return recname
|
||||
|
||||
@classmethod
|
||||
def get_fields_write_update(cls):
|
||||
""" add 'quantity' to updatefields
|
||||
"""
|
||||
result = super(Line, cls).get_fields_write_update()
|
||||
result.append('quantity')
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def get_debit_credit(cls, values, line=None):
|
||||
""" compute quantity_debit/quantity_credit from quantity
|
||||
|
@ -223,6 +231,35 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
linetxt = line.rec_name,
|
||||
))
|
||||
|
||||
@classmethod
|
||||
def update_values_by_splitlines(cls, lines):
|
||||
""" add quantity to line
|
||||
"""
|
||||
to_write = super(Line, cls).update_values_by_splitlines(lines)
|
||||
|
||||
for line in lines:
|
||||
cnt1 = sum([1 for x in line.splitlines if x.quantity is not None])
|
||||
quantity = sum([x.quantity or Decimal('0.0') for x in line.splitlines])
|
||||
if (cnt1 > 0) and (quantity != line.quantity):
|
||||
to_write.extend([ [line], {'quantity': quantity,} ])
|
||||
return to_write
|
||||
|
||||
@classmethod
|
||||
def add_values_from_splitlines(cls, values):
|
||||
""" add values for create to line by settings on splitlines
|
||||
"""
|
||||
values = super(Line, cls).add_values_from_splitlines(values)
|
||||
|
||||
if ('splitlines' in values.keys()) and ('quantity' not in values.keys()):
|
||||
for action in values['splitlines']:
|
||||
quantity = None
|
||||
if action[0] == 'create':
|
||||
cnt1 = sum([1 for x in action[1] if x.get('quantity', None) is not None])
|
||||
quantity = sum([x.get('quantity', Decimal('0.0')) for x in action[1]])
|
||||
if cnt1 > 0:
|
||||
values['quantity'] = quantity
|
||||
return values
|
||||
|
||||
@classmethod
|
||||
def add_2nd_unit_values(cls, values):
|
||||
""" extend create-values
|
||||
|
@ -236,24 +273,4 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
values.update(cls.add_2nd_quantity(values, Cashbook(cashbook).quantity_uom))
|
||||
return values
|
||||
|
||||
@classmethod
|
||||
def write(cls, *args):
|
||||
""" add or update quanity_debit/credit
|
||||
"""
|
||||
actions = iter(args)
|
||||
to_write = []
|
||||
for lines, values in zip(actions, actions):
|
||||
# update debit / credit
|
||||
if len(set(values.keys()).intersection(set({'quantity', 'bookingtype'}))) > 0:
|
||||
for line in lines:
|
||||
values2 = {}
|
||||
values2.update(values)
|
||||
values2.update(cls.get_debit_credit({
|
||||
x:values.get(x, getattr(line, x)) for x in ['quantity', 'bookingtype']
|
||||
}, line=line))
|
||||
to_write.extend([lines, values2])
|
||||
else :
|
||||
to_write.extend([lines, values])
|
||||
super(Line, cls).write(*to_write)
|
||||
|
||||
# end Line
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue