contract
contract copied to clipboard
[14.0][FIX] contract: Reset next invoicing date when terminating a line
Forward-port of #853
Steps to reproduce the problem:
-
Create a new contract
-
Set "Recurrence at line level?"
-
Add a new line, with following data:
- Invoice Every: 1 Month(s)
- Date Start: 2022-06-01
- Invoicing type: Pre-paid
-
Save and click on "Create invoices" button
-
Now edit again and put "Date End": 2022-06-30
Current behavior:
The line is still invoiceable (appears in blue), and if you click on "Create invoices" button, you get the traceback:
...
File "/mnt/data/odoo-addons-dir/contract/models/contract.py", line 534, in recurring_create_invoice
invoice = self._recurring_create_invoice()
File "/mnt/data/odoo-addons-dir/contract/models/contract.py", line 561, in _recurring_create_invoice
invoices_values = self._prepare_recurring_invoices_values(date_ref)
File "/mnt/data/odoo-addons-dir/contract/models/contract.py", line 516, in _prepare_recurring_invoices_values
invoice_line_vals = line._prepare_invoice_line(move_form=move_form)
File "/mnt/data/odoo-addons-dir/contract_layout_category_hide_detail/models/contract_line.py", line 12, in _prepare_invoice_line
vals = super()._prepare_invoice_line(move_form)
File "/mnt/data/odoo-addons-dir/product_contract/models/contract_line.py", line 22, in _prepare_invoice_line
res = super(ContractLine, self)._prepare_invoice_line(move_form)
File "/mnt/data/odoo-addons-dir/contract_variable_quantity/models/contract_line.py", line 44, in _prepare_invoice_line
vals = super()._prepare_invoice_line(move_form)
File "/mnt/data/odoo-addons-dir/contract/models/contract_line.py", line 545, in _prepare_invoice_line
name = self._insert_markers(dates[0], dates[1])
File "/mnt/data/odoo-addons-dir/contract/models/contract_line.py", line 595, in _insert_markers
name = name.replace("#END#", last_date_invoiced.strftime(date_format))
AttributeError: 'bool' object has no attribute 'strftime'
Expected behavior:
Line is not invoiceable anymore, and "Create invoices" button disappears (as no invoiceable line - but anyways, calling the method the same doesn't trigger the invoice creation).
This reverts part of the fixes done by @rousseldenis to apply this simpler one and for not deforming the aim of the method, so no pending fixme.
@Tecnativa TT37880
I was testing this fix, but still get the same error message. After archiving all contracts with "Date End" < now (Date of next invoice) I was able to generate the invoices.
I was testing this fix, but still get the same error message. After archiving all contracts with "Date End" < now (Date of next invoice) I was able to generate the invoices.
@CRogos Could you try this ? https://github.com/OCA/contract/pull/841
Still the same error message. I assume there is a problem when the "Date End" is in the past, but the contract is still selected for invoice creation?
I've now retested this PR and also #841 with a new database. While #841 worked, this PR did not. I tested as following: Today is the 15.9.2022
- Create a new contract
- Date Start 1.6.2022
- Date End 31.7.2022
- Invoice type: pre-paid
- invoice every: 1 Month
- Add a new line, with a product, no End date.
When I now press "Create Invoices" 3 times, than the first invoice is created successfully, also the second, but can see that the Date of next Invoice is changed to the Start Date again:
When pressing the "Create Invoice" the third time we get an error.
@pedrobaeza are you still working on this?