[12.0] contract: some refactoring and a UX improvement - #434
Conversation
First compute the next period end date, then derive the next invoice date from the next period stard and end date.
This concentrates all next date calculation logic in one place, and will allow further simplifications.
Add two computed field showing the next period start and end date. This improve the UX and will enable further simplifications in the code.
Move the part of the logic that compute the next period depending on the chosen next invoice date to _get_next_period_date_end.
Reuse the logic that is now fully located in _get_recurring_next_date.
For backward compatibility
cf8e0e2 to
7c3b9bc
Compare
| ) | ||
| self.contract.recurring_create_invoice() | ||
| self.assertEqual( | ||
| self.acct_line.recurring_next_date, to_date('2018-04-01') |
There was a problem hiding this comment.
The current version assure that a customer is billed the same day each month.
Assume this example:
- date start 01/01
- date end 15/03
the customer will receive an invoices at:
- for pre-paid: 01/01, 01/02 and 01/03
- for monthlylastday: 31/01, 28/02 and 31/03
- for post-paid: 01/02, 01/03 and 01/04
for me it make more sens to say post-paid mode invoice date is the last day of the invoicing period (or the last day of the invoicing period + one day).
Let make a RFC and see what other think about this change
get_relative_delta now works the same for all recurring rules. Move the special case handling to _init_last_date_invoiced which is used only for migration.
e5b1ff4 to
eef75b7
Compare
sbejaoui
left a comment
There was a problem hiding this comment.
Fantastic
Thank you @sbidoul for this great work.
For me the most important thing in this PR is the fact that it fix a logic issue we had for a long time. Now the recurring_invoicing_type is no longer implicit in the monthlylastday option and we can configure a invoicing process to stop at the end of the month and be payed at the first day of the period (even for an interval of several months see).
Adding to this fix, this PR open the way for new features (invoicing offset, computed next invoice date,.. ) by simplifying the code and improve the UX.
cc/ @gva-acsone
| @@ -669,7 +669,7 @@ def _get_period_to_invoice( | |||
| self.ensure_one() | |||
| first_date_invoiced = False | |||
42acf47 to
1b2f8db
Compare
monthlylastday is (almost) not a special case anymore \o/. montlylastday is simply a montly period where the periods are aligned on month boundaries. The last bit of special casing is that postpaid generates invoice the day after the last dasy of the period, except for monthlylastday where the invoice is generated on the last day of the period. This last exception will disappear when we put the offset under user control. This is a breaking change because the post-paid/pre-paid mode becomes relevant for monthlylastday invoicing. The field becomes visible in the UI. Code that generate monthlylastday contract lines must now correctly set the pre-paid/post-paid mode too. Some tests have had to be adapted to reflect that.
1b2f8db to
d9bd822
Compare
|
I added the offset field in the contract line form, to further help the user understand what is going on. @sbejaoui will do some more testing with other depending modules (OCA and customer specific), but we don't expect issue. So this is ready to review. Reviewing individual commits is highly recommended to understand the logical evolution of the code base. |
rafaelbn
left a comment
There was a problem hiding this comment.
After a first quick functional review it looks OK 👍
|
This PR has the |
|
It's difficult to predict side effects with the great amount of changes, but let's trust in your good work and extra tests also makes this more confidence. Trying it out in real will tell us any possible problem. /ocabot merge major |
|
This PR looks fantastic, let's merge it! |
|
To summarize breaking changes:
|
|
Congratulations, your PR was merged at e07ebbe. Thanks a lot for contributing to OCA. ❤️ |
use the new methods for next period calculation result of the refactoring in OCA#434 to consider the recurring_invoicing_type for monthlylastday mode and clean code
use the new methods for next period calculation result of the refactoring in OCA#434 to consider the recurring_invoicing_type for monthlylastday mode and clean code
use the new methods for next period calculation result of the refactoring in OCA#434 to consider the recurring_invoicing_type for monthlylastday mode and clean code
use the new methods for next period calculation result of the refactoring in OCA#434 to consider the recurring_invoicing_type for monthlylastday mode and clean code
use the new methods for next period calculation result of the refactoring in OCA#434 to consider the recurring_invoicing_type for monthlylastday mode and clean code
use the new methods for next period calculation result of the refactoring in OCA#434 to consider the recurring_invoicing_type for monthlylastday mode and clean code
use the new methods for next period calculation result of the refactoring in OCA#434 to consider the recurring_invoicing_type for monthlylastday mode and clean code
use the new methods for next period calculation result of the refactoring in OCA#434 to consider the recurring_invoicing_type for monthlylastday mode and clean code
use the new methods for next period calculation result of the refactoring in OCA#434 to consider the recurring_invoicing_type for monthlylastday mode and clean code
use the new methods for next period calculation result of the refactoring in OCA#434 to consider the recurring_invoicing_type for monthlylastday mode and clean code
use the new methods for next period calculation result of the refactoring in OCA#434 to consider the recurring_invoicing_type for monthlylastday mode and clean code
Some simple refactoring of the contract module. The main idea is to split the computation of the next invoice date in two parts: the computation of the next period, followed by the computation of the next invoice date (aka
recurring_next_date) based on the next period dates.This is best reviewed one commit at a time to understand individual changes.
There is also a UX improvement: display the next period start and end date on the contract line form, so the user does not need to deduce it from other parameters.
Finally,
monthlylastdaynow supportspre-paid/post-paid. This could be a breaking changeif there is code that creates
monthlylastdaycontract lines without setting them topost-paidmode.fixes: #428