Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][FIX] partner_firstname: fix installation w/ missing names #1678

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from

Conversation

mohs8421
Copy link

This change fixes this bug: #1677

With that the module can be installed as only partners with names will be processed

@mohs8421 mohs8421 changed the title Resolve issue blocking partner_firstname from installation [16.0][FIX] Resolve issue blocking partner_firstname from installation Mar 15, 2024
@simahawk simahawk changed the title [16.0][FIX] Resolve issue blocking partner_firstname from installation [16.0][FIX] partner_firstname: fix installation w/ missing names Apr 23, 2024
@simahawk
Copy link
Contributor

@mohs8421 could you please add a test for this change?
When you are done, could you please:

  1. squash your commits
  2. rewrite the commit message according to our guidelines https://github.com/OCA/odoo-community.org/blob/master/website/Contribution/CONTRIBUTING.rst#commit-message

Thanks!

@mohs8421
Copy link
Author

I tried to write a test for it, but it is not possible with the module in place to test this, as the module itself prevents that.
So when trying to create a test record to run _install_partner_firstname() afterwards, it already exits with the empty name error.
Yes, that's partly the point of this module, but it should not be that strict during installation.

For reference, here is the testcode:

    def test_module_installation(self):
        model = self.env[self.model].with_context(**self.context)
        unnamed = model.create({'name': '', 'email': '[email protected]'})
        named = model.create({'name': 'firstname lastname', 'email': '[email protected]'})
        model._install_partner_firstname()
        self.assertEqual(unnamed.name, '')
        self.assertEqual((named.firstname, named.lastname), ('firstname', 'lastname'))

Copy link
Member

@yvaucher yvaucher left a comment

Choose a reason for hiding this comment

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

LGTM, seems safer that way.

@SirAionTech
Copy link
Contributor

I tried to write a test for it, but it is not possible with the module in place to test this, as the module itself prevents that.
So when trying to create a test record to run _install_partner_firstname() afterwards, it already exits with the empty name error.
Yes, that's partly the point of this module, but it should not be that strict during installation.

For reference, here is the testcode:

    def test_module_installation(self):
        model = self.env[self.model].with_context(**self.context)
        unnamed = model.create({'name': '', 'email': '[email protected]'})
        named = model.create({'name': 'firstname lastname', 'email': '[email protected]'})
        model._install_partner_firstname()
        self.assertEqual(unnamed.name, '')
        self.assertEqual((named.firstname, named.lastname), ('firstname', 'lastname'))

You could mock whatever method is preventing you from creating unnamed, just while creating it, so that it's like you are creating the partner while the module is not installed yet.
You can see an example in https://github.com/OCA/account-invoicing/blob/86b9060ce96d91251f6a03bdc8021176880d3586/partner_invoicing_mode/tests/test_invoice_mode.py#L112:

with mock.patch.object(ResPartner, "_update_next_invoice_date") as mock_update:
    ...

Copy link

@CRogos CRogos left a comment

Choose a reason for hiding this comment

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

@mohs8421 I think your test is nearly working. I've added your test to the test_empty.py file and just added the contact "type": "invoice" because empty name is not allowed on all contact types. Than the tests run successfully.

class AddressCase(TransactionCase):

...

    def test_module_installation(self):
        """Create an invoice patner without name."""
        model = self.env["res.partner"]
        unnamed = model.create({'name': '', 'email': '[email protected]', "type": "invoice"})
        named = model.create({'name': 'firstname lastname', 'email': '[email protected]'})
        model._install_partner_firstname()
        self.assertEqual(unnamed.name, '')
        self.assertEqual((named.firstname, named.lastname), ('firstname', 'lastname'))
        

If you add your tests, and squash all commits, I will also approve this PR.

Resolve issue blocking partner_firstname from installation

This change fixes this bug: OCA#1677

With that the module can be installed as only partners with names will be processed
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.

5 participants