Don't set missing attribute on line in _on_change_lines_taxes

because it is sent back to the client as changed values, instead improve
taxable_lines to work with missing values

issue5103
review22691002
This commit is contained in:
Cédric Krier
2016-01-13 21:05:55 +01:00
parent 2ecad9f90c
commit f3791e4fee
+16 -9
View File
@@ -452,13 +452,6 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin):
if self.lines:
for line in self.lines:
self.untaxed_amount += getattr(line, 'amount', None) or 0
for attribute, default_value in (
('taxes', []),
('unit_price', Decimal(0)),
('quantity', 0.),
):
if not getattr(line, attribute, None):
setattr(line, attribute, default_value)
computed_taxes = self._get_taxes()
def is_zero(amount):
@@ -733,8 +726,22 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin):
@property
def taxable_lines(self):
return [(l.taxes, l.unit_price, l.quantity) for l in self.lines
if l.type == 'line']
taxable_lines = []
# In case we're called from an on_change we have to use some sensible
# defaults
for line in self.lines:
if getattr(line, 'type', None) != 'line':
continue
taxable_lines.append(tuple())
for attribute, default_value in [
('taxes', []),
('unit_price', Decimal(0)),
('quantity', 0.),
]:
value = getattr(line, attribute, None)
taxable_lines[-1] += (
value if value is not None else default_value,)
return taxable_lines
@property
def tax_type(self):