Browse Source

[CHG] re-introduce _get_next_ref method to allow overriding (#417)

pull/668/head
Cédric Pigeon (ACSONE) 8 years ago
committed by Quentin Groulard
parent
commit
8cdd34abbd
  1. 12
      base_partner_sequence/models/partner.py

12
base_partner_sequence/models/partner.py

@ -30,18 +30,21 @@ class ResPartner(models.Model):
_inherit = 'res.partner' _inherit = 'res.partner'
@api.multi
def _get_next_ref(self, vals=None):
return self.env['ir.sequence'].next_by_code('res.partner')
@api.model @api.model
def create(self, vals): def create(self, vals):
if not vals.get('ref') and self._needsRef(vals=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) return super(ResPartner, self).create(vals)
@api.multi @api.multi
def copy(self, default=None): def copy(self, default=None):
default = default or {} default = default or {}
if self._needsRef(): 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) return super(ResPartner, self).copy(default)
@api.multi @api.multi
@ -49,8 +52,7 @@ class ResPartner(models.Model):
for partner in self: for partner in self:
if not vals.get('ref') and partner._needsRef(vals) and \ if not vals.get('ref') and partner._needsRef(vals) and \
not partner.ref: 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) super(ResPartner, partner).write(vals)
return True return True

Loading…
Cancel
Save