Skip to content

[16.0] [FIX] maintenance_request_purchase: fix problems when currency_id field is not set#537

Merged
OCA-git-bot merged 1 commit intoOCA:16.0from
dixmit:16.0-fix-maintenance_request_purchase
Apr 13, 2026
Merged

[16.0] [FIX] maintenance_request_purchase: fix problems when currency_id field is not set#537
OCA-git-bot merged 1 commit intoOCA:16.0from
dixmit:16.0-fix-maintenance_request_purchase

Conversation

@luisDIXMIT
Copy link
Copy Markdown
Contributor

@luisDIXMIT luisDIXMIT commented Dec 19, 2025

We have detected problems related to company_id not being set because it is not required and it can be forced to not have a default value. @etobella

@luisDIXMIT luisDIXMIT force-pushed the 16.0-fix-maintenance_request_purchase branch from 63b96d0 to 9ab1fc8 Compare December 19, 2025 11:19
Copy link
Copy Markdown

@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 failure is due to a database connection error during the Odoo startup, not directly caused by the code changes in the PR. This typically occurs in CI environments like Runboat when the test database is not properly initialized or accessible. However, the code change introduces a potential circular dependency or incorrect field access in _compute_currency_id, which could cause runtime issues if not handled carefully.


2. Suggested Fix

In maintenance_request_purchase/models/maintenance_request.py, line 37 in _compute_currency_id, the method accesses record.company_id.currency_id.id without ensuring that record.company_id exists.

Fix:

@api.depends("company_id.currency_id")
def _compute_currency_id(self):
    for record in self:
        record.currency_id = (
            record.company_id.currency_id.id
            if record.company_id
            else self.env.company.currency_id.id
        )

This ensures that company_id is checked before accessing its currency_id.


3. Additional Code Issues

  • Potential runtime error: If company_id is False (not set), accessing record.company_id.currency_id will raise an error unless explicitly guarded.
  • Missing @api.model: The use of self.env.company is correct, but the logic should be robust to avoid accessing fields on non-existent records.

4. Test Improvements

Add test cases in tests/test_maintenance_request.py or similar using SavepointCase to cover:

  • Test with no company set: Ensure currency_id defaults to env.company.currency_id.
  • Test with company set: Ensure currency_id is correctly computed from company_id.currency_id.
  • Test with purchase orders: Ensure _compute_total_purchase_amount works correctly with computed currency_id.

Example test snippet:

def test_compute_currency_id_without_company(self):
    request = self.env['maintenance.request'].create({
        'name': 'Test Request',
        # No company_id set
    })
    self.assertEqual(request.currency_id, self.env.company.currency_id)

def test_compute_currency_id_with_company(self):
    company = self.env['res.company'].create({'name': 'Test Co'})
    request = self.env['maintenance.request'].create({
        'name': 'Test Request',
        'company_id': company.id,
    })
    self.assertEqual(request.currency_id, company.currency_id)

Use SavepointCase for robust database isolation and @tag('post_install') for tests that require module installation.


⏰ This PR has been open for 86 days.
🔍 No human reviews yet after 86 days. PSC members: a quick review would help keep this contributor engaged with OCA.
💤 Last activity was 86 days ago.

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

@etobella
Copy link
Copy Markdown
Member

/ocabot merge patch

Merging as it might give errors.

@OCA-git-bot
Copy link
Copy Markdown
Contributor

On my way to merge this fine PR!
Prepared branch 16.0-ocabot-merge-pr-537-by-etobella-bump-patch, awaiting test results.

OCA-git-bot added a commit that referenced this pull request Apr 13, 2026
Signed-off-by etobella
@OCA-git-bot
Copy link
Copy Markdown
Contributor

@etobella your merge command was aborted due to failed check(s), which you can inspect on this commit of 16.0-ocabot-merge-pr-537-by-etobella-bump-patch.

After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red.

@luisDIXMIT
Copy link
Copy Markdown
Contributor Author

I see the error related to pkg_resources. I will fix it in another PR.

@etobella
Copy link
Copy Markdown
Member

You might need to do a copier update first

@luisDIXMIT luisDIXMIT force-pushed the 16.0-fix-maintenance_request_purchase branch from 9ab1fc8 to e519f32 Compare April 13, 2026 14:15
@etobella
Copy link
Copy Markdown
Member

/ocabot merge patch

@OCA-git-bot
Copy link
Copy Markdown
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 16.0-ocabot-merge-pr-537-by-etobella-bump-patch, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 8d373c0 into OCA:16.0 Apr 13, 2026
7 checks passed
@OCA-git-bot
Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at bb5609b. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants