Cédric Krier pushed to branch branch/default at Tryton / Tryton
Commits:
72345bf6 by Cédric Krier at 2023-07-14T11:59:19+02:00
Require lines when paying invoice with write-off or overpayment
This is needed ensure that at least one line to pay of the invoice is
reconciled.
The lines and payment lines are also shown for overpayment.
Closes #12403
- - - - -
e4c88c41 by Cédric Krier at 2023-07-14T12:01:05+02:00
Do not allow overpayment of invoice when write-off amount is negative
When paying less than the amount to pay, there is no overpayment.
- - - - -
e48f4006 by Cédric Krier at 2023-07-14T12:02:49+02:00
Set overpayment by default when amount is greater than the amount to pay
- - - - -
0cc580e8 by Cédric Krier at 2023-07-15T01:05:48+02:00
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
- - - - -
1 changed file:
- modules/account_invoice/invoice.py
Changes:
=====================================
modules/account_invoice/invoice.py
=====================================
@@ -1396,16 +1396,17 @@
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(
@@ -3157,7 +3158,12 @@
('writeoff', "Write-Off"),
('partial', "Partial Payment"),
('overpayment', "Overpayment"),
- ], 'Type', required=True)
+ ], 'Type', required=True,
+ domain=[
+ If(Eval('amount_writeoff', 0) >= 0,
+ ('type', 'in', ['writeoff', 'partial']),
+ ()),
+ ])
writeoff = fields.Many2One(
'account.move.reconcile.write_off', "Write Off",
domain=[
@@ -3176,7 +3182,7 @@
currency='currency', digits='currency',
readonly=True,
states={
- 'invisible': Eval('type') != 'writeoff',
+ 'invisible': ~Eval('type').in_(['writeoff', 'overpayment']),
})
lines_to_pay = fields.Many2Many('account.move.line', None, None,
'Lines to Pay', readonly=True)
@@ -3186,8 +3192,9 @@
('reconciliation', '=', None),
],
states={
- 'invisible': Eval('type') != 'writeoff',
+ 'invisible': ~Eval('type').in_(['writeoff', 'overpayment']),
+ 'required': Eval('type').in_(['writeoff', 'overpayment']),
})
payment_lines = fields.Many2Many('account.move.line', None, None,
'Payment Lines', readonly=True,
states={
@@ -3190,8 +3197,8 @@
})
payment_lines = fields.Many2Many('account.move.line', None, None,
'Payment Lines', readonly=True,
states={
- 'invisible': Eval('type') != 'writeoff',
+ 'invisible': ~Eval('type').in_(['writeoff', 'overpayment']),
})
company = fields.Many2One('company.company', 'Company', readonly=True)
invoice = fields.Many2One('account.invoice', 'Invoice', readonly=True)
@@ -3309,7 +3316,9 @@
default['invoice'] = invoice.id
- if amount >= invoice.amount_to_pay or currency.is_zero(amount):
+ if amount >= invoice.amount_to_pay:
+ default['type'] = 'overpayment'
+ elif currency.is_zero(amount):
default['type'] = 'writeoff'
return default
View it on Heptapod:
https://foss.heptapod.net/tryton/tryton/-/compare/5a7e7df5b604992006bc8d6d05d9bd077ed0ab13...0cc580e8ad572dced49a71255af4daf5664e699b
--
View it on Heptapod:
https://foss.heptapod.net/tryton/tryton/-/compare/5a7e7df5b604992006bc8d6d05d9bd077ed0ab13...0cc580e8ad572dced49a71255af4daf5664e699b
You're receiving this email because of your account on foss.heptapod.net.