|
12 | 12 | from odoo.addons.account.models.account_payment_method import AccountPaymentMethod |
13 | 13 | from odoo.osv.expression import AND |
14 | 14 | from odoo.addons.point_of_sale.tests.common import archive_products |
| 15 | +from odoo.exceptions import UserError |
15 | 16 |
|
16 | 17 | import odoo.tests |
17 | 18 |
|
@@ -286,6 +287,49 @@ def test_customer_display_online_payment(self): |
286 | 287 | self.start_tour(f"/pos_customer_display/{self.main_pos_config.id}/{self.main_pos_config.access_token}", |
287 | 288 | 'CustomerDisplayTourOnlinePayment', login="pos_user") |
288 | 289 |
|
| 290 | + def test_refuse_online_payment_without_accounting_payment(self): |
| 291 | + """ |
| 292 | + Test that a an order can not be paid through an online payment method from the backend |
| 293 | + when no accounting payment are set for this payment method. Ensure that it will raise |
| 294 | + an error as soon as it is tried as it is not supported yet. Also ensures that we can still |
| 295 | + close the session afterwards, as it is a side effect of not throwing the error. |
| 296 | + """ |
| 297 | + self.main_pos_config.open_ui() |
| 298 | + session = self.main_pos_config.current_session_id |
| 299 | + try: |
| 300 | + self.env["pos.order"].sync_from_ui([{ |
| 301 | + "amount_paid": 1180, |
| 302 | + "amount_tax": 180, |
| 303 | + "amount_return": 0, |
| 304 | + "amount_total": 1180, |
| 305 | + "lines": [ |
| 306 | + Command.create({ |
| 307 | + "price_unit": 1000.0, |
| 308 | + "product_id": self.letter_tray.id, |
| 309 | + "price_subtotal": 1000.0, |
| 310 | + "price_subtotal_incl": 1180.0, |
| 311 | + "qty": 1, |
| 312 | + }), |
| 313 | + ], |
| 314 | + "name": "Order 12345-123-1234", |
| 315 | + "session_id": session.id, |
| 316 | + "payment_ids": [ |
| 317 | + Command.create({ |
| 318 | + "amount": 1180, |
| 319 | + "name": fields.Datetime.now(), |
| 320 | + "payment_method_id": self.online_payment_method.id, |
| 321 | + }), |
| 322 | + ], |
| 323 | + "uuid": "12345-123-1234", |
| 324 | + }]) |
| 325 | + self.fail("An error should be raised if no accounting payment has been set") |
| 326 | + except UserError as e: |
| 327 | + self.assertIn("Cannot create a POS online payment without an accounting payment", str(e)) |
| 328 | + # Make sure that we can close the session |
| 329 | + session.order_ids.filtered(lambda o: o.state == 'draft').unlink() |
| 330 | + session.action_pos_session_close() |
| 331 | + self.assertEqual(session.state, 'closed') |
| 332 | + |
289 | 333 | @classmethod |
290 | 334 | def tearDownClass(cls): |
291 | 335 | # Restore company values after the tests |
|
0 commit comments