Browse Source

[FIX] - unique ref on write

pull/686/head
sbejaoui 6 years ago
parent
commit
e59555f8f7
  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
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

13
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)
Loading…
Cancel
Save