[FIX] account_voucher: force receivable/payable on payment

Create a voucher in pay_now mode
set another account that the one of the partner
Validate

Before this commit, the automatic payment and payment entries
were done in the account receivable/payable of the partner
which means that the voucher and the payment were never reconciled

After this commit, the payment and its entries occur in the same
payable/receivable than the voucher's

OPW 2056240

closes odoo/odoo#36232

Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
This commit is contained in:
Lucas Perais (lpe)
2019-08-29 12:32:17 +00:00
parent 25e881d629
commit cbe04c4df1
2 changed files with 70 additions and 1 deletions
@@ -422,7 +422,9 @@ class AccountVoucher(models.Model):
# Create a payment to allow the reconciliation when pay_now = 'pay_now'.
if voucher.pay_now == 'pay_now':
payment_id = self.env['account.payment'].create(voucher.voucher_pay_now_payment_create())
payment_id = (self.env['account.payment']
.with_context(force_counterpart_account=voucher.account_id.id)
.create(voucher.voucher_pay_now_payment_create()))
payment_id.post()
# Reconcile the receipt with the payment
@@ -545,3 +547,19 @@ class AccountVoucherLine(models.Model):
values['price_unit'] = values['price_unit'] * currency.rate
return {'value': values, 'domain': {}}
class AccountPayment(models.Model):
_inherit = 'account.payment'
# Allows to force the destination account
# for receivable/payable
#
# @override
def _get_counterpart_move_line_vals(self, invoice=False):
values = super(AccountPayment, self)._get_counterpart_move_line_vals(invoice)
if self._context.get('force_counterpart_account'):
values['account_id'] = self._context['force_counterpart_account']
return values
@@ -96,3 +96,54 @@ class TestAccountVoucher(common.TransactionCase):
self.assertEquals(vendor_voucher_move.journal_id, cash_journal_id, 'Journal is incorrect on account move.')
# Check amount in Account move line.
self.assertEquals(vendor_voucher_move.amount, 1000.0, 'Amount is incorrect in acccount move.')
def test_different_account_than_default(self):
self._load('account', 'test', 'account_minimal_test.xml')
# User-groups and References
cash_journal_id = self.env.ref('account_voucher.cash_journal')
sales_journal_id = self.env.ref('account_voucher.sales_journal')
account_receivable_id = self.env.ref('account_voucher.a_recv')
receivable_other = account_receivable_id.copy({
'name': 'Other Receivable',
'code': '666',
})
income_account = self.env['account.account'].create({
'name': 'income',
'code': '999',
'user_type_id': self.env.ref('account.data_account_type_other_income').id,
})
partner = self.env['res.partner'].create({
'name': 'Ian Anderson',
'property_account_receivable_id': account_receivable_id.id,
})
voucher = self.env['account.voucher'].create({
'voucher_type': 'sale',
'partner_id': partner.id,
'account_id': receivable_other.id,
'journal_id': sales_journal_id.id,
'pay_now': 'pay_now',
'payment_journal_id': cash_journal_id.id,
'line_ids': [(0, False, {
'name': 'Test',
'quantity': 12.0,
'price_unit': 500,
'account_id': income_account.id
})]
})
# validation
voucher.proforma_voucher()
line_rcv = voucher.move_id.line_ids.filtered(lambda l: l.account_id.internal_type == 'receivable')
self.assertEquals(line_rcv.account_id, receivable_other)
self.assertTrue(line_rcv.full_reconcile_id.exists())
self.assertEquals(len(line_rcv.full_reconcile_id.reconciled_line_ids), 2)
reconciled_line = line_rcv.full_reconcile_id.reconciled_line_ids - line_rcv
self.assertEquals(reconciled_line.account_id, receivable_other)