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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
21 additions and
4 deletions
-
base_partner_sequence/models/partner.py
-
base_partner_sequence/tests/test_base_partner_sequence.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 |
|
|
|
@ -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) |