Browse Source

calcul key en lettre

master
root 3 years ago
parent
commit
dcecd4d03c
1 changed files with 47 additions and 6 deletions
  1. +47
    -6
      models/partner.py

+ 47
- 6
models/partner.py View File

@ -118,7 +118,6 @@ class partner(models.Model):
) )
key=fields.Char( key=fields.Char(
compute='_compute_key',
string="Key", string="Key",
store=True, store=True,
readonly=True readonly=True
@ -128,15 +127,57 @@ class partner(models.Model):
npai_count=fields.Integer(String="NPAI count", readonly=True) npai_count=fields.Integer(String="NPAI count", readonly=True)
source=fields.Char(String="source") source=fields.Char(String="source")
def _alpha(self,id):
alpha={}
alpha[1]='A'
alpha[2]='B'
alpha[3]='C'
alpha[4]='D'
alpha[5]='E'
alpha[6]='F'
alpha[7]='G'
alpha[8]='H'
alpha[9]='I'
alpha[10]='J'
alpha[11]='K'
alpha[12]='L'
alpha[13]='M'
alpha[14]='N'
alpha[15]='O'
alpha[16]='P'
alpha[17]='Q'
alpha[18]='R'
alpha[19]='S'
alpha[20]='T'
alpha[21]='U'
alpha[22]='V'
alpha[23]='W'
alpha[24]='X'
alpha[25]='Y'
alpha[26]='Z'
return (alpha[id%26])
def _compute_key(self): def _compute_key(self):
for rec in self:
rec.key=int(rec.id)*40456
self.key==self._alpha(int(self.id))
@api.model
def create(self, values):
# Override the original create function for the res.partner model
record = super(partner, self).create(values)
# Change the values of a variable in this super function
record['key'] = self._alpha(int(record.id))
# Return the record so that the changes are applied and everything is stored.
return record
def _compute_all_key(self): def _compute_all_key(self):
for rec in self.env['res.partner'].search([]):
rec.key=int(rec.id)*40456
for rec in self.env['res.partner'].search([]):
rec.key=self._alpha(int(rec.id))
def _update_source(self): def _update_source(self):


Loading…
Cancel
Save