Skip to content

[WIP][16.0] add partner_multi_relation_contact#2250

Open
NL66278 wants to merge 12 commits intoOCA:16.0from
Therp:16.0-add-partner_multi_relation_contact
Open

[WIP][16.0] add partner_multi_relation_contact#2250
NL66278 wants to merge 12 commits intoOCA:16.0from
Therp:16.0-add-partner_multi_relation_contact

Conversation

@NL66278
Copy link
Contributor

@NL66278 NL66278 commented Jan 5, 2026

Based on the simplified version of partner_multi_relation

@NL66278 NL66278 force-pushed the 16.0-add-partner_multi_relation_contact branch 6 times, most recently from 2dc8bb8 to 4fb406a Compare January 6, 2026 12:23
@NL66278 NL66278 force-pushed the 16.0-add-partner_multi_relation_contact branch from 4fb406a to 04fa4e4 Compare January 6, 2026 15:27
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 of Test Failure

The test failure occurs because the migration script attempts to drop SQL views (res_partner_relation_all and res_partner_relation_type_selection) that no longer exist in the updated module structure. These views were removed in favor of direct model-based relations, but the post-migration script still tries to drop them, causing a database error during upgrade.


2. Suggested Fix

In partner_multi_relation/migrations/16.0.2.0.0/post-migration.py, remove or conditionally execute the DROP VIEW statements for res_partner_relation_all and res_partner_relation_type_selection.

Specific change:

# Replace:
env.cr.execute("DROP VIEW IF EXISTS res_partner_relation_all;")
env.cr.execute("DROP VIEW IF EXISTS res_partner_relation_type_selection;")

# With:
# Only drop if the views actually exist
env.cr.execute("DROP VIEW IF EXISTS res_partner_relation_all;")
env.cr.execute("DROP VIEW IF EXISTS res_partner_relation_type_selection;")

Or better yet, use openupgrade's helper to safely drop views:

openupgrade.drop_view_if_exists(env.cr, "res_partner_relation_all")
openupgrade.drop_view_if_exists(env.cr, "res_partner_relation_type_selection")

This avoids errors in case the views are already gone or never existed.


3. Additional Code Issues

  • Missing active field in res_partner_relation model:
    The active field was added to res_partner_relation, but there is no logic to automatically set it to False when date_end is in the past.
    Suggestion: Add a cron job or a computed field that sets active = False for records where date_end < today.

  • Inconsistent use of self.env.context in _get_current_partner:
    The method uses context.get("active_model") == "res.partner" to infer the current partner, but this may not be reliable in all contexts.
    Suggestion: Ensure that current_partner_id is always explicitly passed via context, or add a fallback to self.env.user.partner_id if no context partner is found.

  • Potential performance issue in _search_relation_date:
    The method performs two separate searches on res.partner.relation with date_domain, which can be inefficient.
    Suggestion: Refactor to use a single query with a union or subquery if needed, or optimize the domain logic.


4. Test Improvements

Add tests for:

  • Migration behavior:
    Use TransactionCase to simulate a database upgrade and assert that res_partner_relation_all and res_partner_relation_type_selection are safely dropped without errors.

Add tests for:

  • Relation search methods (_search_relation_*)
    Use SavepointCase to test edge cases such as:
    • Search with invalid operators (should raise ValidationError)
    • Search with date_start and date_end constraints
    • Search with in and not in operators on relation types

Add tests for:

  • Context-dependent fields (_compute_* methods)
    Use SavepointCase to test:
    • type_id_display, this_partner_id, other_partner_id with and without current_partner_id in context
    • Ensure correct display logic when partner is on the left or right side

Reference OCA Testing Patterns:

  • Use @tag("post_install", "at_install") for migration tests.
  • Use TransactionCase for full database-level behavior.
  • Use SavepointCase for unit tests with complex contexts and domain logic.

Summary

Issue File Description
Migration failure post-migration.py Drop views that no longer exist
Missing active logic res_partner_relation.py No auto-archive logic for past-dated relations
Context handling _get_current_partner Inconsistent inference of current partner
Search performance _search_relation_date Redundant queries on res.partner.relation

These changes will improve stability, correctness, and test coverage of the module.


⏰ This PR has been open for 69 days.
🔍 No human reviews yet after 69 days. PSC members: a quick review would help keep this contributor engaged with OCA.
💤 Last activity was 51 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

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