@@ -39,15 +39,46 @@ def setUp(self):
39
39
)
40
40
41
41
def test_fatturapa_in_purchase (self ):
42
- """Check that `name_get` works properly. verify to_invoice field"""
42
+ """
43
+ Check that `name_get` works properly and verify the `to_invoice` field.
44
+ Handle the intermediary VAT check wizard if triggered during import.
45
+ """
43
46
res = self .run_wizard ("test_fatturapa_in_purchase" , "IT05979361218_008.xml" )
44
- invoice_id = res .get ("domain" )[0 ][2 ][0 ]
45
- invoice = self .invoice_model .browse (invoice_id )
46
47
48
+ # Handle the intermediary VAT check wizard if it appears
49
+ if res .get ("res_model" ) == "wizard.check.intermediary" :
50
+ context = res .get ("context" , {})
51
+ intermediary_id = context .get ("intermediary_id" )
52
+ invoice_id = context .get ("invoice_id" )
53
+
54
+ self .assertTrue (intermediary_id , "intermediary_id is missing in context" )
55
+ self .assertTrue (invoice_id , "invoice_id is missing in context" )
56
+
57
+ wizard = (
58
+ self .env ["wizard.check.intermediary" ]
59
+ .with_context (context )
60
+ .create (
61
+ {
62
+ "message" : context .get ("default_message" ),
63
+ "intermediary_id" : intermediary_id ,
64
+ "invoice_id" : invoice_id ,
65
+ }
66
+ )
67
+ )
68
+
69
+ wizard .action_confirm ()
70
+ invoice = self .env ["account.move" ].browse (invoice_id )
71
+
72
+ else :
73
+ invoice_id = res .get ("domain" )[0 ][2 ][0 ]
74
+ invoice = self .invoice_model .browse (invoice_id )
75
+
76
+ # Link the invoice line to the purchase order line
47
77
inv_line = first (invoice .invoice_line_ids )
48
78
order_line = first (self .order .order_line )
49
79
inv_line .purchase_line_id = order_line
50
80
81
+ # Check the display name and `to_invoice` field logic
51
82
self .assertEqual (order_line .display_name , "test_po: Large Desk" )
52
83
self .assertFalse (order_line .to_invoice )
53
84
order_line .product_id .write ({"purchase_method" : "purchase" })
0 commit comments