[FIX] account: manual reconciliation widget was inversing debit/credit
Also add a lost functionality, when coming from payment view, pass account_move_line id to the context so that it is directly opened as a proposition in the reconciliation widget. If a matching line is found for that payment, also propose the matching line.
This commit is contained in:
committed by
qdp-odoo
parent
5d3cbf4d7a
commit
e1cbaf7af7
@@ -588,19 +588,40 @@ class AccountMoveLine(models.Model):
|
||||
@api.model
|
||||
def get_reconciliation_proposition(self, account_id, partner_id=False):
|
||||
""" Returns two lines whose amount are opposite """
|
||||
|
||||
target_currency = (self.currency_id and self.amount_currency) and self.currency_id or self.company_id.currency_id
|
||||
partner_id_condition = partner_id and 'AND a.partner_id = %(partner_id)s' or ''
|
||||
|
||||
rec_prop = self.env['account.move.line']
|
||||
# Get pairs
|
||||
partner_id_condition = partner_id and 'AND a.partner_id = %(partner_id)s AND b.partner_id = %(partner_id)s' or ''
|
||||
query = """
|
||||
SELECT a.id, b.id
|
||||
FROM account_move_line a, account_move_line b
|
||||
WHERE a.amount_residual = -b.amount_residual
|
||||
AND NOT a.reconciled AND NOT b.reconciled
|
||||
AND a.account_id = %(account_id)s AND b.account_id = %(account_id)s
|
||||
{partner_id_condition}
|
||||
ORDER BY a.date desc
|
||||
LIMIT 10
|
||||
""".format(**locals())
|
||||
move_line_id = self.env.context.get('move_line_id', False)
|
||||
if move_line_id:
|
||||
move_line = self.env['account.move.line'].browse(move_line_id)
|
||||
amount = move_line.amount_residual;
|
||||
rec_prop = move_line
|
||||
query = """
|
||||
SELECT a.id, a.id FROM account_move_line a
|
||||
WHERE a.amount_residual = -%(amount)s
|
||||
AND NOT a.reconciled
|
||||
AND a.account_id = %(account_id)s
|
||||
AND a.id != %(move_line_id)s
|
||||
{partner_id_condition}
|
||||
ORDER BY a.date desc
|
||||
LIMIT 10
|
||||
""".format(**locals())
|
||||
else:
|
||||
partner_id_condition = partner_id_condition and partner_id_condition+' AND b.partner_id = %(partner_id)s' or ''
|
||||
query = """
|
||||
SELECT a.id, b.id
|
||||
FROM account_move_line a, account_move_line b
|
||||
WHERE a.amount_residual = -b.amount_residual
|
||||
AND NOT a.reconciled AND NOT b.reconciled
|
||||
AND a.account_id = %(account_id)s AND b.account_id = %(account_id)s
|
||||
{partner_id_condition}
|
||||
ORDER BY a.date desc
|
||||
LIMIT 10
|
||||
""".format(**locals())
|
||||
|
||||
self.env.cr.execute(query, locals())
|
||||
pairs = self.env.cr.fetchall()
|
||||
|
||||
@@ -609,11 +630,12 @@ class AccountMoveLine(models.Model):
|
||||
allowed_ids = set(self.env['account.move.line'].browse(all_pair_ids).ids)
|
||||
pairs = [pair for pair in pairs if pair[0] in allowed_ids and pair[1] in allowed_ids]
|
||||
|
||||
# Return lines formatted
|
||||
if len(pairs) > 0:
|
||||
target_currency = (self.currency_id and self.amount_currency) and self.currency_id or self.company_id.currency_id
|
||||
lines = self.browse(list(pairs[0]))
|
||||
return lines.prepare_move_lines_for_reconciliation_widget(target_currency=target_currency)
|
||||
rec_prop += self.browse(list(set(pairs[0])))
|
||||
|
||||
if len(rec_prop) > 0:
|
||||
# Return lines formatted
|
||||
return rec_prop.prepare_move_lines_for_reconciliation_widget(target_currency=target_currency)
|
||||
return []
|
||||
|
||||
@api.model
|
||||
|
||||
@@ -231,11 +231,18 @@ class account_payment(models.Model):
|
||||
|
||||
def open_payment_matching_screen(self):
|
||||
# Open reconciliation view for customers/suppliers
|
||||
action_context = {'show_mode_selector': False, 'company_ids': [self.company_id.id], 'partner_ids': [self.partner_id.commercial_partner_id.id]}
|
||||
move_line_id = False
|
||||
for move_line in self.move_line_ids:
|
||||
if move_line.account_id.reconcile:
|
||||
move_line_id = move_line.id
|
||||
break;
|
||||
action_context = {'company_ids': [self.company_id.id], 'partner_ids': [self.partner_id.commercial_partner_id.id]}
|
||||
if self.partner_type == 'customer':
|
||||
action_context.update({'mode': 'customers'})
|
||||
elif self.partner_type == 'supplier':
|
||||
action_context.update({'mode': 'suppliers'})
|
||||
if move_line_id:
|
||||
action_context.update({'move_line_id': move_line_id})
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'manual_reconciliation_view',
|
||||
|
||||
@@ -1061,6 +1061,7 @@ var ManualModel = StatementModel.extend({
|
||||
model: 'account.move.line',
|
||||
method: 'get_data_for_manual_reconciliation',
|
||||
args: args,
|
||||
context: context,
|
||||
})
|
||||
.then(function (result) {
|
||||
var defs = _.map(result, self._formatLine.bind(self, context.mode));
|
||||
@@ -1073,6 +1074,7 @@ var ManualModel = StatementModel.extend({
|
||||
model: 'account.move.line',
|
||||
method: 'get_data_for_manual_reconciliation',
|
||||
args: ['account', self.account_ids],
|
||||
context: context,
|
||||
})
|
||||
.then(function (result) {
|
||||
var defs = _.map(result, self._formatLine.bind(self, 'accounts'));
|
||||
@@ -1091,6 +1093,7 @@ var ManualModel = StatementModel.extend({
|
||||
model: 'account.move.line',
|
||||
method: 'get_data_for_manual_reconciliation_widget',
|
||||
args: [partner_ids, account_ids],
|
||||
context: context,
|
||||
})
|
||||
.then(function (result) {
|
||||
var defs = _.map(result.accounts, self._formatLine.bind(self, 'accounts'));
|
||||
@@ -1269,6 +1272,10 @@ var ManualModel = StatementModel.extend({
|
||||
this._super(line, props);
|
||||
if (props.length) {
|
||||
_.each(props, function (prop) {
|
||||
var tmp_value = prop.debit || prop.credit;
|
||||
prop.credit = prop.credit !== 0 ? 0 : tmp_value;
|
||||
prop.debit = prop.debit !== 0 ? 0 : tmp_value;
|
||||
prop.amount = -prop.amount;
|
||||
prop.journal_id = self._formatNameGet(prop.journal_id || line.journal_id);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -995,9 +995,9 @@ QUnit.module('account', {
|
||||
" Agrolait 101200 ",
|
||||
"should display the partner and the account code as title");
|
||||
|
||||
assert.strictEqual(clientAction.$('.o_reconciliation_line:first .match tr:first .cell_left').text(),
|
||||
assert.strictEqual(clientAction.$('.o_reconciliation_line:first .match tr:first .cell_right').text(),
|
||||
"$ 11,000.00", "sould display the line in $");
|
||||
assert.strictEqual(clientAction.$('.o_reconciliation_line:first .match tr:first .cell_left .o_multi_currency').data('content'),
|
||||
assert.strictEqual(clientAction.$('.o_reconciliation_line:first .match tr:first .cell_right .o_multi_currency').data('content'),
|
||||
"10,222.00 €", "sould display the monetary information in €");
|
||||
|
||||
assert.strictEqual(clientAction.$('.accounting_view:first .o_no_valid:visible').length, 1, "should display the skip button");
|
||||
|
||||
Reference in New Issue
Block a user