|
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,83 @@ 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 city or zip |
| 894 | +
|
| 895 | + expect to fail with a proper message |
| 896 | + """ |
| 897 | + self.res_partner_fatturapa_0.street = False |
| 898 | + self.res_partner_fatturapa_0.city = False |
| 899 | + invoice = self.invoice_model.create( |
| 900 | + { |
| 901 | + "invoice_date": "2016-06-15", |
| 902 | + "partner_id": self.res_partner_fatturapa_0.id, |
| 903 | + "journal_id": self.sales_journal.id, |
| 904 | + "invoice_payment_term_id": self.account_payment_term.id, |
| 905 | + "user_id": self.user_demo.id, |
| 906 | + "move_type": "out_invoice", |
| 907 | + "currency_id": self.EUR.id, |
| 908 | + "invoice_line_ids": [ |
| 909 | + ( |
| 910 | + 0, |
| 911 | + 0, |
| 912 | + { |
| 913 | + "account_id": self.a_sale.id, |
| 914 | + "product_id": self.product_product_10.id, |
| 915 | + "name": "Mouse, Optical", |
| 916 | + "quantity": 1, |
| 917 | + "product_uom_id": self.product_uom_unit.id, |
| 918 | + "price_unit": 10, |
| 919 | + "tax_ids": [(6, 0, {self.tax_22.id})], |
| 920 | + }, |
| 921 | + ), |
| 922 | + ( |
| 923 | + 0, |
| 924 | + 0, |
| 925 | + { |
| 926 | + "account_id": self.a_sale.id, |
| 927 | + "product_id": self.product_order_01.id, |
| 928 | + "name": "Zed+ Antivirus", |
| 929 | + "quantity": 1, |
| 930 | + "product_uom_id": self.product_uom_unit.id, |
| 931 | + "price_unit": 4, |
| 932 | + "tax_ids": [(6, 0, {self.tax_22.id})], |
| 933 | + }, |
| 934 | + ), |
| 935 | + ], |
| 936 | + } |
| 937 | + ) |
| 938 | + invoice._post() |
| 939 | + wizard = self.wizard_model.create({}) |
| 940 | + with self.assertRaises(UserError) as ue: |
| 941 | + wizard.with_context({"active_ids": [invoice.id]}).exportFatturaPA() |
| 942 | + error_msg = ue.exception.args[0] |
| 943 | + error_fragments = [ |
| 944 | + f"Error processing invoice(s) {invoice.name}", |
| 945 | + "Indirizzo", |
| 946 | + "Comune", |
| 947 | + "Activate debug mode to see the full error", |
| 948 | + ] |
| 949 | + for fragment in error_fragments: |
| 950 | + self.assertIn(fragment, error_msg) |
| 951 | + |
| 952 | + # Enter debug mode and add details |
| 953 | + odoo.http._request_stack.push( |
| 954 | + Mock(db=self.env.cr.dbname, env=self.env, debug=True) |
| 955 | + ) |
| 956 | + wizard = self.wizard_model.create({}) |
| 957 | + with self.assertRaises(UserError) as ue: |
| 958 | + wizard.with_context({"active_ids": [invoice.id]}).exportFatturaPA() |
| 959 | + debug_error_msg = ue.exception.args[0] |
| 960 | + debug_error_fragments = [ |
| 961 | + "Full error follows", |
| 962 | + "Reason: value doesn't match any pattern of", |
| 963 | + "class 'lxml.etree._Element'>", |
| 964 | + ] |
| 965 | + for fragment in error_fragments[:-1] + debug_error_fragments: |
| 966 | + self.assertIn(fragment, debug_error_msg) |
| 967 | + |
889 | 968 | def test_multicompany_fail(self):
|
890 | 969 | """
|
891 | 970 | - create two invoices in two different companies
|
|
0 commit comments