Skip to content

[16.0][FIX] partner_industry_secondary: Fix industry populate#2134

Open
vincent-hatakeyama wants to merge 2 commits into
OCA:16.0from
xcgd:bugfix/16.0/partner_industry_secondary/fix-populate
Open

[16.0][FIX] partner_industry_secondary: Fix industry populate#2134
vincent-hatakeyama wants to merge 2 commits into
OCA:16.0from
xcgd:bugfix/16.0/partner_industry_secondary/fix-populate

Conversation

@vincent-hatakeyama
Copy link
Copy Markdown

Fix industry populate to take to handle required name.

The fix needs to be ported to 17.0 and 18.0 too, as it affects those versions too.
I have not looked in older versions.

@vincent-hatakeyama
Copy link
Copy Markdown
Author

Populate tests is not done by OCA so it does not appear on codecov/path.

Odoo core puts populate methods in a separate directory and pylint-odoo complains about it. Is it expected to put the populate methods in the models directory?

@vincent-hatakeyama vincent-hatakeyama force-pushed the bugfix/16.0/partner_industry_secondary/fix-populate branch from 901017d to eafa8a1 Compare September 10, 2025 14:11
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 8, 2026

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 Feb 8, 2026
Copy link
Copy Markdown
Member

@StefanRijnhart StefanRijnhart left a comment

Choose a reason for hiding this comment

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

Thanks! Populate seems to be a bit of a blind corner in the OCA. I was hardly aware myself.
You are right that Odoo keeps population code separately, but its still model code that is loaded during runtime, so for our purposes merging it into models is fine.

@vincent-hatakeyama vincent-hatakeyama force-pushed the bugfix/16.0/partner_industry_secondary/fix-populate branch from eafa8a1 to ab65077 Compare February 26, 2026 15:15
@vincent-hatakeyama
Copy link
Copy Markdown
Author

I moved the populate fix in the models/<model>.py file.

Comment thread partner_industry_secondary/__init__.py Outdated
@vincent-hatakeyama vincent-hatakeyama force-pushed the bugfix/16.0/partner_industry_secondary/fix-populate branch from ab65077 to 20d6a9f Compare February 27, 2026 10:08
@github-actions github-actions Bot removed the stale PR/Issue without recent activity, it'll be soon closed automatically. label Mar 1, 2026
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 of the test failure

The test failure is caused by a database connection error during the Odoo startup, likely due to an invalid or inaccessible database configuration in the test environment. This is not directly caused by the code changes in the PR but indicates an infrastructure issue.

2. Suggested fix

The test failure itself is not due to code changes in partner_industry_secondary, but to the test environment. However, to ensure correctness of the new _populate_factories method, make sure it's only called during data population, not during normal runtime.

File: partner_industry_secondary/models/res_partner_industry.py
Method: _populate_factories
Suggestion: Add a guard to ensure that _populate_factories is only used in a data population context (e.g., via self.env.context.get("populate")), or ensure that it's not called during normal Odoo operations.

3. Additional code issues

  • Potential performance issue in _check_uniq_name: The method loops over self and performs a database query for each record, which is inefficient. It should be optimized to check uniqueness in bulk.

    Fix suggestion:
    Replace the loop with a single domain-based search and validate uniqueness across all records in self at once.

    def _check_uniq_name(self):
        if not self:
            return
        # Group records by name and parent_id
        groups = {}
        for rec in self:
            key = (rec.name, rec.parent_id.id)
            groups.setdefault(key, []).append(rec)
        # Check for duplicates
        for (name, parent_id), records in groups.items():
            if len(records) > 1:
                raise exceptions.ValidationError(
                    _("Error! Industry with same name and parent already exists.")
                )

4. Test improvements

Add tests to ensure:

  • The _populate_factories method works correctly with populate.cartesian.
  • The name field is properly populated with fallback values.
  • The _check_uniq_name method properly detects and raises errors for duplicate industries.

Suggested test cases:

  • TransactionCase: Test copy() and name field population.
  • SavepointCase: Test _check_uniq_name with duplicate records.
  • Tagged test: Add a test tagged with @tag('populate') to validate data factory behavior.

Example test snippet (TransactionCase):

def test_populate_factories(self):
    factories = self.env["res.partner.industry"]._populate_factories()
    name_factory = next((f for f in factories if f[0] == "name"), None)
    self.assertIsNotNone(name_factory)
    # Validate that it uses cartesian with expected values

Example test snippet (SavepointCase):

def test_check_uniq_name_duplicate(self):
    industry1 = self.env["res.partner.industry"].create({"name": "Test"})
    with self.assertRaises(exceptions.ValidationError):
        self.env["res.partner.industry"].create({
            "name": "Test",
            "parent_id": industry1.parent_id.id,
        })

These tests align with OCA patterns and ensure correctness of both new logic and existing constraints.


⚠️ PR Aging Alert: CRITICAL

This PR by @vincent-hatakeyama has been waiting for 186 days — that is over 6 months without being merged or closed.

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

(
field_name,
populate.cartesian(
["Industry name", "Industry name {counter}"], [0.01, 0.99]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • Here, multiple records with name=Industry name might be generated with parent_id=False.
  • Due to the same name and parent, _check_uniq_name() might give error.
  • Possible solution: Use ["Industry name {counter}"], [1.0]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I applied your suggested changes and rebased on latest 16.0 branch.

@BhaveshHeliconia
Copy link
Copy Markdown
Contributor

@vincent-hatakeyama could you please check? The pre-commit and test/ci checks are failing.

@vincent-hatakeyama vincent-hatakeyama force-pushed the bugfix/16.0/partner_industry_secondary/fix-populate branch from 20d6a9f to 83126a0 Compare June 4, 2026 07:54
@OCA-git-bot OCA-git-bot added series:16.0 mod:partner_industry_secondary Module partner_industry_secondary mod:partner_identification Module partner_identification labels Jun 4, 2026
@vincent-hatakeyama
Copy link
Copy Markdown
Author

@vincent-hatakeyama could you please check? The pre-commit and test/ci checks are failing.

pre-commit fails on all PR due to incorrect translation. I’ve added a fix for that. The rest works as expected now.

For the coverage, as populate is not run in OCA, it might be needed to ignore the unused method.

Copy link
Copy Markdown
Contributor

@BhaveshHeliconia BhaveshHeliconia left a comment

Choose a reason for hiding this comment

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

LGTM!

@vincent-hatakeyama vincent-hatakeyama force-pushed the bugfix/16.0/partner_industry_secondary/fix-populate branch from 5621e05 to 0143852 Compare June 5, 2026 08:31
@OCA-git-bot OCA-git-bot removed the mod:partner_identification Module partner_identification label Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:partner_industry_secondary Module partner_industry_secondary series:16.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants