mirror of
https://github.com/brain-tec/account_ebics.git
synced 2024-11-23 12:42:04 +00:00
account_ebics - mulit-company fix company_ids field
This commit is contained in:
parent
d941794eff
commit
076e4328f8
@ -3,7 +3,7 @@
|
||||
|
||||
{
|
||||
"name": "EBICS banking protocol",
|
||||
"version": "15.0.1.0.1",
|
||||
"version": "15.0.1.1.0",
|
||||
"license": "LGPL-3",
|
||||
"author": "Noviat",
|
||||
"website": "https://www.noviat.com",
|
||||
|
54
account_ebics/migrations/15.0.1.1/pre-migration.py
Normal file
54
account_ebics/migrations/15.0.1.1/pre-migration.py
Normal file
@ -0,0 +1,54 @@
|
||||
# Copyright 2009-2022 Noviat.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
|
||||
def migrate(cr, version):
|
||||
if not version:
|
||||
return
|
||||
|
||||
cr.execute("select id from ebics_config")
|
||||
cfg_ids = [x[0] for x in cr.fetchall()]
|
||||
for cfg_id in cfg_ids:
|
||||
cr.execute(
|
||||
"""
|
||||
SELECT aj.company_id
|
||||
FROM account_journal_ebics_config_rel rel
|
||||
JOIN account_journal aj ON rel.account_journal_id = aj.id
|
||||
WHERE ebics_config_id = %s
|
||||
""",
|
||||
(cfg_id,),
|
||||
)
|
||||
new_cpy_ids = [x[0] for x in cr.fetchall()]
|
||||
cr.execute(
|
||||
"""
|
||||
SELECT res_company_id
|
||||
FROM ebics_config_res_company_rel
|
||||
WHERE ebics_config_id = %s
|
||||
""",
|
||||
(cfg_id,),
|
||||
)
|
||||
old_cpy_ids = [x[0] for x in cr.fetchall()]
|
||||
|
||||
to_add = []
|
||||
for cid in new_cpy_ids:
|
||||
if cid in old_cpy_ids:
|
||||
old_cpy_ids.remove(cid)
|
||||
else:
|
||||
to_add.append(cid)
|
||||
if old_cpy_ids:
|
||||
cr.execute(
|
||||
"""
|
||||
DELETE FROM ebics_config_res_company_rel
|
||||
WHERE res_company_id IN %s
|
||||
""",
|
||||
(tuple(old_cpy_ids),),
|
||||
)
|
||||
if to_add:
|
||||
for cid in to_add:
|
||||
cr.execute(
|
||||
"""
|
||||
INSERT INTO ebics_config_res_company_rel(ebics_config_id, res_company_id)
|
||||
VALUES (%s, %s);
|
||||
""",
|
||||
(cfg_id, cid),
|
||||
)
|
@ -28,6 +28,7 @@ class EbicsConfig(models.Model):
|
||||
)
|
||||
journal_ids = fields.Many2many(
|
||||
comodel_name="account.journal",
|
||||
relation="account_journal_ebics_config_rel",
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
string="Bank Accounts",
|
||||
@ -148,8 +149,9 @@ class EbicsConfig(models.Model):
|
||||
active = fields.Boolean(default=True)
|
||||
company_ids = fields.Many2many(
|
||||
comodel_name="res.company",
|
||||
relation="ebics_config_res_company_rel",
|
||||
string="Companies",
|
||||
required=True,
|
||||
readonly=True,
|
||||
help="Companies sharing this EBICS contract.",
|
||||
)
|
||||
|
||||
@ -181,9 +183,26 @@ class EbicsConfig(models.Model):
|
||||
)
|
||||
)
|
||||
|
||||
@api.onchange("journal_ids")
|
||||
def _onchange_journal_ids(self):
|
||||
self.company_ids = self.journal_ids.mapped("company_id")
|
||||
def write(self, vals):
|
||||
"""
|
||||
Due to the multi-company nature of the EBICS config we
|
||||
need to adapt the company_ids in the write method.
|
||||
"""
|
||||
if "journal_ids" not in vals:
|
||||
return super().write(vals)
|
||||
for rec in self:
|
||||
old_company_ids = rec.journal_ids.mapped("company_id").ids
|
||||
super(EbicsConfig, rec).write(vals)
|
||||
new_company_ids = rec.journal_ids.mapped("company_id").ids
|
||||
updates = []
|
||||
for cid in new_company_ids:
|
||||
if cid in old_company_ids:
|
||||
old_company_ids.remove(cid)
|
||||
else:
|
||||
updates += [(4, cid)]
|
||||
updates += [(3, x) for x in old_company_ids]
|
||||
super(EbicsConfig, rec).write({"company_ids": updates})
|
||||
return True
|
||||
|
||||
def unlink(self):
|
||||
for ebics_config in self:
|
||||
|
@ -245,6 +245,8 @@ class EbicsFile(models.Model):
|
||||
statement_ids = [x["statement_id"] for x in sts_data]
|
||||
if statement_ids:
|
||||
self.sudo().bank_statement_ids = [(4, x) for x in statement_ids]
|
||||
company_ids = self.sudo().bank_statement_ids.mapped("company_id").ids
|
||||
self.company_ids = [(6, 0, company_ids)]
|
||||
ctx = dict(self.env.context, statement_ids=statement_ids)
|
||||
module = __name__.split("addons.")[1].split(".")[0]
|
||||
result_view = self.env.ref("%s.ebics_file_view_form_result" % module)
|
||||
|
@ -68,8 +68,8 @@
|
||||
name="order_number"
|
||||
attrs="{'invisible': [('ebics_version', '!=', 'H003')]}"
|
||||
/>
|
||||
<field name="company_ids" widget="many2many_tags" invisible="1" />
|
||||
</group>
|
||||
<field name="company_ids" invisible="1" />
|
||||
</group>
|
||||
<notebook>
|
||||
<page string="EBICS Users" groups="account_ebics.group_ebics_manager">
|
||||
|
Loading…
Reference in New Issue
Block a user