Skip to content

[16.0][IMP]contract: add recurring total#1322

Open
alejandrotrey wants to merge 1 commit intoOCA:16.0from
alejandrotrey:16.0-imp-contract
Open

[16.0][IMP]contract: add recurring total#1322
alejandrotrey wants to merge 1 commit intoOCA:16.0from
alejandrotrey:16.0-imp-contract

Conversation

@alejandrotrey
Copy link

@cubells Can you review please?

@alejandrotrey
Copy link
Author

@pedrobaeza can you review please?

@pedrobaeza pedrobaeza added this to the 16.0 milestone Nov 10, 2025
@pedrobaeza
Copy link
Member

You have https://github.com/OCA/contract/tree/16.0/contract_forecast for that BI AFAIK.

@github-actions
Copy link

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.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Mar 15, 2026
Copy link

@marcos-mendez marcos-mendez left a comment

Choose a reason for hiding this comment

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

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=True on recurring_subtotal: This is the main issue causing cache errors. Without store=True, the computed field cannot be reliably accessed in related computations or views, especially in test environments.
  • No handling of recurring_rule_type in rule_type_dict: If recurring_rule_type is not one of the defined keys (daily, weekly, etc.), it defaults to 1, which may lead to incorrect annual frequency. Consider raising a UserError or using a default fallback if needed.

4. Test Improvements

To improve test coverage and prevent regressions:

  • Add a TransactionCase test that creates a contract line with various recurring_rule_type values and checks that recurring_subtotal is correctly computed and stored.
  • Test in SavepointCase to ensure that computed fields are correctly updated and cached across multiple records and operations.
  • Add test for recurring_total computation that verifies it correctly sums recurring_subtotal of 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 * 2

Use @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:

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

@github-actions github-actions bot removed the stale PR/Issue without recent activity, it'll be soon closed automatically. label Mar 22, 2026
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.

3 participants