Skip to content

Commit

Permalink
Fix conflict with 10.0 + Fix unit test fail
Browse files Browse the repository at this point in the history
  • Loading branch information
acsonefho committed Sep 27, 2019
1 parent ab806eb commit 2430c0e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
30 changes: 28 additions & 2 deletions shopinvader/tests/test_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright 2019 ACSONE SA/NV
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
import mock
from odoo import fields
from odoo.exceptions import MissingError

from .common import CommonCase
Expand All @@ -10,13 +11,38 @@
class TestInvoice(CommonCase):
def setUp(self, *args, **kwargs):
super(TestInvoice, self).setUp(*args, **kwargs)
self.register_payments_obj = self.env["account.register.payments"]
self.journal_obj = self.env["account.journal"]
self.sale = self.env.ref("shopinvader.sale_order_2")
self.partner = self.env.ref("shopinvader.partner_1")
self.payment_method_manual_in = self.env.ref(
"account.account_payment_method_manual_in"
)
self.bank_journal_euro = self.journal_obj.create(
{"name": "Bank", "type": "bank", "code": "BNK627"}
)
with self.work_on_services(partner=self.partner) as work:
self.sale_service = work.component(usage="sales")
self.invoice_service = work.component(usage="invoice")
self.invoice = self._confirm_and_invoice_sale(self.sale)

def _make_payment(self, invoice):
"""
Make the invoice payment
:param invoice: account.invoice recordset
:return: bool
"""
ctx = {"active_model": invoice._name, "active_ids": invoice.ids}
wizard_obj = self.register_payments_obj.with_context(ctx)
register_payments = wizard_obj.create(
{
"payment_date": fields.Date.today(),
"journal_id": self.bank_journal_euro.id,
"payment_method_id": self.payment_method_manual_in.id,
}
)
register_payments.create_payment()

def _confirm_and_invoice_sale(self, sale):
sale.action_confirm()
for line in sale.order_line:
Expand Down Expand Up @@ -48,7 +74,7 @@ def test_02(self):
Expected result:
* An http response with the file to download
"""
self.invoice.action_invoice_paid()
self._make_payment(self.invoice)
with mock.patch(
"openerp.addons.shopinvader.services.invoice.content_disposition"
) as mocked_cd, mock.patch(
Expand Down Expand Up @@ -79,6 +105,6 @@ def test_03(self):
sale.shopinvader_backend_id = self.backend
self.assertNotEqual(sale.partner_id, self.partner)
invoice = self._confirm_and_invoice_sale(sale)
invoice.action_invoice_paid()
self._make_payment(invoice)
with self.assertRaises(MissingError):
self.invoice_service.download(invoice.id)
27 changes: 26 additions & 1 deletion shopinvader/tests/test_sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ def setUp(self, *args, **kwargs):
super(SaleCase, self).setUp(*args, **kwargs)
self.sale = self.env.ref("shopinvader.sale_order_2")
self.partner = self.env.ref("shopinvader.partner_1")
self.register_payments_obj = self.env["account.register.payments"]
self.journal_obj = self.env["account.journal"]
self.payment_method_manual_in = self.env.ref(
"account.account_payment_method_manual_in"
)
self.bank_journal_euro = self.journal_obj.create(
{"name": "Bank", "type": "bank", "code": "BNK6278"}
)
with self.work_on_services(partner=self.partner) as work:
self.service = work.component(usage="sales")

Expand Down Expand Up @@ -85,6 +93,23 @@ def test_ask_email_invoice(self):
self.service.dispatch("ask_email_invoice", _id=self.sale.id)
self.assertEquals(self.env["queue.job"].search_count(domain), 1)

def _make_payment(self, invoice):
"""
Make the invoice payment
:param invoice: account.invoice recordset
:return: bool
"""
ctx = {"active_model": invoice._name, "active_ids": invoice.ids}
wizard_obj = self.register_payments_obj.with_context(ctx)
register_payments = wizard_obj.create(
{
"payment_date": fields.Date.today(),
"journal_id": self.bank_journal_euro.id,
"payment_method_id": self.payment_method_manual_in.id,
}
)
register_payments.create_payment()

def test_invoice_01(self):
"""
Data
Expand All @@ -109,7 +134,7 @@ def test_invoice_02(self):
* Invoice information must be filled
"""
self._confirm_and_invoice_sale()
self.invoice.action_invoice_paid()
self._make_payment(self.invoice)
self.assertEqual(self.invoice.state, "paid")
res = self.service.get(self.sale.id)
self.assertTrue(res)
Expand Down

0 comments on commit 2430c0e

Please sign in to comment.