Browse Source

Merge pull request #686 from acsone/12.0-fix_unique_ref_on_write

[12.0][base_partner_sequence] fix unique ref on write
pull/687/merge
Pedro M. Baeza 6 years ago
committed by GitHub
parent
commit
f7aad664f6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      base_partner_sequence/models/partner.py
  2. 13
      base_partner_sequence/tests/test_base_partner_sequence.py

12
base_partner_sequence/models/partner.py

@ -32,10 +32,14 @@ class ResPartner(models.Model):
@api.multi @api.multi
def write(self, vals): def write(self, vals):
for partner in self: 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 return True
@api.multi @api.multi

13
base_partner_sequence/tests/test_base_partner_sequence.py

@ -33,3 +33,16 @@ class TestBasePartnerSequence(common.TransactionCase):
self.assertEqual( self.assertEqual(
self.partner.ref, contact.ref, "All it's ok as sequence doesn't " self.partner.ref, contact.ref, "All it's ok as sequence doesn't "
"increase.") "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)
Loading…
Cancel
Save