Repository navigation
Conversation
Add amount_from_pricelist on contract lines, used by the line view and both invoice price computations, so that other modules can decide when the line amount wins over the pricelist price.
|
| @api.depends("product_id") | ||
| def _compute_amount_from_pricelist(self): | ||
| for line in self: | ||
| line.amount_from_pricelist = line.pricelist_item_count > 0 |
There was a problem hiding this comment.
If a pricelist item is added or removed after a contract line’s price-choice flag has been read in the same request, and that flag is not invalidated, invoice creation or updates can use the old price source. The flag reads pricelist_item_count but declares only product_id as a dependency. Track the count as a dependency before merging so the price choice updates with it.
Knowledge Base Used: Recurring contracts and invoicing
There was a problem hiding this comment.
In theory: if a pricelist item is added or removed earlier in the same request, the cached value could be outdated. But its fix wouldn't help. Odoo's own pricelist_item_count has no dependencies at all (it just counts records), so declaring it as a dependency triggers nothing. It isn't a regression either: the old code read the same pricelist_item_count with exactly the same caching. In practice, a pricelist rule is never changed and a contract invoiced in the same request.
There was a problem hiding this comment.
You're right. Adding @api.depends("pricelist_item_count") would not provide meaningful invalidation because the upstream product.pricelist_item_count itself declares no dependencies. This also preserves the same cached read used by the previous invoice computations, so it is not a regression. Since pricelist rules are not changed while an invoice is being created, this is theoretical rather than actionable. I'll withdraw the finding.
Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.
| amount_from_pricelist = fields.Boolean( | ||
| compute="_compute_amount_from_pricelist", | ||
| help="The invoiced price comes from the pricelist instead of the line price.", | ||
| ) |
There was a problem hiding this comment.
There is no direct invoice test for a product-specific pricelist item or an override that uses the contract line amount. The existing fixture uses a global item and defines no test of its own. This is a non-blocking coverage gap, but a later pricing change could restore the wrong sponsorship charge without a test catching it. Add creation and update tests for both price choices.
Knowledge Base Used: Recurring contracts and invoicing
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Artifacts
Invoice price-choice verification script
- This authored script extracts and executes the pricing methods from either revision with lightweight records, allowing the same scenarios to be compared.
Invoice pricing before the change
- Running the script against HEAD^ showed that a priced product used 42 for both invoice paths, including the override scenario.
Invoice pricing after the change
- Running the same script against HEAD showed that the overridden choice used the line amount of 17 for both invoice paths.
Targeted Odoo test collection failure
- Running the existing test file with pytest exited 2 during import because `dateutil` is missing, so an Odoo transaction run was not possible.
T3487 — Fix failing quality test: Create a Write&Pray Sponsorship
compassion-accounting— modulerecurring_contractcompassion-modules— modulessponsorship_compassion,thankyou_letterscompassion-switzerland— modulepartner_communication_switzerland(version 18.0.1.1.6)Merge order:
compassion-accountingfirst.sponsorship_compassionoverrides the newrecurring.contract.line._compute_amount_from_pricelist.Original report
Quality test "Create a Write&Pray Sponsorship" failed in three places:
Root causes
1. Mobile warning
partner_communication_switzerland/models/contracts.py) ran on every change of type, even before a correspondent was chosen.2. Amount and invoices
readonly="pricelist_item_count > 0").contract_group.build_inv_line_data,move_line._update_invoice_lines_from_contract).3. Communications
survey.public_url, a v14 field that doesn't exist in v18. Rendering failed and the welcome was skipped (the error is only logged)._send_new_dossier, "no email → printed dossier" was checked before the W&P case. W&P sponsors with only a mobile got the printed dossier._get_salutation_*usesfirstname, neverpreferred_name(same in v14).ade0fc72, merged 17.09),thankyou_letters_compute_addressonly assignsname_linefor partners with a title, so computing the address crashes (UnboundLocalError) for any partner without one. In production, every printed communication for a partner without a title fails this way, not only W&P.Changes
compassion-accounting
aedec6c— Allow invoicing the contract line amount of pricelist products: new computedamount_from_priceliston contract lines (default: product has pricelist items). It's used by the line list view (readonly) and by both invoice price computations, so other modules can decide when the line amount wins.How to test