Skip to content

Commit

Permalink
[CHG] re-introduce _get_next_ref method to allow overriding (OCA#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric Pigeon (ACSONE) authored and jesusVMayor committed Dec 13, 2017
1 parent 3b49b5f commit cca3e43
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions base_partner_sequence/models/partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,29 @@ class ResPartner(models.Model):

_inherit = 'res.partner'

@api.multi
def _get_next_ref(self, vals=None):
return self.env['ir.sequence'].next_by_code('res.partner')

@api.model
def create(self, vals):
if not vals.get('ref') and self._needsRef(vals=vals):
vals['ref'] = self.env['ir.sequence'].next_by_code('res.partner')
vals['ref'] = self._get_next_ref(vals=vals)
return super(ResPartner, self).create(vals)

@api.multi
def copy(self, default=None):
default = default or {}
if self._needsRef():
default['ref'] = self.env['ir.sequence'].\
next_by_code('res.partner')
default['ref'] = self._get_next_ref()
return super(ResPartner, self).copy(default)

@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'] = self.env['ir.sequence'].\
next_by_code('res.partner')
vals['ref'] = self._get_next_ref(vals=vals)

super(ResPartner, partner).write(vals)
return True
Expand Down

0 comments on commit cca3e43

Please sign in to comment.