@@ -14,6 +14,10 @@ def setUpClass(cls):
14
14
super ().setUpClass ()
15
15
cls .pattern_config_m2m .export_format = "json"
16
16
cls .pattern_config .export_format = "json"
17
+ cls .pattern_config_currency = cls .env .ref (
18
+ "pattern_import_export.demo_pattern_config_currency"
19
+ )
20
+ cls .pattern_config_currency .export_format = "json"
17
21
18
22
def run_pattern_file (self , pattern_file ):
19
23
model = self .env [pattern_file .pattern_config_id .model_id .model ].with_context (
@@ -331,7 +335,7 @@ def test_o2m_with_empty_value(self):
331
335
self .assertEqual (partners [0 ].name , unique_name )
332
336
self .assertEqual (partners [0 ].child_ids , partners [1 ])
333
337
334
- def _helper_o2m_update (self ):
338
+ def _case_o2m_update_no_delete_cascade (self ):
335
339
unique_name = str (uuid4 ())
336
340
partner = self .env ["res.partner" ].create (
337
341
{
@@ -359,20 +363,54 @@ def _helper_o2m_update(self):
359
363
self .assertPatternDone (pattern_file )
360
364
return partner , child_1 , child_2
361
365
362
- def test_o2m_update_with_purge (self ):
366
+ def _case_o2m_update_with_delete_cascade (self ):
367
+ currency = self .env .ref ("base.EUR" )
368
+ currency .write (
369
+ {
370
+ "rate_ids" : [
371
+ (5 , 0 , 0 ),
372
+ (0 , 0 , {"name" : "1999-12-02" , "rate" : 1 }),
373
+ (0 , 0 , {"name" : "2000-01-30" , "rate" : 2 }),
374
+ ]
375
+ }
376
+ )
377
+ data = [
378
+ {
379
+ ".id" : currency .id ,
380
+ "rate_ids|1|name#key" : "1999-12-02" ,
381
+ "rate_ids|1|rate" : 1.5 ,
382
+ "rate_ids|2|name#key" : "2022-01-01" ,
383
+ "rate_ids|2|rate" : 3 ,
384
+ }
385
+ ]
386
+ pattern_file = self .create_pattern (self .pattern_config_currency , "import" , data )
387
+ self .run_pattern_file (pattern_file )
388
+ self .assertPatternDone (pattern_file )
389
+ return currency
390
+
391
+ def test_o2m_update_with_purge_no_delete_cascade (self ):
363
392
self .pattern_config .purge_one2many = True
364
- partner , child_1 , child_2 = self ._helper_o2m_update ()
393
+ partner , child_1 , child_2 = self ._case_o2m_update_no_delete_cascade ()
365
394
self .assertEqual (len (partner .child_ids ), 3 )
366
395
self .assertIn (child_1 , partner .child_ids )
367
396
self .assertNotIn (child_2 , partner .child_ids )
368
397
369
398
def test_o2m_update_without_purge (self ):
370
399
self .pattern_config .purge_one2many = False
371
- partner , child_1 , child_2 = self ._helper_o2m_update ()
400
+ partner , child_1 , child_2 = self ._case_o2m_update_no_delete_cascade ()
372
401
self .assertEqual (len (partner .child_ids ), 4 )
373
402
self .assertIn (child_1 , partner .child_ids )
374
403
self .assertIn (child_2 , partner .child_ids )
375
404
405
+ def test_o2m_update_with_purge_with_delete_cascade (self ):
406
+ self .pattern_config_currency .purge_one2many = True
407
+ currency = self ._case_o2m_update_with_delete_cascade ()
408
+ self .assertEqual (len (currency .rate_ids ), 2 )
409
+
410
+ def test_o2m_update_without_purge_with_delete_cascade (self ):
411
+ currency = self ._case_o2m_update_with_delete_cascade ()
412
+ self .assertEqual (len (currency .rate_ids ), 3 )
413
+
376
414
def test_empty_m2m_with_o2m (self ):
377
415
unique_name = str (uuid4 ())
378
416
partner2_name = str (uuid4 ())
0 commit comments