[16.0][FIX] partner_firstname: fix installation w/ missing names
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 could you please add a test for this change? When you are done, could you please:
- squash your commits
- rewrite the commit message according to our guidelines https://github.com/OCA/odoo-community.org/blob/master/website/Contribution/CONTRIBUTING.rst#commit-message
Thanks!
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'))
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:
...
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.