Skip to content

[16.0][ADD] account_invoice_partner_company_only: Restrict partner…#2180

Open
maisim wants to merge 1 commit intoOCA:16.0from
maisim:16.0-add-account_invoice_partner_id_company_only
Open

[16.0][ADD] account_invoice_partner_company_only: Restrict partner…#2180
maisim wants to merge 1 commit intoOCA:16.0from
maisim:16.0-add-account_invoice_partner_id_company_only

Conversation

@maisim
Copy link
Copy Markdown

@maisim maisim commented Nov 28, 2025

… to companies

Copy link
Copy Markdown
Contributor

@luisDIXMIT luisDIXMIT left a comment

Choose a reason for hiding this comment

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

I tested it on runboat and it doesn’t seem to be working.

image

@maisim
Copy link
Copy Markdown
Author

maisim commented Dec 2, 2025

I tested it on runboat and it it doesn’t seem to be working.

image

The domain seems oververvrited by another module in the repo. That means this is probably not the right way to do it. Maybe with a Python constraint? Let me take a look.

@maisim
Copy link
Copy Markdown
Author

maisim commented Dec 2, 2025

After some tests, using a constraint that throws an exception is too intrusive, so I just left the contact filter for "company" types in the form.

I'm moving this pull request to draft status because this module will be an optional dependency (using preferences) of OCA/sale-workflow#4039, and I'll be making some changes. This time, I'll wait until everything is ready before requesting a review. :)

@rrebollo
Copy link
Copy Markdown

@maisim the name of the addon should be account_invoice_partner_company_only or similar, I think the _id part should go off.

The domain seems oververvrited by another module in the repo. That means this is probably not the right way to do it. Maybe with a Python constraint? Let me take a look.

Look at my review comments on the sale-workflow addon.

@maisim maisim force-pushed the 16.0-add-account_invoice_partner_id_company_only branch from 11fdd50 to 387be53 Compare March 25, 2026 08:10
@maisim maisim changed the title [16.0][ADD] account_invoice_partner_id_company_only: Restrict partner… [16.0][ADD] account_invoice_partner_company_only: Restrict partner… Mar 25, 2026
@maisim
Copy link
Copy Markdown
Author

maisim commented Mar 25, 2026

Hi @rrebollo,
I made the same changes as in OCA/sale-workflow#4042 and OCA/project#1611

  • Rename the module
  • Add negative tests
  • Fix copyright
  • use base_view_inheritance_extension

Let me know if that's okay with you

maisim added a commit to maisim/sale-workflow that referenced this pull request Mar 25, 2026
…unctional tests from runboat

TODO: remove once the following PRs are merged:
- OCA#4042 (sale_order_partner_company_only)
- OCA/project#1611 (project_partner_company_only)
- OCA/account-invoicing#2180 (account_invoice_partner_company_only)
maisim added a commit to maisim/sale-workflow that referenced this pull request Mar 25, 2026
…unctional tests from runboat

TODO: remove once the following PRs are merged:
- OCA#4042 (sale_order_partner_company_only)
- OCA/project#1611 (project_partner_company_only)
- OCA/account-invoicing#2180 (account_invoice_partner_company_only)
Copy link
Copy Markdown

@rrebollo rrebollo left a comment

Choose a reason for hiding this comment

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

The design and implementation still feel quite naive at this point. The base requirement may be valid, but you need to work on it a bit longer.

Take a look at already merged addons to grasp the philosophy behind OCA contributions.

Thanks for your effort.

Comment on lines +28 to +50
def test_01_partner_domain_in_view(self):
"""Test that partner_id field has company-only domain in the view."""
account_move = self.env["account.move"]
view = self.env.ref("account.view_move_form")

# Get the view arch with our module's modifications
view_info = account_move.get_view(view_id=view.id)
doc = etree.fromstring(view_info["arch"])

# Find partner_id field in the view
partner_fields = doc.xpath("//field[@name='partner_id']")

# Check that the first partner_id field has the compayny type domain
domain_found = False
field = partner_fields[0]
domain = field.get("domain")
if "('is_company', '=', True)" in domain:
domain_found = True

self.assertTrue(
domain_found,
"partner_id field should have a domain restricting to companies",
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Here, you're testing whether Odoo is functioning as expected, but what you should be testing is the feature of this addon—not Odoo's built-in functionality.

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.

Hi !

As mentioned here OCA/sale-workflow#4039 (comment) , I'm going to close this PR because I agree it's strange to have this module on its own, without a strong link to the "main" module.

However, and with the performance goal we all share here, I don't quite understand your comment: this test verifies that the filter is indeed present, which is precisely the role of this module.

Comment on lines +52 to +64
def test_02_invoice_with_company(self):
"""Test creating an invoice with a company partner"""
invoice = self.env["account.move"].create(
{
"partner_id": self.partner_company.id,
"move_type": "out_invoice",
}
)
self.assertEqual(
invoice.partner_id,
self.partner_company,
"Invoice should be created with company partner",
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Idem

Comment on lines +66 to +83
def test_03_individual_contact_excluded_by_domain(self):
"""Test that individual contacts are excluded by the view domain.

The domain restricts partner_id to companies only. A contact with
is_company=False must not appear in a search using that domain.
"""
domain = [("is_company", "=", True)]
results = self.env["res.partner"].search(domain)
self.assertIn(
self.partner_company,
results,
"Company partner should be included in restricted domain search",
)
self.assertNotIn(
self.individual_contact,
results,
"Individual contact should be excluded by the is_company domain",
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Similar to before. You're testing whether domains are correctly handled by Odoo—that's not a feature of your addon.

Comment on lines +8 to +13
<xpath expr="//field[@name='partner_id']" position="attributes">
<attribute
name="domain"
operation="domain_add"
>[('is_company', '=', True)]</attribute>
</xpath>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Are you sure this view is used only for invoices? I believe it's generally used for journal entries. Is that also your goal?

During the tests, you seemed interested only in the out_invoice type, so is this the correct implementation? Also, you're only limiting at this level. What about account.move records created via the API?

You need to think more carefully about your design.

@maisim
Copy link
Copy Markdown
Author

maisim commented Apr 10, 2026

Hi @rrebollo, thanx for your review.

The design and implementation still feel quite naive at this point. The base requirement may be valid, but you need to work on it a bit longer.

As mentioned in the first comment of this PR and in the documentation for this module:

This module is used by sale_partner_sale_contact (available in the
sale-workflow repository) to enforce proper commercial relationships while
allowing contact person tracking.

But I admit that:

  • The PR message should have described how it works.
  • This is probably not the right approach; it might be better to integrate it into the main module as an option that can be enabled in the settings.

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