[16.0][IMP]contract: add recurring total#1322
Conversation
|
@pedrobaeza can you review please? |
|
You have https://github.com/OCA/contract/tree/16.0/contract_forecast for that BI AFAIK. |
|
There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. |
marcos-mendez
left a comment
There was a problem hiding this comment.
Automated Review -- Tests Failed
1. Root Cause
The test failures occur due to a CacheMiss error when accessing contract.line(2).recurring_subtotal, indicating that the computed field recurring_subtotal on contract.line is not properly initialized or cached during test execution, likely because it depends on other fields that are not yet set or computed in the test context.
2. Suggested Fix
In contract/models/contract_line.py, the _compute_recurring_subtotal method computes recurring_subtotal based on state, recurring_rule_type, and recurring_interval, but the field is not stored (store=False by default for computed fields). However, the _compute_recurring_total in contract.py depends on contract_line_ids.recurring_subtotal, which causes a cache miss when the line is accessed before the computation is triggered.
Fix:
Add store=True to the recurring_subtotal field definition in contract_line.py (around line 105):
recurring_subtotal = fields.Monetary(
compute="_compute_recurring_subtotal",
currency_field="currency_id",
store=True, # <-- Add this
)This ensures that the computed value is stored and available in the cache, resolving the CacheMiss.
3. Additional Code Issues
- Missing
store=Trueonrecurring_subtotal: This is the main issue causing cache errors. Withoutstore=True, the computed field cannot be reliably accessed in related computations or views, especially in test environments. - No handling of
recurring_rule_typeinrule_type_dict: Ifrecurring_rule_typeis not one of the defined keys (daily,weekly, etc.), it defaults to1, which may lead to incorrect annual frequency. Consider raising aUserErroror using a default fallback if needed.
4. Test Improvements
To improve test coverage and prevent regressions:
- Add a
TransactionCasetest that creates a contract line with variousrecurring_rule_typevalues and checks thatrecurring_subtotalis correctly computed and stored. - Test in
SavepointCaseto ensure that computed fields are correctly updated and cached across multiple records and operations. - Add test for
recurring_totalcomputation that verifies it correctly sumsrecurring_subtotalof all lines, especially when lines are created, modified, or deleted.
Example test pattern:
def test_recurring_subtotal_computation(self):
line = self.env['contract.line'].create({
'contract_id': self.contract.id,
'price_unit': 100,
'quantity': 2,
'recurring_rule_type': 'monthly',
'recurring_interval': 1,
})
self.assertEqual(line.recurring_subtotal, 1200.0) # 100 * 12 * 2Use @tagged('post_install', 'manual') for tests that involve computed fields or complex caching logic.
⏰ PR Aging Alert
This PR by @alejandrotrey has been open for 143 days (4 months).
🔴 Zero human reviews in 143 days. This contributor invested their time to improve this module. The PSC owes them at least a response — even a "needs changes" is better than silence.
Every ignored PR is a contributor who might not come back. Review time matters. (OCA Aging Report)
Reciprocal Review Request
Hi everyone! I found some test failures on this PR and left detailed feedback above. I am happy to discuss or help debug. In the meantime, if any of you get a chance, I would appreciate a look at my open PR(s):
My open PRs across OCA:
- server-tools#3548 [18.0][MIG] base_kanban_stage: Migration to 18.0
- hr-attendance#262 [16.0][ADD] Hr_attendance_idsecure: iDSecure (ControliD) attendance integration
- stock-logistics-workflow#2276 [16.0][ADD] stock_move_line_devaluation
- stock-logistics-workflow#2275 [16.0][ADD] Stock move line analytic account
- stock-logistics-workflow#2268 [16.0][ADD] stock_move_line_picking_partner
- purchase-workflow#2694 [16.0][IMP]Purchase workflow added to review state & exception fix
Reviewing each other's work helps the whole community move forward. Thank you!
Environment via OCA Neural Reviewer: Minikube + K8s Job + oca-ci/py3.10-odoo16.0 | Odoo 16.0
Automated review by OCA Neural Reviewer + qwen3-coder:30b
@cubells Can you review please?