partner-contact icon indicating copy to clipboard operation
partner-contact copied to clipboard

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

Open mohs8421 opened this issue 1 year ago • 3 comments

This change fixes this bug: https://github.com/OCA/partner-contact/issues/1677

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

mohs8421 avatar Feb 28 '24 12:02 mohs8421

@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!

simahawk avatar Apr 23 '24 08:04 simahawk

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'))

mohs8421 avatar Apr 23 '24 13:04 mohs8421

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:
    ...

SirAionTech avatar Aug 26 '24 15:08 SirAionTech

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[bot] avatar Mar 16 '25 12:03 github-actions[bot]