changeset 3aadaeca1ed9 in modules/account_invoice:default
details:
https://hg.tryton.org/modules/account_invoice?cmd=changeset&node=3aadaeca1ed9
description:
Use invoice date to enforce sequence on customer invoice
issue11139
review378091002
diffstat:
CHANGELOG | 1 +
invoice.py | 18 ++++++------------
message.xml | 2 +-
tests/scenario_invoice_customer_sequential.rst | 8 ++++----
4 files changed, 12 insertions(+), 17 deletions(-)
diffs (98 lines):
diff -r f41e3f7dfd7f -r 3aadaeca1ed9 CHANGELOG
--- a/CHANGELOG Fri Mar 25 15:56:45 2022 +0100
+++ b/CHANGELOG Sat Mar 26 12:04:40 2022 +0100
@@ -1,3 +1,4 @@
+* Use invoice date to enforce sequence on customer invoice
* Prevent delete tax identifier used on invoice
* Raise a warning when validating supplier invoice with same reference
* Add support for Python 3.10
diff -r f41e3f7dfd7f -r 3aadaeca1ed9 invoice.py
--- a/invoice.py Fri Mar 25 15:56:45 2022 +0100
+++ b/invoice.py Sat Mar 26 12:04:40 2022 +0100
@@ -1083,10 +1083,10 @@
with Transaction().set_context(company=company.id):
today = Date.today()
- def accounting_date(invoice):
- return invoice.accounting_date or invoice.invoice_date or today
+ def invoice_date(invoice):
+ return invoice.invoice_date or today
- grouped_invoices = sorted(grouped_invoices, key=accounting_date)
+ grouped_invoices = sorted(grouped_invoices, key=invoice_date)
for invoice in grouped_invoices:
# Posted and paid invoices are tested by check_modify so we can
@@ -1106,20 +1106,14 @@
invoice.invoice_date = today
invoice.number, invoice.sequence = invoice.get_next_number()
if invoice.type == 'out' and invoice.sequence not in sequences:
- date = accounting_date(invoice)
+ date = invoice_date(invoice)
# Do not need to lock the table
# because sequence.get_id is sequential
after_invoices = cls.search([
('sequence', '=', invoice.sequence),
- ['OR',
- ('accounting_date', '>', date),
- [
- ('accounting_date', '=', None),
- ('invoice_date', '>', date),
- ],
- ],
+ ('invoice_date', '>', date),
],
- limit=1, order=[('accounting_date', 'DESC')])
+ limit=1, order=[('invoice_date', 'DESC')])
if after_invoices:
after_invoice, = after_invoices
raise InvoiceNumberError(
diff -r f41e3f7dfd7f -r 3aadaeca1ed9 message.xml
--- a/message.xml Fri Mar 25 15:56:45 2022 +0100
+++ b/message.xml Sat Mar 26 12:04:40 2022 +0100
@@ -22,7 +22,7 @@
<field name="text">To post invoice "%(invoice)s", you must define
a sequence on fiscal year "%(fiscalyear)s".</field>
</record>
<record model="ir.message" id="msg_invoice_number_after">
- <field name="text">To number the invoice "%(invoice)s", you must
set an accounting date after "%(date)s" because the sequence "%(sequence)s" has
already been used for invoice "%(after_invoice)s".</field>
+ <field name="text">To number the invoice "%(invoice)s", you must
set an invoice date after "%(date)s" because the sequence "%(sequence)s" has
already been used for invoice "%(after_invoice)s".</field>
</record>
<record model="ir.message" id="msg_invoice_modify">
<field name="text">You cannot modify invoice "%(invoice)s" because
it is posted, paid or cancelled.</field>
diff -r f41e3f7dfd7f -r 3aadaeca1ed9
tests/scenario_invoice_customer_sequential.rst
--- a/tests/scenario_invoice_customer_sequential.rst Fri Mar 25 15:56:45
2022 +0100
+++ b/tests/scenario_invoice_customer_sequential.rst Sat Mar 26 12:04:40
2022 +0100
@@ -53,7 +53,7 @@
>>> invoice = Invoice(type='out')
>>> invoice.party = party
- >>> invoice.accounting_date = fiscalyear.periods[1].start_date
+ >>> invoice.invoice_date = fiscalyear.periods[1].start_date
>>> line = invoice.lines.new()
>>> line.quantity = 1
>>> line.unit_price = Decimal('10')
@@ -62,7 +62,7 @@
>>> invoice = Invoice(type='out')
>>> invoice.party = party
- >>> invoice.accounting_date = next_fiscalyear.periods[0].start_date
+ >>> invoice.invoice_date = next_fiscalyear.periods[0].start_date
>>> line = invoice.lines.new()
>>> line.quantity = 1
>>> line.unit_price = Decimal('20')
@@ -73,7 +73,7 @@
>>> invoice = Invoice(type='out')
>>> invoice.party = party
- >>> invoice.accounting_date = fiscalyear.periods[0].start_date
+ >>> invoice.invoice_date = fiscalyear.periods[0].start_date
>>> line = invoice.lines.new()
>>> line.quantity = 1
>>> line.unit_price = Decimal('5')
@@ -87,5 +87,5 @@
Post invoice on the third period::
- >>> invoice.accounting_date = fiscalyear.periods[2].start_date
+ >>> invoice.invoice_date = fiscalyear.periods[2].start_date
>>> invoice.click('post')