Skip to content

Commit

Permalink
[IMP] SUITE account payment return: Use SavepointCase in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdauden committed Oct 25, 2016
1 parent 5232871 commit 008d6da
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions account_payment_return/tests/test_payment_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,43 @@
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp.exceptions import Warning as UserError
from openerp.tests.common import TransactionCase
from openerp.tests.common import SavepointCase


class TestPaymentReturn(TransactionCase):

def setUp(self):
super(TestPaymentReturn, self).setUp()
self.account_invoice_model = self.env['account.invoice']
self.payment_return_model = self.env['payment.return']
self.partner = self.env.ref('base.res_partner_1')
class TestPaymentReturn(SavepointCase):
@classmethod
def setUpClass(cls):
super(TestPaymentReturn, cls).setUp()
cls.account_invoice_model = cls.env['account.invoice']
cls.payment_return_model = cls.env['payment.return']
cls.partner = cls.env.ref('base.res_partner_1')
# Prepare invoice and pay it for making the return
self.invoice = self.env.ref('account.invoice_2')
self.invoice.journal_id.update_posted = True
self.invoice.signal_workflow('invoice_open')
self.receivable_line = self.invoice.move_id.line_id.filtered(
cls.invoice = cls.env.ref('account.invoice_2')
cls.invoice.journal_id.update_posted = True
cls.invoice.signal_workflow('invoice_open')
cls.receivable_line = cls.invoice.move_id.line_id.filtered(
lambda x: x.account_id.type == 'receivable')
# Invert the move to simulate the payment
self.payment_move = self.invoice.move_id.copy()
for move_line in self.payment_move.line_id:
cls.payment_move = cls.invoice.move_id.copy()
for move_line in cls.payment_move.line_id:
debit = move_line.debit
move_line.write({'debit': move_line.credit,
'credit': debit})
self.payment_line = self.payment_move.line_id.filtered(
cls.payment_line = cls.payment_move.line_id.filtered(
lambda x: x.account_id.type == 'receivable')
# Reconcile both
self.reconcile = self.env['account.move.reconcile'].create(
cls.reconcile = cls.env['account.move.reconcile'].create(
{'type': 'manual',
'line_id': [(4, self.payment_line.id),
(4, self.receivable_line.id)]})
'line_id': [(4, cls.payment_line.id),
(4, cls.receivable_line.id)]})
# Create payment return
self.payment_return = self.payment_return_model.create(
{'journal_id': self.env.ref('account.bank_journal').id,
cls.payment_return = cls.payment_return_model.create(
{'journal_id': cls.env.ref('account.bank_journal').id,
'line_ids': [
(0, 0, {'partner_id': self.partner.id,
'move_line_ids': [(6, 0, self.payment_line.ids)],
'amount': self.payment_line.credit})]})
self.payment_return.journal_id.update_posted = True
(0, 0, {'partner_id': cls.partner.id,
'move_line_ids': [(6, 0, cls.payment_line.ids)],
'amount': cls.payment_line.credit})]})
cls.payment_return.journal_id.update_posted = True

def test_confirm_error(self):
self.payment_return.line_ids[0].move_line_ids = False
Expand Down Expand Up @@ -70,6 +70,7 @@ def test_payment_return(self):
self.assertEqual(self.invoice.state, 'paid')
self.payment_return.action_draft()
self.assertEqual(self.payment_return.state, 'draft')
self.payment_return.unlink()

def test_payment_partial_return(self):
self.payment_return.line_ids[0].amount = 5.0
Expand Down

0 comments on commit 008d6da

Please sign in to comment.