contract
contract copied to clipboard
[14.0][BUG] - Contract with an End date raise an error
Hello there,
I'm sorry let me know if am I on the wrong way but I'm not sure if this is a bad understanding of the module or if this is a real problem.
I have a problem if I want to specify the Date End of the Contract.
For instance this is Contract of 3 months invoiced 1 time for each month.
Steps to reproduce the problem :
With an empty database and the Contracts (14.0) module freshly updated from github. With and Odoo 14 with standard addons in a new project.
- Create a contract with a start_date in the past to make the test easier.
date_start = 06/01/2021 recurring interval = 1 recurring_rule_type = monthly recurring_invoice_type = pre-paid line_recurrence = False
- Add at least one line to invoice here
name = Test quantity = 1 price_unit = 10
- Save the contract
- Edit the contract and set the Date end and check the start/end dates are correctly set on Contract and on lines
date_end = 08/01/2021 We need to set the dates in two steps here because otherwise the Date end is not set when saving the first time.
- Before the first invoicing the dates are :
Date Start 06/01/2021 Date End 08/01/2021 Date of Next Invoice 06/01/2021
- Click on the button "Create Invoice" to simulate the call of the CRON
1st Click => OK :
Date Start 06/01/2021 Date End 08/01/2021 Date of Next Invoice 07/01/2021
2nd Click => OK :
Date Start 06/01/2021 Date End 08/01/2021 Date of Next Invoice 08/01/2021
3rd Click => OK / NOK ? :
Date Start 06/01/2021 Date End 08/01/2021 Date of Next Invoice 06/01/2021
Here the date of the next invoice is reset to the start date so at the next call of the CRON or click on the button this Contract will be invoiced because the "recurring_next_date" still set and lower than the "current date" of execution I guess the "recurring_next_date" should be empty here because this Contract dosn't need to be invoiced one more time because the Date end was 08/01/2021.
4th call the CRON => NOK An Odoo error is raise
Error: Odoo Server Error Traceback (most recent call last): File "/opt/odoo/odoo/odoo/addons/base/models/ir_http.py", line 237, in _dispatch result = request.dispatch() File "/opt/odoo/odoo/odoo/http.py", line 683, in dispatch result = self._call_function(**self.params) File "/opt/odoo/odoo/odoo/http.py", line 359, in _call_function return checked_call(self.db, *args, **kwargs) File "/opt/odoo/odoo/odoo/service/model.py", line 94, in wrapper return f(dbname, *args, **kwargs) File "/opt/odoo/odoo/odoo/http.py", line 347, in checked_call result = self.endpoint(*a, **kw) File "/opt/odoo/odoo/odoo/http.py", line 912, in __call__ return self.method(*args, **kw) File "/opt/odoo/odoo/odoo/http.py", line 531, in response_wrap response = f(*args, **kw) File "/opt/odoo/odoo/addons/web/controllers/main.py", line 1393, in call_button action = self._call_kw(model, method, args, kwargs) File "/opt/odoo/odoo/addons/web/controllers/main.py", line 1381, in _call_kw return call_kw(request.env[model], method, args, kwargs) File "/opt/odoo/odoo/odoo/api.py", line 396, in call_kw result = _call_kw_multi(method, model, args, kwargs) File "/opt/odoo/odoo/odoo/api.py", line 383, in _call_kw_multi result = method(recs, *args, **kwargs) File "/opt/odoo/custom_addons/contract/models/contract.py", line 564, in recurring_create_invoice invoice = self._recurring_create_invoice() File "/opt/odoo/custom_addons/contract/models/contract.py", line 591, in _recurring_create_invoice invoices_values = self._prepare_recurring_invoices_values(date_ref) File "/opt/odoo/custom_addons/contract/models/contract.py", line 546, in _prepare_recurring_invoices_values invoice_line_vals = line._prepare_invoice_line(move_form=move_form) File "/opt/odoo/custom_addons/contract/models/contract_line.py", line 560, in _prepare_invoice_line name = self._insert_markers(dates[0], dates[1]) File "/opt/odoo/custom_addons/contract/models/contract_line.py", line 610, in _insert_markers name = name.replace("#END#", last_date_invoiced.strftime(date_format)) Exception The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/opt/odoo/odoo/odoo/http.py", line 639, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/opt/odoo/odoo/odoo/http.py", line 315, in _handle_exception raise exception.with_traceback(None) from new_cause AttributeError: 'bool' object has no attribute 'strftime'
This error appear because in the last call, the value of "last_date_invoiced" is "False". We should never call this function again because this Contract shoudn't be invoiced a new time.
Is there a bug ? The "recurring_next_date" should be empty at the end of the Contract ?
Thanks
The problem seems to be in this function :
@api.depends(
"contract_line_ids.recurring_next_date",
"contract_line_ids.is_canceled",
)
def _compute_recurring_next_date(self):
for contract in self:
recurring_next_date = contract.contract_line_ids.filtered(
lambda l: (
l.recurring_next_date
and not l.is_canceled
and (not l.display_type or l.is_recurring_note)
)
).mapped("recurring_next_date")
# we give priority to computation from date_start if modified
if (
contract._origin
and contract._origin.date_start != contract.date_start
or not recurring_next_date
):
super(ContractContract, contract)._compute_recurring_next_date()
else:
contract.recurring_next_date = min(recurring_next_date)
Why are we calling super()
if recurring_next_date
from the contract.contract_line_ids.filtered(....)
is False
?
If recurring_next_date
is False
that because there is no next invoicing period because of the date_end
so we must keep this value set to lines and the contract no ?
By changing the if statement
and the contract.recurring_next_date
assignation, my Contract is ended as it should be, the recurring_next_date
is correctly set to False
.
But is not totally good because with that modification we can't copy a Contract anymore 🙈 because of a constrains in _check_recurring_next_date_recurring_invoices
.
Maybe we have to use a context here just to say to Odoo "recurring_next_date
is False
but that's normal here write it"
Any other ideas or advices to fix this ?
Thanks,
Mkxm
What are the steps to reproduce the problem in UI?
Hello,
Sorry maybe it was not clear in my first comment.
Here a clearly fresh exemple :
And what we should have ? The next invoice date has to be empty when the Contract is ended ?
@pedrobaeza we had the same issue (V13). We suggest 2 solutions:
A) If we add the condition is_terminated = False to the domain ( _get_contracts_to_invoice_domain
), we could solve these use cases.
B) When calling _compute_recurring_next_date
we could empty recurring next_date
when this date is later than date_end
.
Pedro, could you validate which option would be better? We can take care of this.
Hi @pedrobaeza , did you have the chance to have a look at this? We can manage the FIX. THX.
Hello Team
Any update on this issue?
I'd like to vote for this issue - have the same problem here in Odoo v13.
Hello Team
Someone have solution for this issue ?
I can confirm that this is not working when setting the recurrence at contract level instead of line level, the recurring_next_date will be update to the value of date_start if it reach the date_end, that makes the contract never be finished. Recurrence on line level seems to be fine, except that we can not duplicate the contract record
This is fixed in https://github.com/OCA/contract/pull/853 (for v13, but it's applicable the same for 14 and 15)
I think #841 also solves this issue.