summaryrefslogtreecommitdiff
path: root/addons/account/models
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2019-04-05 18:46:10 +0200
committerChristophe Simonis <chs@odoo.com>2019-04-05 18:46:10 +0200
commit3f95b074e959f0f4ac93fbf4048c0c7276f2c17a (patch)
treef4e793da5d83bcd1bd4347f71cb3f45cbc953df3 /addons/account/models
parent1a871d72438c731d08ef10e668b81b4ade900b85 (diff)
parentf2be461f0906ed47306da58c31240014b6239d80 (diff)
[MERGE] forward port branch saas-12.2 up to f2be461f090
Diffstat (limited to 'addons/account/models')
-rw-r--r--addons/account/models/account_bank_statement.py10
-rw-r--r--addons/account/models/reconciliation_widget.py11
2 files changed, 18 insertions, 3 deletions
diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py
index b63543a6b0f..487477dee6a 100644
--- a/addons/account/models/account_bank_statement.py
+++ b/addons/account/models/account_bank_statement.py
@@ -235,14 +235,18 @@ class AccountBankStatement(models.Model):
statements = self.filtered(lambda r: r.state == 'open')
for statement in statements:
moves = self.env['account.move']
+ # `line.journal_entry_ids` gets invalidated from the cache during the loop
+ # because new move lines are being created at each iteration.
+ # The below dict is to prevent the ORM to permanently refetch `line.journal_entry_ids`
+ line_journal_entries = {line: line.journal_entry_ids for line in statement.line_ids}
for st_line in statement.line_ids:
#upon bank statement confirmation, look if some lines have the account_id set. It would trigger a journal entry
#creation towards that account, with the wanted side-effect to skip that line in the bank reconciliation widget.
+ journal_entries = line_journal_entries[st_line]
st_line.fast_counterpart_creation()
- if not st_line.account_id and not st_line.journal_entry_ids.ids and not st_line.statement_id.currency_id.is_zero(st_line.amount):
+ if not st_line.account_id and not journal_entries.ids and not st_line.statement_id.currency_id.is_zero(st_line.amount):
raise UserError(_('All the account entries lines must be processed in order to close the statement.'))
- for aml in st_line.journal_entry_ids:
- moves |= aml.move_id
+ moves = statement.mapped('line_ids.journal_entry_ids.move_id')
if moves:
moves.filtered(lambda m: m.state != 'posted').post()
statement.message_post(body=_('Statement %s confirmed, journal items were created.') % (statement.name,))
diff --git a/addons/account/models/reconciliation_widget.py b/addons/account/models/reconciliation_widget.py
index 875a346dabd..4683afab86f 100644
--- a/addons/account/models/reconciliation_widget.py
+++ b/addons/account/models/reconciliation_widget.py
@@ -95,6 +95,17 @@ class AccountReconciliation(models.AbstractModel):
WHERE st_line.id IN %s
'''
params = [tuple(st_lines.ids)]
+
+ # Add the res.partner's IR rules to the WHERE clause. In case partners are not shared
+ # between companies, identical partners may exist in a company we don't have access to.
+ ir_rules_query = self.env['res.partner']._where_calc([])
+ self.env['res.partner']._apply_ir_rules(ir_rules_query, 'read')
+ from_clause, where_clause, where_clause_params = ir_rules_query.get_sql()
+ where_p3 = (" AND %s" % where_clause).replace('res_partner', 'p3') if where_clause else ''
+ if where_p3:
+ query += where_p3
+ params += where_clause_params
+
self._cr.execute(query, params)
result = {}