[IMP] account: manual reconciliation

Improve the manual reconciliation widget:
previously when opening the reconciliation view from receivable or payable account, only entries having a partner where showned, now also shows entries with no partner. -> We still need to have one entry in debit and one in credit for the reconciliation widget to show something but partner is not necessary anymore.

When coming from the aged receivable or the partner followup and clicking "reconcile" we want to be able to see all entries for that partner that are not reconciled (before we only showed something if they were at least one debit and one credit entries for that partner). We added a new context key (all_entries) for that use case.

closes odoo/odoo#36879

Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
This commit is contained in:
Cedric Snauwaert
2019-09-19 07:56:09 +00:00
parent abbc44952d
commit d136a725b2
2 changed files with 37 additions and 25 deletions
+1 -6
View File
@@ -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',
+36 -19
View File
@@ -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',