Repository navigation
[FIX] sponsorship_compassion: invoice the contract line amount, except the sponsorship price - #2230
Merged
Merged
Conversation
…t the sponsorship price The pricelist only proposes the amount of a new contract line. Only the products of the Sponsorship category take their invoiced price from the pricelist (outside contributions SC / SWP), so that a change of the sponsorship price reaches every sponsorship. Any other product, e.g. a Child Survival donation at 42 with a pricelist price of 50, is invoiced at the amount of its contract line. Assisted-by: claude-opus-5-5, medium, claude-code
…cise docstring Assisted-by: claude-opus-5-5, medium, claude-code
[Medium impact] The PR appears safe to merge and deploy together with the required companion accounting PR. Reviews (2) · Last reviewed commit: "Merge branch '18.0' into T-contract-amou..." · Reviewed by Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Since T3487 (
amount_from_pricelist), every contract line whose product has a pricelist rule is invoiced at the pricelist price instead of its own amount, except in contributions (SC / SWP). Example: a donation contract (type O) with a "Child Survival Program" line at 42 is invoiced 50 since a rule at 50 was added to the Public Pricelist.Business rule (confirmed by the Swiss finance / CRM owner): the pricelist only proposes the amount of a new line; the contract line amount is invoiced. Only the sponsorship price is fixed by the pricelist (read-only on the line), so that a change of that price reaches every active sponsorship; a sponsor giving more gets an extra line of another product.
amount_from_pricelistis now set only for products of exactly the Sponsorship category (product_category_sponsorship, not its sub-categories such as sponsor gifts) with a pricelist item of their own, outside SC / SWP. Every other line (funds, Child Survival, Sponsorship Fund, M2M…) is invoiced at its amount, and its amount becomes editable in the contract form.Companion PR
amount_from_pricelist. Merge and deploy together: without it, that button would overwrite donation amounts with the pricelist price.Deployment
Python only (
amount_from_pricelistis a non-stored compute): restart the server; the next invoices follow the new rule. No-uneeded.Open invoices already generated at the pricelist price are not changed by the code. A one-off script (private ops repository) sets them back to the contract amount through
update_open_invoices(unpaid invoices of the current invoicing month or later, outside generated payment orders), checking each invoice after. On an anonymized copy of production: 58 lines on 54 open invoices, 49 fixed, 5 of past months left as is.Data impact checked on that copy (lines whose invoiced price changes, contract amount ≠ pricelist price): mostly O donations of Child Survival Program (rule 50) and Sponsorship Fund (rule 42), and 8 CSP contracts with a Child Survival complement of 8 / 18 next to the Survival Sponsorship line. The business owner confirmed the contract amount is right for all of them. Sponsorship lines (S) all match their pricelist (42 CHF, 52 USD, 150 PLN): unchanged.
How to test
Test evidence
New
sponsorship_compassion/tests/test_contract_line_amount.py, throughcontract_waiting()(invoice generation) andupdate_cl_amount(). Disposable database with demo data:test_invoice_takes_the_line_amount_of_a_priced_productfails (True is not false),test_price_update_reaches_only_sponsorship_linesfails (45.0 != 42). Without the compassion-accounting change only: the latter fails (45.0 != 60, SC contribution overwritten).test_invoice_takes_the_pricelist_price_of_the_sponsorshippasses on both: characterization of the kept sponsorship behaviour./sponsorship_compassion,/recurring_contract: 4 errors, identical on the base branch (TestResConfigSettings.test_settings_of_a_new_companyportal_sponsorships not-null,TestSWPConsistency,TestProjectCompassion.test_sync_projects_from_gmc_logic,TestSponsorshipImpact).test_write_and_pray_fixesreads the flag for thesponsorshipproduct, which is in the Sponsorship category: its expectations S=True, SC/SWP=False still hold, traced in the code), Nordic modules.Sibling paths
Invariant: a contract line is invoiced at its own amount unless
amount_from_pricelistis set (Sponsorship-category product with its own pricelist item, outside SC / SWP); the pricelist button only rewrites lines with the flag.contract_group.build_inv_line_data(and thesponsorship_compassion/crm_compassionoverrides calling super)test_invoice_takes_*viacontract_waiting()move_line._update_invoice_lines_from_contractupdate_cl_amountin the test, no assertion on the invoice (gap)update_cl_amounttest_price_update_reaches_only_sponsorship_lines(O, SC)account_invoice_pricelistrepricing of a draft invoice (manual quantity/product change, "update prices" button)Rules review
Read-only rules review (code-rules, odoo-rules) on both PRs:
account_invoice_pricelistreprices draft invoice lines regardless of the flag → declared out of scope (above).🤖 Generated with Claude Code