|
6 | 6 |
|
7 | 7 | import base64
|
8 | 8 | import re
|
| 9 | +from unittest.mock import Mock |
9 | 10 |
|
10 | 11 | from psycopg2 import IntegrityError
|
11 | 12 |
|
| 13 | +import odoo |
12 | 14 | from odoo import fields
|
13 | 15 | from odoo.exceptions import UserError
|
14 | 16 | from odoo.tests import Form, tagged
|
@@ -886,6 +888,56 @@ def test_no_tax_fail(self):
|
886 | 888 | )
|
887 | 889 | self.assertEqual(ue.exception.args[0], error_message)
|
888 | 890 |
|
| 891 | + def test_partner_no_address_fail(self): |
| 892 | + """ |
| 893 | + - create an XML invoice where the customer has no address or city |
| 894 | +
|
| 895 | + expect to fail with a proper message |
| 896 | + """ |
| 897 | + invoice = self._create_invoice() |
| 898 | + invoice.partner_id.street = False |
| 899 | + invoice.partner_id.city = False |
| 900 | + invoice._post() |
| 901 | + wizard = self.wizard_model.create({}) |
| 902 | + with self.assertRaises(UserError) as ue: |
| 903 | + wizard.with_context({"active_ids": [invoice.id]}).exportFatturaPA() |
| 904 | + error_msg = ue.exception.args[0] |
| 905 | + error_fragments = ( |
| 906 | + f"Error processing invoice(s) {invoice.name}", |
| 907 | + "Indirizzo", |
| 908 | + "Comune", |
| 909 | + "Activate debug mode to see the full error", |
| 910 | + ) |
| 911 | + for fragment in error_fragments: |
| 912 | + self.assertIn(fragment, error_msg) |
| 913 | + |
| 914 | + try: |
| 915 | + # Enter debug mode and add details |
| 916 | + odoo.http._request_stack.push( |
| 917 | + Mock( |
| 918 | + db=self.env.cr.dbname, |
| 919 | + env=self.env, |
| 920 | + debug=True, |
| 921 | + website=False, # compatibility with website module |
| 922 | + is_frontend=False, |
| 923 | + ) |
| 924 | + ) |
| 925 | + wizard = self.wizard_model.create({}) |
| 926 | + with self.assertRaises(UserError) as ue: |
| 927 | + wizard.with_context({"active_ids": [invoice.id]}).exportFatturaPA() |
| 928 | + debug_error_msg = ue.exception.args[0] |
| 929 | + debug_error_fragments = ( |
| 930 | + "Full error follows", |
| 931 | + "Reason: value doesn't match any pattern of", |
| 932 | + "p{IsBasicLatin}", |
| 933 | + "<Comune xmlns:ns1", |
| 934 | + ) |
| 935 | + for fragment in error_fragments[:-1] + debug_error_fragments: |
| 936 | + self.assertIn(fragment, debug_error_msg) |
| 937 | + finally: |
| 938 | + # Remove from the stack to not interfere with other tests |
| 939 | + odoo.http._request_stack.pop() |
| 940 | + |
889 | 941 | def test_multicompany_fail(self):
|
890 | 942 | """
|
891 | 943 | - create two invoices in two different companies
|
|
0 commit comments