Skip to content

[12.0] contract: some refactoring and a UX improvement - #434

Merged
OCA-git-bot merged 18 commits into
OCA:12.0from
acsone:12.0-contract-refactor-sbi
Dec 12, 2019
Merged

[12.0] contract: some refactoring and a UX improvement#434
OCA-git-bot merged 18 commits into
OCA:12.0from
acsone:12.0-contract-refactor-sbi

Conversation

@sbidoul

@sbidoul sbidoul commented Dec 6, 2019

Copy link
Copy Markdown
Member

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, monthlylastday now supports pre-paid/post-paid. This could be a breaking change
if there is code that creates monthlylastday contract lines without setting them to post-paid mode.

fixes: #428

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.
@sbidoul sbidoul added this to the 12.0 milestone Dec 6, 2019
@sbidoul
sbidoul requested a review from sbejaoui December 6, 2019 10:13
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.
@sbidoul
sbidoul force-pushed the 12.0-contract-refactor-sbi branch from cf8e0e2 to 7c3b9bc Compare December 6, 2019 13:26
)
self.contract.recurring_create_invoice()
self.assertEqual(
self.acct_line.recurring_next_date, to_date('2018-04-01')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread contract/tests/test_contract.py
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.
Comment thread contract/migrations/12.0.5.0.0/pre-migration.py Outdated
@sbejaoui
sbejaoui self-requested a review December 9, 2019 09:14
Comment thread contract/models/contract_line.py Outdated
@sbejaoui
sbejaoui force-pushed the 12.0-contract-refactor-sbi branch from e5b1ff4 to eef75b7 Compare December 9, 2019 11:11

@sbejaoui sbejaoui left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread contract/models/contract_line.py Outdated
@@ -669,7 +669,7 @@ def _get_period_to_invoice(
self.ensure_one()
first_date_invoiced = False

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is useless now

@sbidoul
sbidoul force-pushed the 12.0-contract-refactor-sbi branch from 42acf47 to 1b2f8db Compare December 9, 2019 12:16
sbidoul and others added 2 commits December 9, 2019 13:17
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.
@sbidoul
sbidoul force-pushed the 12.0-contract-refactor-sbi branch from 1b2f8db to d9bd822 Compare December 9, 2019 12:17
@sbidoul

sbidoul commented Dec 9, 2019

Copy link
Copy Markdown
Member Author

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 rafaelbn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a first quick functional review it looks OK 👍

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@pedrobaeza

Copy link
Copy Markdown
Member

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

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR looks fantastic, let's merge it!
Prepared branch 12.0-ocabot-merge-pr-434-by-pedrobaeza-bump-major, awaiting test results.

OCA-git-bot added a commit that referenced this pull request Dec 12, 2019
Signed-off-by pedrobaeza
@sbidoul

sbidoul commented Dec 12, 2019

Copy link
Copy Markdown
Member Author

To summarize breaking changes:

  • Contract lines and products using monthlylastday MUST now specify pre-paid / post-paid. There is a migration script for that. The UI has been adapted. Code that creates such lines must be adapted or will default to pre-paid whereas post-paid was implied before.
  • get_relative_delta() now works uniformly for all period types (it had an exception for monthlylastday before). Code calling it directly must be adapted.
  • In post-paid mode, the invoice date is now always the first day after the end of the period being invoiced. There was an exception before for the last period of the contract.

@OCA-git-bot
OCA-git-bot merged commit ab4ed31 into OCA:12.0 Dec 12, 2019
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at e07ebbe. Thanks a lot for contributing to OCA. ❤️

@sbidoul
sbidoul deleted the 12.0-contract-refactor-sbi branch December 12, 2019 10:00
sbejaoui added a commit to acsone/contract that referenced this pull request Dec 18, 2019
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
sbejaoui added a commit to acsone/contract that referenced this pull request Dec 18, 2019
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
sbejaoui added a commit to acsone/contract that referenced this pull request Oct 25, 2020
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
sbejaoui added a commit to acsone/contract that referenced this pull request Oct 30, 2020
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
sbejaoui added a commit to acsone/contract that referenced this pull request Nov 2, 2020
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
sbejaoui added a commit to acsone/contract that referenced this pull request Apr 21, 2025
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
sbejaoui added a commit to acsone/contract that referenced this pull request Jun 4, 2025
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
fcayre pushed a commit to fcayre/contract that referenced this pull request Jun 12, 2025
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
sbejaoui added a commit to acsone/contract that referenced this pull request Jun 19, 2025
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
fcayre pushed a commit to fcayre/contract that referenced this pull request Sep 16, 2025
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
Larsq1 pushed a commit to codeforward-bv/contract that referenced this pull request Jun 15, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CONTRACT] - Pre-paid mode, invoice the first of each month except for the first period

5 participants