mirror of
https://github.com/brain-tec/account_ebics.git
synced 2024-11-22 12:12:03 +00:00
various fixes
This commit is contained in:
parent
113caae673
commit
f16e81f0a4
@ -131,8 +131,7 @@ class EbicsUserID(models.Model):
|
|||||||
rec.ebics_keys_fn = (
|
rec.ebics_keys_fn = (
|
||||||
rec.name
|
rec.name
|
||||||
and keys_dir
|
and keys_dir
|
||||||
and os.path.isfile(
|
and (keys_dir + '/' + rec.name + '_keys'))
|
||||||
keys_dir + '/' + rec.name + '_keys'))
|
|
||||||
|
|
||||||
@api.depends('ebics_keys_fn')
|
@api.depends('ebics_keys_fn')
|
||||||
def _compute_ebics_keys_found(self):
|
def _compute_ebics_keys_found(self):
|
||||||
@ -152,6 +151,9 @@ class EbicsUserID(models.Model):
|
|||||||
def set_to_draft(self):
|
def set_to_draft(self):
|
||||||
return self.write({'state': 'draft'})
|
return self.write({'state': 'draft'})
|
||||||
|
|
||||||
|
def set_to_active_keys(self):
|
||||||
|
return self.write({'state': 'active_keys'})
|
||||||
|
|
||||||
def set_to_get_bank_keys(self):
|
def set_to_get_bank_keys(self):
|
||||||
return self.write({'state': 'get_bank_keys'})
|
return self.write({'state': 'get_bank_keys'})
|
||||||
|
|
||||||
@ -161,7 +163,7 @@ class EbicsUserID(models.Model):
|
|||||||
Create new keys and certificates for this user
|
Create new keys and certificates for this user
|
||||||
"""
|
"""
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
self._check_ebics_files()
|
self.ebics_config_id._check_ebics_files()
|
||||||
if self.state != 'draft':
|
if self.state != 'draft':
|
||||||
raise UserError(
|
raise UserError(
|
||||||
_("Set state to 'draft' before Bank Key (re)initialisation."))
|
_("Set state to 'draft' before Bank Key (re)initialisation."))
|
||||||
@ -172,12 +174,15 @@ class EbicsUserID(models.Model):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
keyring = EbicsKeyRing(
|
keyring = EbicsKeyRing(
|
||||||
keys=self.ebics_keys,
|
keys=self.ebics_keys_fn,
|
||||||
passphrase=self.ebics_passphrase)
|
passphrase=self.ebics_passphrase)
|
||||||
bank = EbicsBank(
|
bank = EbicsBank(
|
||||||
keyring=keyring, hostid=self.ebics_host, url=self.ebics_url)
|
keyring=keyring,
|
||||||
|
hostid=self.ebics_config_id.ebics_host,
|
||||||
|
url=self.ebics_config_id.ebics_url)
|
||||||
user = EbicsUser(
|
user = EbicsUser(
|
||||||
keyring=keyring, partnerid=self.ebics_partner,
|
keyring=keyring,
|
||||||
|
partnerid=self.ebics_config_id.ebics_partner,
|
||||||
userid=self.name)
|
userid=self.name)
|
||||||
except Exception:
|
except Exception:
|
||||||
exctype, value = exc_info()[:2]
|
exctype, value = exc_info()[:2]
|
||||||
@ -185,12 +190,12 @@ class EbicsUserID(models.Model):
|
|||||||
error += '\n' + str(exctype) + '\n' + str(value)
|
error += '\n' + str(exctype) + '\n' + str(value)
|
||||||
raise UserError(error)
|
raise UserError(error)
|
||||||
|
|
||||||
self._check_ebics_keys()
|
self.ebics_config_id._check_ebics_keys()
|
||||||
if not os.path.isfile(self.ebics_keys):
|
if not os.path.isfile(self.ebics_keys_fn):
|
||||||
try:
|
try:
|
||||||
user.create_keys(
|
user.create_keys(
|
||||||
keyversion=self.ebics_key_version,
|
keyversion=self.ebics_config_id.ebics_key_version,
|
||||||
bitlength=self.ebics_key_bitlength)
|
bitlength=self.ebics_config_id.ebics_key_bitlength)
|
||||||
except Exception:
|
except Exception:
|
||||||
exctype, value = exc_info()[:2]
|
exctype, value = exc_info()[:2]
|
||||||
error = _("EBICS Initialisation Error:")
|
error = _("EBICS Initialisation Error:")
|
||||||
@ -210,17 +215,18 @@ class EbicsUserID(models.Model):
|
|||||||
kwargs = {k: v for k, v in dn_attrs.items() if v}
|
kwargs = {k: v for k, v in dn_attrs.items() if v}
|
||||||
user.create_certificates(**kwargs)
|
user.create_certificates(**kwargs)
|
||||||
|
|
||||||
client = EbicsClient(bank, user, version=self.ebics_version)
|
client = EbicsClient(
|
||||||
|
bank, user, version=self.ebics_config_id.ebics_version)
|
||||||
|
|
||||||
# Send the public electronic signature key to the bank.
|
# Send the public electronic signature key to the bank.
|
||||||
try:
|
try:
|
||||||
if self.ebics_version == 'H003':
|
if self.ebics_config_id.ebics_version == 'H003':
|
||||||
bank._order_number = self._get_order_number()
|
bank._order_number = self.ebics_config_id._get_order_number()
|
||||||
OrderID = client.INI()
|
OrderID = client.INI()
|
||||||
_logger.info(
|
_logger.info(
|
||||||
'%s, EBICS INI command, OrderID=%s', self._name, OrderID)
|
'%s, EBICS INI command, OrderID=%s', self._name, OrderID)
|
||||||
if self.ebics_version == 'H003':
|
if self.ebics_version == 'H003':
|
||||||
self._update_order_number(OrderID)
|
self.ebics_config_id._update_order_number(OrderID)
|
||||||
except URLError:
|
except URLError:
|
||||||
exctype, value = exc_info()[:2]
|
exctype, value = exc_info()[:2]
|
||||||
raise UserError(_(
|
raise UserError(_(
|
||||||
@ -240,29 +246,31 @@ class EbicsUserID(models.Model):
|
|||||||
raise UserError(error)
|
raise UserError(error)
|
||||||
|
|
||||||
# Send the public authentication and encryption keys to the bank.
|
# Send the public authentication and encryption keys to the bank.
|
||||||
if self.ebics_version == 'H003':
|
if self.ebics_config_id.ebics_version == 'H003':
|
||||||
bank._order_number = self._get_order_number()
|
bank._order_number = self.ebics_config_id._get_order_number()
|
||||||
OrderID = client.HIA()
|
OrderID = client.HIA()
|
||||||
_logger.info('%s, EBICS HIA command, OrderID=%s', self._name, OrderID)
|
_logger.info('%s, EBICS HIA command, OrderID=%s', self._name, OrderID)
|
||||||
if self.ebics_version == 'H003':
|
if self.ebics_version == 'H003':
|
||||||
self._update_order_number(OrderID)
|
self.ebics_config_id._update_order_number(OrderID)
|
||||||
|
|
||||||
# Create an INI-letter which must be printed and sent to the bank.
|
# Create an INI-letter which must be printed and sent to the bank.
|
||||||
cc = self.bank_id.bank_id.country.code
|
bank = self.ebics_config_id.journal_ids[0].bank_id
|
||||||
|
cc = bank.country.code
|
||||||
if cc in ['FR', 'DE']:
|
if cc in ['FR', 'DE']:
|
||||||
lang = cc
|
lang = cc
|
||||||
else:
|
else:
|
||||||
lang = self.env.user.lang or \
|
lang = self.env.user.lang or \
|
||||||
self.env['res.lang'].search([])[0].code
|
self.env['res.lang'].search([])[0].code
|
||||||
lang = lang[:2]
|
lang = lang[:2]
|
||||||
tmp_dir = os.path.normpath(self.ebics_files + '/tmp')
|
tmp_dir = os.path.normpath(self.ebics_config_id.ebics_files + '/tmp')
|
||||||
if not os.path.isdir(tmp_dir):
|
if not os.path.isdir(tmp_dir):
|
||||||
os.makedirs(tmp_dir, mode=0o700)
|
os.makedirs(tmp_dir, mode=0o700)
|
||||||
fn_date = fields.Date.today().isoformat()
|
fn_date = fields.Date.today().isoformat()
|
||||||
fn = '_'.join([self.ebics_host, 'ini_letter', fn_date]) + '.pdf'
|
fn = '_'.join(
|
||||||
|
[self.ebics_config_id.ebics_host, 'ini_letter', fn_date]) + '.pdf'
|
||||||
full_tmp_fn = os.path.normpath(tmp_dir + '/' + fn)
|
full_tmp_fn = os.path.normpath(tmp_dir + '/' + fn)
|
||||||
user.create_ini_letter(
|
user.create_ini_letter(
|
||||||
bankname=self.bank_id.bank_id.name,
|
bankname=bank.name,
|
||||||
path=full_tmp_fn,
|
path=full_tmp_fn,
|
||||||
lang=lang)
|
lang=lang)
|
||||||
with open(full_tmp_fn, 'rb') as f:
|
with open(full_tmp_fn, 'rb') as f:
|
||||||
@ -293,27 +301,32 @@ class EbicsUserID(models.Model):
|
|||||||
must be downloaded and checked for consistency.
|
must be downloaded and checked for consistency.
|
||||||
"""
|
"""
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
self._check_ebics_files()
|
self.ebics_config_id._check_ebics_files()
|
||||||
if self.state != 'get_bank_keys':
|
if self.state != 'get_bank_keys':
|
||||||
raise UserError(
|
raise UserError(
|
||||||
_("Set state to 'Get Keys from Bank'."))
|
_("Set state to 'Get Keys from Bank'."))
|
||||||
keyring = EbicsKeyRing(
|
keyring = EbicsKeyRing(
|
||||||
keys=self.ebics_keys, passphrase=self.ebics_passphrase)
|
keys=self.ebics_keys_fn, passphrase=self.ebics_passphrase)
|
||||||
bank = EbicsBank(
|
bank = EbicsBank(
|
||||||
keyring=keyring, hostid=self.ebics_host, url=self.ebics_url)
|
keyring=keyring,
|
||||||
|
hostid=self.ebics_config_id.ebics_host,
|
||||||
|
url=self.ebics_config_id.ebics_url)
|
||||||
user = EbicsUser(
|
user = EbicsUser(
|
||||||
keyring=keyring, partnerid=self.ebics_partner,
|
keyring=keyring,
|
||||||
|
partnerid=self.ebics_config_id.ebics_partner,
|
||||||
userid=self.name)
|
userid=self.name)
|
||||||
client = EbicsClient(
|
client = EbicsClient(
|
||||||
bank, user, version=self.ebics_version)
|
bank, user, version=self.ebics_config_id.ebics_version)
|
||||||
|
|
||||||
public_bank_keys = client.HPB()
|
public_bank_keys = client.HPB()
|
||||||
public_bank_keys = public_bank_keys.encode()
|
public_bank_keys = public_bank_keys.encode()
|
||||||
tmp_dir = os.path.normpath(self.ebics_files + '/tmp')
|
tmp_dir = os.path.normpath(self.ebics_config_id.ebics_files + '/tmp')
|
||||||
if not os.path.isdir(tmp_dir):
|
if not os.path.isdir(tmp_dir):
|
||||||
os.makedirs(tmp_dir, mode=0o700)
|
os.makedirs(tmp_dir, mode=0o700)
|
||||||
fn_date = fields.Date.today().isoformat()
|
fn_date = fields.Date.today().isoformat()
|
||||||
fn = '_'.join([self.ebics_host, 'public_bank_keys', fn_date]) + '.txt'
|
fn = '_'.join(
|
||||||
|
[self.ebics_config_id.ebics_host, 'public_bank_keys', fn_date]
|
||||||
|
) + '.txt'
|
||||||
self.write({
|
self.write({
|
||||||
'ebics_public_bank_keys': base64.encodestring(public_bank_keys),
|
'ebics_public_bank_keys': base64.encodestring(public_bank_keys),
|
||||||
'ebics_public_bank_keys_fn': fn,
|
'ebics_public_bank_keys_fn': fn,
|
||||||
@ -334,15 +347,17 @@ class EbicsUserID(models.Model):
|
|||||||
_("Set state to 'Verification'."))
|
_("Set state to 'Verification'."))
|
||||||
|
|
||||||
keyring = EbicsKeyRing(
|
keyring = EbicsKeyRing(
|
||||||
keys=self.ebics_keys, passphrase=self.ebics_passphrase)
|
keys=self.ebics_keys_fn, passphrase=self.ebics_passphrase)
|
||||||
bank = EbicsBank(
|
bank = EbicsBank(
|
||||||
keyring=keyring, hostid=self.ebics_host, url=self.ebics_url)
|
keyring=keyring,
|
||||||
|
hostid=self.ebics_config_id.ebics_host,
|
||||||
|
url=self.ebics_config_id.ebics_url)
|
||||||
bank.activate_keys()
|
bank.activate_keys()
|
||||||
return self.write({'state': 'active_keys'})
|
return self.write({'state': 'active_keys'})
|
||||||
|
|
||||||
def change_passphrase(self):
|
def change_passphrase(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
ctx = dict(self._context, default_ebics_config_id=self.id)
|
ctx = dict(self._context, default_ebics_userid_id=self.id)
|
||||||
module = __name__.split('addons.')[1].split('.')[0]
|
module = __name__.split('addons.')[1].split('.')[0]
|
||||||
view = self.env.ref(
|
view = self.env.ref(
|
||||||
'%s.ebics_change_passphrase_view_form' % module)
|
'%s.ebics_change_passphrase_view_form' % module)
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
<field name="name">EBICS File model company rule</field>
|
<field name="name">EBICS File model company rule</field>
|
||||||
<field name="model_id" ref="model_ebics_file"/>
|
<field name="model_id" ref="model_ebics_file"/>
|
||||||
<field eval="True" name="global"/>
|
<field eval="True" name="global"/>
|
||||||
<field name="domain_force">['|', ('company_ids', '=', False), ('company_isd', 'in', user.company_ids.ids)]</field>
|
<field name="domain_force">['|', ('company_ids', '=', False), ('company_ids', 'in', user.company_ids.ids)]</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
|
@ -30,10 +30,12 @@
|
|||||||
help="EBICS Initialisation - Push this button when the public have been checked for consistency."/>
|
help="EBICS Initialisation - Push this button when the public have been checked for consistency."/>
|
||||||
<button name="change_passphrase" string="Change Passphrase" type="object" class="oe_highlight"
|
<button name="change_passphrase" string="Change Passphrase" type="object" class="oe_highlight"
|
||||||
attrs="{'invisible': [('ebics_keys_found', '=', False)]}"/>
|
attrs="{'invisible': [('ebics_keys_found', '=', False)]}"/>
|
||||||
<button name="set_to_draft" states="active" string="Set to Draft" type="object"
|
<button name="set_to_draft" states="active_keys" string="Set to Draft" type="object"
|
||||||
help="Set to Draft in order to reinitialize your bank connection."/>
|
help="Set to Draft in order to reinitialize your bank connection."/>
|
||||||
<button name="set_to_get_bank_keys" states="active" string="Renew Bank Keys" type="object"
|
<button name="set_to_get_bank_keys" states="active_keys" string="Renew Bank Keys" type="object"
|
||||||
help="Use this button to update the EBICS certificates of your bank."/>
|
help="Use this button to update the EBICS certificates of your bank."/>
|
||||||
|
<button name="set_to_active_keys" states="draft" string="Force Active Keys" type="object"
|
||||||
|
help="Use this button to bypass the EBICS initialization (e.g. in case you have manually transferred active EBICS keys from another system."/>
|
||||||
<field name="state" widget="statusbar"/>
|
<field name="state" widget="statusbar"/>
|
||||||
</header>
|
</header>
|
||||||
<group name="main">
|
<group name="main">
|
||||||
|
@ -20,9 +20,9 @@ class EbicsChangePassphrase(models.TransientModel):
|
|||||||
_name = 'ebics.change.passphrase'
|
_name = 'ebics.change.passphrase'
|
||||||
_description = 'Change EBICS keys passphrase'
|
_description = 'Change EBICS keys passphrase'
|
||||||
|
|
||||||
ebics_config_id = fields.Many2one(
|
ebics_userid_id = fields.Many2one(
|
||||||
comodel_name='ebics.config',
|
comodel_name='ebics.userid',
|
||||||
string='EBICS Configuration',
|
string='EBICS UserID',
|
||||||
readonly=True)
|
readonly=True)
|
||||||
old_pass = fields.Char(
|
old_pass = fields.Char(
|
||||||
string='Old Passphrase',
|
string='Old Passphrase',
|
||||||
@ -37,23 +37,23 @@ class EbicsChangePassphrase(models.TransientModel):
|
|||||||
|
|
||||||
def change_passphrase(self):
|
def change_passphrase(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
if self.old_pass != self.ebics_config_id.ebics_passphrase:
|
if self.old_pass != self.ebics_userid_id.ebics_passphrase:
|
||||||
raise UserError(_(
|
raise UserError(_(
|
||||||
"Incorrect old passphrase."))
|
"Incorrect old passphrase."))
|
||||||
if self.new_pass != self.new_pass_check:
|
if self.new_pass != self.new_pass_check:
|
||||||
raise UserError(_(
|
raise UserError(_(
|
||||||
"New passphrase verification error."))
|
"New passphrase verification error."))
|
||||||
if self.new_pass == self.ebics_config_id.ebics_passphrase:
|
if self.new_pass == self.ebics_userid_id.ebics_passphrase:
|
||||||
raise UserError(_(
|
raise UserError(_(
|
||||||
"New passphrase equal to old passphrase."))
|
"New passphrase equal to old passphrase."))
|
||||||
try:
|
try:
|
||||||
keyring = EbicsKeyRing(
|
keyring = EbicsKeyRing(
|
||||||
keys=self.ebics_config_id.ebics_keys,
|
keys=self.ebics_userid_id.ebics_keys_fn,
|
||||||
passphrase=self.ebics_config_id.ebics_passphrase)
|
passphrase=self.ebics_userid_id.ebics_passphrase)
|
||||||
keyring.change_passphrase(self.new_pass)
|
keyring.change_passphrase(self.new_pass)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise UserError(str(e))
|
raise UserError(str(e))
|
||||||
self.ebics_config_id.ebics_passphrase = self.new_pass
|
self.ebics_userid.ebics_passphrase = self.new_pass
|
||||||
self.note = "The EBICS Passphrase has been changed."
|
self.note = "The EBICS Passphrase has been changed."
|
||||||
|
|
||||||
module = __name__.split('addons.')[1].split('.')[0]
|
module = __name__.split('addons.')[1].split('.')[0]
|
||||||
|
@ -277,10 +277,10 @@ class EbicsXfer(models.TransientModel):
|
|||||||
and getattr(client, order_type)
|
and getattr(client, order_type)
|
||||||
if order_type == 'FUL':
|
if order_type == 'FUL':
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
# bank = self.ebics_config_id.bank_id.bank v8.0
|
bank = self.ebics_config_id.journal_ids[0].bank_id
|
||||||
bank = self.ebics_config_id.bank_id.bank_id
|
cc = bank.country.code
|
||||||
if bank.country:
|
if cc:
|
||||||
kwargs['country'] = bank.country.code
|
kwargs['country'] = cc
|
||||||
if self.test_mode:
|
if self.test_mode:
|
||||||
kwargs['TEST'] = 'TRUE'
|
kwargs['TEST'] = 'TRUE'
|
||||||
OrderID = method(ef_format.name, upload_data, **kwargs)
|
OrderID = method(ef_format.name, upload_data, **kwargs)
|
||||||
@ -298,7 +298,7 @@ class EbicsXfer(models.TransientModel):
|
|||||||
"EBICS File has been uploaded (OrderID %s)."
|
"EBICS File has been uploaded (OrderID %s)."
|
||||||
) % OrderID
|
) % OrderID
|
||||||
ef_note = _("EBICS OrderID: %s") % OrderID
|
ef_note = _("EBICS OrderID: %s") % OrderID
|
||||||
if self._context.get('origin'):
|
if self.env.context.get('origin'):
|
||||||
ef_note += '\n' + _(
|
ef_note += '\n' + _(
|
||||||
"Origin: %s") % self._context['origin']
|
"Origin: %s") % self._context['origin']
|
||||||
suffix = self.format_id.suffix
|
suffix = self.format_id.suffix
|
||||||
@ -351,7 +351,7 @@ class EbicsXfer(models.TransientModel):
|
|||||||
self.ebics_config_id._check_ebics_keys()
|
self.ebics_config_id._check_ebics_keys()
|
||||||
passphrase = self._get_passphrase()
|
passphrase = self._get_passphrase()
|
||||||
keyring = EbicsKeyRing(
|
keyring = EbicsKeyRing(
|
||||||
keys=self.ebics_config_id.ebics_keys,
|
keys=self.ebics_userid_id.ebics_keys_fn,
|
||||||
passphrase=passphrase)
|
passphrase=passphrase)
|
||||||
|
|
||||||
bank = EbicsBank(
|
bank = EbicsBank(
|
||||||
@ -364,9 +364,9 @@ class EbicsXfer(models.TransientModel):
|
|||||||
user = EbicsUser(
|
user = EbicsUser(
|
||||||
keyring=keyring,
|
keyring=keyring,
|
||||||
partnerid=self.ebics_config_id.ebics_partner,
|
partnerid=self.ebics_config_id.ebics_partner,
|
||||||
userid=self.ebics_config_id.ebics_user)
|
userid=self.ebics_userid_id.name)
|
||||||
signature_class = self.format_id.signature_class \
|
signature_class = self.format_id.signature_class \
|
||||||
or self.ebics_config_id.signature_class
|
or self.ebics_userid_id.signature_class
|
||||||
if signature_class == 'T':
|
if signature_class == 'T':
|
||||||
user.manual_approval = True
|
user.manual_approval = True
|
||||||
|
|
||||||
@ -383,7 +383,7 @@ class EbicsXfer(models.TransientModel):
|
|||||||
return client
|
return client
|
||||||
|
|
||||||
def _get_passphrase(self):
|
def _get_passphrase(self):
|
||||||
passphrase = self.ebics_config_id.ebics_passphrase
|
passphrase = self.ebics_userid_id.ebics_passphrase
|
||||||
|
|
||||||
if passphrase:
|
if passphrase:
|
||||||
return passphrase
|
return passphrase
|
||||||
|
Loading…
Reference in New Issue
Block a user