diff --git a/addons/account/models/account.py b/addons/account/models/account.py index e2301af91d3..fb8c6d9cb2c 100644 --- a/addons/account/models/account.py +++ b/addons/account/models/account.py @@ -504,12 +504,7 @@ class AccountAccount(models.Model): def action_open_reconcile(self): self.ensure_one() # Open reconciliation view for this account - if self.internal_type == 'payable': - action_context = {'show_mode_selector': False, 'mode': 'suppliers'} - elif self.internal_type == 'receivable': - action_context = {'show_mode_selector': False, 'mode': 'customers'} - else: - action_context = {'show_mode_selector': False, 'mode': 'accounts', 'account_ids': [self.id,]} + action_context = {'show_mode_selector': False, 'mode': 'accounts', 'account_ids': [self.id,]} return { 'type': 'ir.actions.client', 'tag': 'manual_reconciliation_view', diff --git a/addons/account/models/reconciliation_widget.py b/addons/account/models/reconciliation_widget.py index 367b8f82a93..a52aa1ee3b3 100644 --- a/addons/account/models/reconciliation_widget.py +++ b/addons/account/models/reconciliation_widget.py @@ -314,11 +314,16 @@ class AccountReconciliation(models.AbstractModel): 'customers': [], 'suppliers': [], } - + # If we have specified partner_ids, don't return the list of reconciliation for specific accounts as it will + # show entries that are not reconciled with other partner. Asking for a specific partner on a specific account + # is never done. + accounts_data = [] + if not partner_ids: + accounts_data = self.get_data_for_manual_reconciliation('account', account_ids) return { 'customers': self.get_data_for_manual_reconciliation('partner', partner_ids, 'receivable'), 'suppliers': self.get_data_for_manual_reconciliation('partner', partner_ids, 'payable'), - 'accounts': self.get_data_for_manual_reconciliation('account', account_ids), + 'accounts': accounts_data, } @api.model @@ -347,7 +352,32 @@ class AccountReconciliation(models.AbstractModel): is_partner = res_type == 'partner' res_alias = is_partner and 'p' or 'a' aml_ids = self._context.get('active_ids') and self._context.get('active_model') == 'account.move.line' and tuple(self._context.get('active_ids')) - + all_entries = self._context.get('all_entries', False) + all_entries_query = """ + AND EXISTS ( + SELECT NULL + FROM account_move_line l + WHERE l.account_id = a.id + {inner_where} + AND l.amount_residual != 0 + ) + """.format(inner_where=is_partner and 'AND l.partner_id = p.id' or ' ') + only_dual_entries_query = """ + AND EXISTS ( + SELECT NULL + FROM account_move_line l + WHERE l.account_id = a.id + {inner_where} + AND l.amount_residual > 0 + ) + AND EXISTS ( + SELECT NULL + FROM account_move_line l + WHERE l.account_id = a.id + {inner_where} + AND l.amount_residual < 0 + ) + """.format(inner_where=is_partner and 'AND l.partner_id = p.id' or ' ') query = (""" SELECT {select} account_id, account_name, account_code, max_date FROM ( @@ -368,21 +398,8 @@ class AccountReconciliation(models.AbstractModel): {where2} {where3} AND l.company_id = {company_id} - AND EXISTS ( - SELECT NULL - FROM account_move_line l - WHERE l.account_id = a.id - {inner_where} - AND l.amount_residual > 0 - ) - AND EXISTS ( - SELECT NULL - FROM account_move_line l - WHERE l.account_id = a.id - {inner_where} - AND l.amount_residual < 0 - ) {where4} + {where5} GROUP BY {group_by1} a.id, a.name, a.code {group_by2} {order_by} ) as s @@ -395,8 +412,8 @@ class AccountReconciliation(models.AbstractModel): where2=account_type and "AND at.type = %(account_type)s" or '', where3=res_ids and 'AND ' + res_alias + '.id in %(res_ids)s' or '', company_id=self.env.company.id, - inner_where=is_partner and 'AND l.partner_id = p.id' or ' ', - where4=aml_ids and 'AND l.id IN %(aml_ids)s' or '', + where4=aml_ids and 'AND l.id IN %(aml_ids)s' or ' ', + where5=all_entries and all_entries_query or only_dual_entries_query, group_by1=is_partner and 'l.partner_id, p.id,' or ' ', group_by2=is_partner and ', p.last_time_entries_checked' or ' ', order_by=is_partner and 'ORDER BY p.last_time_entries_checked' or 'ORDER BY a.code',