@@ -34,6 +34,8 @@ def setUpClass(cls):
3434 "city" : "Odoo Ville" ,
3535 "zip" : "28001" ,
3636 "street" : "Calle de La Rua, 3" ,
37+ "phone" : "666555444" ,
38+ "email" : "test@test.com" ,
3739 }
3840 )
3941 order_form = Form (cls .env ["sale.order" ].with_context (tracking_disable = True ))
@@ -64,6 +66,16 @@ def test_01_gls_picking_confirm_simple(self):
6466 self .picking .button_validate ()
6567 self .assertTrue (self .picking .carrier_tracking_ref )
6668 self .assertTrue (self .picking .gls_asm_public_tracking_ref )
69+ # Check label generation
70+ self .picking .gls_asm_get_label ()
71+ attachment = self .env ["ir.attachment" ].search (
72+ [
73+ ("res_model" , "=" , "stock.picking" ),
74+ ("res_id" , "=" , self .picking .id ),
75+ ("name" , "like" , "gls_%" ),
76+ ]
77+ )
78+ self .assertTrue (attachment , "Label was not attached to the picking" )
6779 self .picking .cancel_shipment ()
6880 self .assertFalse (self .picking .carrier_tracking_ref )
6981 self .assertFalse (self .picking .gls_asm_public_tracking_ref )
@@ -81,3 +93,96 @@ def test_03_gls_escaping(self):
8193 properly escaped"""
8294 vals = self .carrier_gls_asm ._prepare_gls_asm_shipping (self .picking )
8395 self .assertEqual (vals .get ("destinatario_nombre" ), "Mr. Odoo & Co." )
96+
97+ def test_04_gls_pickup_confirm (self ):
98+ """Test pickup confirmation"""
99+ self .carrier_gls_asm .gls_asm_service = "56" # RECOGIDA ECONOMY
100+ self .picking .name = f"ODOO-{ int (time .time ())} "
101+ self .picking .gls_asm_send_pickup ()
102+ self .assertTrue (self .picking .carrier_tracking_ref )
103+ self .assertTrue (self .picking .gls_asm_public_tracking_ref )
104+ self .picking .cancel_shipment ()
105+ # TODO: The pickup cancelation returns Error -204, check if
106+ # _prepare_cancel_pickup_docin is correct
107+ # self.assertFalse(self.picking.carrier_tracking_ref)
108+ # self.assertFalse(self.picking.gls_asm_public_tracking_ref)
109+
110+ def test_05_gls_errors (self ):
111+ """Test various error conditions"""
112+ self .carrier_gls_asm .gls_asm_service = "37" # ECONOMY
113+ # Test missing sender street
114+ original_street = self .company .partner_id .street
115+ self .company .partner_id .street = False
116+ with self .assertRaises (UserError ):
117+ self .carrier_gls_asm ._prepare_gls_asm_shipping (self .picking )
118+ self .carrier_gls_asm .gls_asm_service = "57" # RECOGIDA ECONOMY
119+ with self .assertRaises (UserError ):
120+ self .carrier_gls_asm ._prepare_gls_asm_pickup (self .picking )
121+ self .company .partner_id .street = original_street
122+
123+ def test_06_tracking_links (self ):
124+ """Test tracking link generation"""
125+ self .picking .carrier_tracking_ref = "123456"
126+ # ASM Link
127+ link = self .carrier_gls_asm .gls_asm_get_tracking_link (self .picking )
128+ self .assertIn ("123456" , link )
129+ self .assertIn (self .partner .zip , link )
130+
131+ # International Link
132+ self .picking .gls_asm_picking_ref = "REFERENCIA_INT"
133+ link = self .carrier_gls_asm .gls_asm_get_tracking_link (self .picking )
134+ self .assertIn ("REFERENCIA_INT" , link )
135+
136+ # Portugal Link
137+ self .partner .country_id = self .env .ref ("base.pt" )
138+ link = self .carrier_gls_asm .gls_asm_get_tracking_link (self .picking )
139+ self .assertIn ("REFERENCIA_INT" , link )
140+
141+ def test_07_labels_and_manifests (self ):
142+ """Test labels and manifest wizard"""
143+ # Labels (mocked or at least checking the branch)
144+ label = self .carrier_gls_asm .gls_asm_get_label ("123" )
145+ self .assertFalse (label ) # Should be false if not real tracking or mocked
146+
147+ # Manifest wizard
148+ action = self .carrier_gls_asm .action_get_manifest ()
149+ self .assertEqual (action ["res_model" ], "gls.asm.minifest.wizard" )
150+ wizard = self .env [action ["res_model" ]].browse (action ["res_id" ])
151+ self .assertEqual (wizard .carrier_id , self .carrier_gls_asm )
152+
153+ # Should raise error if no data found for manifest
154+ wizard .date_from = "2050-01-01"
155+ with self .assertRaises (UserError ):
156+ wizard .get_manifest ()
157+
158+ def test_08_ambiguous_tracking_ref (self ):
159+ """Test cancellation when tracking ref is not unique"""
160+ self .picking .carrier_tracking_ref = "123456"
161+ with self .assertRaises (UserError ):
162+ self .picking .cancel_shipment ()
163+
164+ def test_09_gls_cod (self ):
165+ """Test Cash On Delivery"""
166+ self .carrier_gls_asm .gls_asm_cash_on_delivery = True
167+ # Need a sales order for COD amount
168+ sale = self .env ["sale.order" ].create (
169+ {
170+ "partner_id" : self .partner .id ,
171+ "order_line" : [
172+ (
173+ 0 ,
174+ 0 ,
175+ {
176+ "product_id" : self .product .id ,
177+ "product_uom_qty" : 1 ,
178+ "price_unit" : 100.0 ,
179+ },
180+ )
181+ ],
182+ }
183+ )
184+ sale .action_confirm ()
185+ self .picking = sale .picking_ids [0 ]
186+ self .picking .carrier_id = self .carrier_gls_asm
187+ vals = self .carrier_gls_asm ._prepare_gls_asm_shipping (self .picking )
188+ self .assertEqual (vals .get ("destinatario_nombre" ), "Mr. Odoo & Co." )
0 commit comments