Skip to content

[FIX] sponsorship_compassion: invoice the contract line amount, except the sponsorship price - #2230

Merged
Danielgergely merged 3 commits into
18.0from
T-contract-amount-priority
Nov 27, 2026
Merged

Danielgergely merged 3 commits into
18.0from
T-contract-amount-priority

Conversation

@davidwul

Copy link
Copy Markdown
Contributor

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_pricelist is 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

Deployment

Python only (amount_from_pricelist is a non-stored compute): restart the server; the next invoices follow the new rule. No -u needed.

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

  1. Public Pricelist with a rule for Child Survival Program at 50 and for Sponsorship at 42.
  2. Donation contract (O) with Child Survival at 42, validate it: the invoice line is 42 (was 50). The amount is editable in the form.
  3. Sponsorship (S): the sponsorship line stays read-only and is invoiced at the pricelist price.

Test evidence

New sponsorship_compassion/tests/test_contract_line_amount.py, through contract_waiting() (invoice generation) and update_cl_amount(). Disposable database with demo data:

odoo-bin -d <test_db> -u sponsorship_compassion --test-tags /sponsorship_compassion:TestContractLineAmount --stop-after-init
  • With both PRs: 3/3 pass.
  • Without the model changes: test_invoice_takes_the_line_amount_of_a_priced_product fails (True is not false), test_price_update_reaches_only_sponsorship_lines fails (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_sponsorship passes on both: characterization of the kept sponsorship behaviour.
  • Full suites /sponsorship_compassion,/recurring_contract: 4 errors, identical on the base branch (TestResConfigSettings.test_settings_of_a_new_company portal_sponsorships not-null, TestSWPConsistency, TestProjectCompassion.test_sync_projects_from_gmc_logic, TestSponsorshipImpact).
  • Not run: crm_compassion, my_compassion, sponsorship_switzerland, partner_communication_switzerland (test_write_and_pray_fixes reads the flag for the sponsorship product, which is in the Sponsorship category: its expectations S=True, SC/SWP=False still hold, traced in the code), Nordic modules.
  • pre-commit clean on the changed files.

Sibling paths

Invariant: a contract line is invoiced at its own amount unless amount_from_pricelist is set (Sponsorship-category product with its own pricelist item, outside SC / SWP); the pricelist button only rewrites lines with the flag.

Entry point Covered by
Invoice generation, contract_group.build_inv_line_data (and the sponsorship_compassion / crm_compassion overrides calling super) test_invoice_takes_* via contract_waiting()
Open invoice update on contract change, move_line._update_invoice_lines_from_contract reads the same flag; exercised by update_cl_amount in the test, no assertion on the invoice (gap)
Pricelist button / on-time automation, update_cl_amount test_price_update_reaches_only_sponsorship_lines (O, SC)
Contract form, amount read-only when the flag is set view only, not tested
New line onchange proposing the pricelist price unchanged, consistent with "the pricelist proposes"
OCA account_invoice_pricelist repricing of a draft invoice (manual quantity/product change, "update prices" button) Out of scope: manual action on a draft invoice by staff, ignores the flag before and after this change

Rules review

Read-only rules review (code-rules, odoo-rules) on both PRs:

  • SC / SWP exclusion of the price-update button untested → fixed: SC contract added to the test, red without the compassion-accounting change.
  • OCA account_invoice_pricelist reprices draft invoice lines regardless of the flag → declared out of scope (above).
  • Docstring promised more than the code (own pricelist item only, exact category) → docstring made precise.
  • Data impact on existing lines → checked on an anonymized production copy, confirmed by the business owner (above).
  • Nordic sponsorship products in another category → not checkable here (database data); Nordic reviewer to confirm their sponsorship product is in the Sponsorship category.

🤖 Generated with Claude Code

…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
@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge and deploy together with the required companion accounting PR.RetriggerView in GreptileConfidence Score: 5/5

[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

@Danielgergely
Danielgergely merged commit 1ea5ee7 into 18.0 Nov 27, 2026
2 checks passed
@Danielgergely
Danielgergely deleted the T-contract-amount-priority branch November 27, 2026 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants