Copy alternative payees of invoice if it is the only party on lines to pay

Only one alternative payee is permitted on draft invoice so we can copy it
only if there is only one and it is the one that was already set when posting
the invoice (only party that appears in the lines to pay).

Closes #12528
This commit is contained in:
Cédric Krier
2023-10-28 14:04:23 +02:00
parent 71771568e3
commit 04af335284
2 changed files with 27 additions and 0 deletions
+15
View File
@@ -1399,6 +1399,20 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin, InvoiceReportMixin):
default = {}
else:
default = default.copy()
alternative_payees2copy = set()
for invoice in invoices:
if len(invoice.alternative_payees) == 1:
parties = {l.party for l in invoice.lines_to_pay}
if parties <= set(invoice.alternative_payees):
alternative_payees2copy.add(invoice.id)
def copy_alternative_payees(data):
if data['id'] in alternative_payees2copy:
return data.get('alternative_payees', [])
else:
return []
default.setdefault('number', None)
default.setdefault('sequence')
default.setdefault('move', None)
@@ -1407,6 +1421,7 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin, InvoiceReportMixin):
default.setdefault('invoice_report_cache', None)
default.setdefault('invoice_report_cache_id', None)
default.setdefault('invoice_report_format', None)
default.setdefault('alternative_payees', copy_alternative_payees)
default.setdefault('payment_lines', None)
default.setdefault('invoice_date', None)
default.setdefault('accounting_date', None)
@@ -88,6 +88,12 @@ Post customer invoice::
>>> party3.receivable
Decimal('0.0')
Copying invoice with single alternative payee is kept::
>>> duplicate_inv, = invoice.duplicate()
>>> duplicate_inv.alternative_payees == invoice.alternative_payees
True
Set another payee::
>>> delegate = Wizard(
@@ -129,3 +135,9 @@ Pay the invoice::
1
>>> len(invoice.reconciliation_lines)
1
Copying invoice with many alternative payees remove them::
>>> duplicate_inv, = invoice.duplicate()
>>> duplicate_inv.alternative_payees
[]