Browse Source

[FIX] OCA reviews

pull/1003/head
Mourad Elhadj Mimoune 7 years ago
parent
commit
7ae3f0b5c4
  1. 15
      keychain/models/keychain_backend.py
  2. 1
      keychain/tests/test_keychain_backend.py
  3. 4
      keychain/views/keychain_view.xml

15
keychain/models/keychain_backend.py

@ -2,7 +2,7 @@
# © 2016 Akretion Sebastien Beau # © 2016 Akretion Sebastien Beau
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models, fields
from odoo import api, fields, models
from odoo.tools.config import config from odoo.tools.config import config
@ -17,11 +17,15 @@ class KeychainBackend(models.AbstractModel):
required=True) required=True)
data = fields.Serialized( data = fields.Serialized(
compute="_compute_keychain", compute="_compute_keychain",
inverse="_inverse_keychain")
inverse="_inverse_keychain",
help="Additionnal data as json")
@api.multi
def _get_technical_name(self): def _get_technical_name(self):
self.ensure_one()
return '%s,%s' % (self._name, self.id) return '%s,%s' % (self._name, self.id)
@api.multi
def _get_existing_keychain(self): def _get_existing_keychain(self):
self.ensure_one() self.ensure_one()
return self.env['keychain.account'].retrieve([ return self.env['keychain.account'].retrieve([
@ -29,7 +33,9 @@ class KeychainBackend(models.AbstractModel):
('technical_name', '=', self._get_technical_name()) ('technical_name', '=', self._get_technical_name())
]) ])
@api.multi
def _prepare_keychain(self): def _prepare_keychain(self):
self.ensure_one()
env = config.get('running_env') env = config.get('running_env')
return { return {
'name': "%s %s" % (self.name, env), 'name': "%s %s" % (self.name, env),
@ -38,6 +44,7 @@ class KeychainBackend(models.AbstractModel):
'environment': env, 'environment': env,
} }
@api.multi
def _get_keychain_account(self): def _get_keychain_account(self):
self.ensure_one() self.ensure_one()
account = self._get_existing_keychain() account = self._get_existing_keychain()
@ -46,12 +53,14 @@ class KeychainBackend(models.AbstractModel):
account = self.env['keychain.account'].create(vals) account = self.env['keychain.account'].create(vals)
return account return account
@api.multi
def _inverse_password(self): def _inverse_password(self):
for record in self: for record in self:
account = self._get_keychain_account() account = self._get_keychain_account()
if record.password and record.password != '******': if record.password and record.password != '******':
account.clear_password = record.password account.clear_password = record.password
@api.multi
def _compute_password(self): def _compute_password(self):
for record in self: for record in self:
account = record._get_existing_keychain() account = record._get_existing_keychain()
@ -60,11 +69,13 @@ class KeychainBackend(models.AbstractModel):
else: else:
record.password = "" record.password = ""
@api.multi
def _inverse_keychain(self): def _inverse_keychain(self):
for record in self: for record in self:
account = record._get_keychain_account() account = record._get_keychain_account()
account.data = account._serialize_data(record.data) account.data = account._serialize_data(record.data)
@api.multi
def _compute_keychain(self): def _compute_keychain(self):
for record in self: for record in self:
account = record._get_existing_keychain() account = record._get_existing_keychain()

1
keychain/tests/test_keychain_backend.py

@ -79,4 +79,3 @@ class TestKeychain(TransactionCase):
self.assertEqual( self.assertEqual(
account.technical_name, '%s,%s' % (backend._name, backend.id), account.technical_name, '%s,%s' % (backend._name, backend.id),
'Account technical_name is not correct') 'Account technical_name is not correct')

4
keychain/views/keychain_view.xml

@ -4,7 +4,7 @@
<field name="model">keychain.account</field> <field name="model">keychain.account</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Accounts">
<tree>
<field name="namespace"/> <field name="namespace"/>
<field name="name"/> <field name="name"/>
<field name="technical_name" /> <field name="technical_name" />
@ -18,7 +18,7 @@
<record model="ir.ui.view" id="keychain_account_form"> <record model="ir.ui.view" id="keychain_account_form">
<field name="model">keychain.account</field> <field name="model">keychain.account</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="Accounts form">
<form>
<group> <group>
<field name="namespace"/> <field name="namespace"/>
<field name="name" /> <field name="name" />

Loading…
Cancel
Save