Start remainder with all lines for amount to pay invoice
This is the worst case before finding a better one with a lower remainder. Closes #12403
This commit is contained in:
1 parent
852741ae54
commit
2be6515fa6
1 file changed
+11
-10
@@ -1396,16 +1396,17 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin):
|
||||
if not l.reconciliation
|
||||
and (not self.account.party_required or l.party == party)]
|
||||
|
||||
best = Result([], self.total_amount)
|
||||
for n in range(len(lines), 0, -1):
|
||||
for comb_lines in combinations(lines, n):
|
||||
remainder = sum(map(balance, comb_lines))
|
||||
remainder -= amount
|
||||
result = Result(list(comb_lines), remainder)
|
||||
if currency.is_zero(remainder):
|
||||
return result
|
||||
if abs(remainder) < abs(best.remainder):
|
||||
best = result
|
||||
remainder = sum(map(balance, lines)) - amount
|
||||
best = Result(lines, remainder)
|
||||
if remainder:
|
||||
for n in range(len(lines) - 1, 0, -1):
|
||||
for comb_lines in combinations(lines, n):
|
||||
remainder = sum(map(balance, comb_lines)) - amount
|
||||
result = Result(list(comb_lines), remainder)
|
||||
if currency.is_zero(remainder):
|
||||
return result
|
||||
if abs(remainder) < abs(best.remainder):
|
||||
best = result
|
||||
return best
|
||||
|
||||
def pay_invoice(
|
||||
|
||||
Reference in new issue
Block a user