[13.0][FIX]multi-company fix

This commit is contained in:
Luc De Meyer 2020-07-18 17:43:35 +02:00
parent 11f66002d5
commit da3429f1d5
2 changed files with 30 additions and 8 deletions

View File

@ -3,7 +3,7 @@
{ {
'name': 'EBICS banking protocol', 'name': 'EBICS banking protocol',
'version': '13.0.1.1.0', 'version': '13.0.1.1.1',
'license': 'LGPL-3', 'license': 'LGPL-3',
'author': 'Noviat', 'author': 'Noviat',
'category': 'Accounting & Finance', 'category': 'Accounting & Finance',

View File

@ -86,6 +86,10 @@ class EbicsFile(models.Model):
def process(self): def process(self):
self.ensure_one() self.ensure_one()
ctx = dict(
self.env.context,
allowed_company_ids=self.env.user.company_ids.ids)
self = self.with_context(ctx)
self.note_process = '' self.note_process = ''
ff_methods = self._file_format_methods() ff_methods = self._file_format_methods()
ff = self.format_id.name ff = self.format_id.name
@ -157,18 +161,36 @@ class EbicsFile(models.Model):
self.note_process += '\n' self.note_process += '\n'
self.note_process += '\n' self.note_process += '\n'
if st_line_ids: if st_line_ids:
self.flush()
self.env.cr.execute( self.env.cr.execute(
""" """
SELECT DISTINCT statement_id SELECT DISTINCT
FROM account_bank_statement_line absl.statement_id,
WHERE id IN %s abs.name, abs.date, abs.company_id,
rc.name AS company_name
FROM account_bank_statement_line absl
INNER JOIN account_bank_statement abs
ON abs.id = absl.statement_id
INNER JOIN res_company rc
ON rc.id = abs.company_id
WHERE absl.id IN %s
ORDER BY date, company_id
""", """,
(tuple(st_line_ids),) (tuple(st_line_ids),)
) )
statement_ids = [x[0] for x in self.env.cr.fetchall()] sts_data = self.env.cr.dictfetchall()
self.note_process += _( else:
"Number of Bank Statements: %s" sts_data = []
) % len(statement_ids) st_cnt = len(sts_data)
if st_cnt:
self.note_process += _(
"%s bank statements have been imported: "
) % st_cnt
self.note_process += '\n'
for st_data in sts_data:
self.note_process += ("\n%s, %s (%s)") % (
st_data['date'], st_data['name'], st_data['company_name'])
statement_ids = [x['statement_id'] for x in sts_data]
if statement_ids: if statement_ids:
self.sudo().bank_statement_ids = [(6, 0, statement_ids)] self.sudo().bank_statement_ids = [(6, 0, statement_ids)]
ctx = dict(self.env.context, statement_ids=statement_ids) ctx = dict(self.env.context, statement_ids=statement_ids)