diff --git a/base_partner_sequence/models/partner.py b/base_partner_sequence/models/partner.py index 29bbf9520..ef150eceb 100644 --- a/base_partner_sequence/models/partner.py +++ b/base_partner_sequence/models/partner.py @@ -32,10 +32,14 @@ class ResPartner(models.Model): @api.multi def write(self, vals): for partner in self: - if not vals.get('ref') and partner._needsRef(vals) and \ - not partner.ref: - vals['ref'] = partner._get_next_ref(vals=vals) - super(ResPartner, partner).write(vals) + partner_vals = vals.copy() + if ( + not partner_vals.get('ref') + and partner._needsRef(partner_vals) + and not partner.ref + ): + partner_vals['ref'] = partner._get_next_ref(vals=partner_vals) + super(ResPartner, partner).write(partner_vals) return True @api.multi diff --git a/base_partner_sequence/tests/test_base_partner_sequence.py b/base_partner_sequence/tests/test_base_partner_sequence.py index b5e479cf3..abf7d7885 100644 --- a/base_partner_sequence/tests/test_base_partner_sequence.py +++ b/base_partner_sequence/tests/test_base_partner_sequence.py @@ -33,3 +33,16 @@ class TestBasePartnerSequence(common.TransactionCase): self.assertEqual( self.partner.ref, contact.ref, "All it's ok as sequence doesn't " "increase.") + + def test_unique_ref_on_write(self): + """Assert that create and write gives a different refs if we """ + vals = [ + {'name': "test1", 'email': "test@test.com"}, + {'name': "test2", 'email': "test@test.com"}, + ] + partners = self.env['res.partner'].create(vals) + self.assertFalse(partners[0].ref == partners[1].ref) + partners.write({'ref': False}) + self.assertFalse(partners[0].ref) + partners.write({}) + self.assertFalse(partners[0].ref == partners[1].ref)