Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 7d104877

Von Sven Schöling vor fast 2 Jahren hinzugefügt

  • ID 7d10487719948d9215b040395403053d5378c36f
  • Vorgänger de558fa6
  • Nachfolger b41d5e72

PriceRule: tests

- shipto und custom shipto
- requirement specs cvars
- text cvars

Unterschiede anzeigen:

t/db/price_rule.t
22 22
  SL::DB::Manager::CustomVariable->delete_all(all => 1);
23 23
  SL::DB::Manager::CustomVariableConfig->delete_all(all => 1);
24 24
  SL::DB::Manager::Order->delete_all(all => 1);
25
  SL::DB::Manager::Shipto->delete_all(all => 1);
25 26

  
26 27
  $::request->{_cache} = {};
27 28
}
......
131 132
#  - Contact
132 133
#  - IC
133 134
#  - Project
135
#  - ShipTo
134 136
#
135 137
# and the cvars themselves can have these types:
136 138
#  - select
......
419 421
    $item->part->cvar_by_name($name)->save;
420 422
    test($price_rule, $order, $item, "$name -- matching", 1);
421 423
  }
424

  
425
  {
426
    reset_db();
427

  
428
    my $name = "shipto cvar and price rule matching that";
429

  
430
    my $config = SL::DB::CustomVariableConfig->new(
431
      module => 'ShipTo',
432
      type => 'number',
433
      name => $name,
434
      description => $name,
435
      searchable  => 0,
436
      includeable => 0,
437
      included_by_default => 0,
438
      flags => '',
439
    )->save->load;
440

  
441
    my $price_rule = SL::DB::PriceRule->new(
442
      name  => $name,
443
      price => 1,
444
      type  => "customer",
445
      items => [
446
        SL::DB::PriceRuleItem->new(
447
          custom_variable_configs => $config,
448
          value_num               => 15,
449
          op                      => "eq",
450
          type                    => "cvar",
451
        ),
452
      ],
453
    )->save;
454

  
455
    my $order = create_sales_order()->save->load;
456
    my $item = $order->items_sorted->[0];
457
    my $shipto = SL::DB::Shipto->new;
458
    $order->shipto($shipto);
459
    $order->save->load;
460

  
461
    test($price_rule, $order, $item, "$name -- default value", 0);
462

  
463
    $order->shipto->cvar_by_name($name)->value(20);
464
    $order->shipto->cvar_by_name($name)->save;
465
    test($price_rule, $order, $item, "$name -- not matching", 0);
466

  
467
    $order->shipto->cvar_by_name($name)->value(15);
468
    $order->shipto->cvar_by_name($name)->save;
469
    test($price_rule, $order, $item, "$name -- matching", 1);
470
  }
471

  
472
  {
473
    reset_db();
474

  
475
    my $name = "custom shipto cvar and price rule matching that";
476

  
477
    my $config = SL::DB::CustomVariableConfig->new(
478
      module => 'ShipTo',
479
      type => 'number',
480
      name => $name,
481
      description => $name,
482
      searchable  => 0,
483
      includeable => 0,
484
      included_by_default => 0,
485
      flags => '',
486
    )->save->load;
487

  
488
    my $price_rule = SL::DB::PriceRule->new(
489
      name  => $name,
490
      price => 1,
491
      type  => "customer",
492
      items => [
493
        SL::DB::PriceRuleItem->new(
494
          custom_variable_configs => $config,
495
          value_num               => 15,
496
          op                      => "eq",
497
          type                    => "cvar",
498
        ),
499
      ],
500
    )->save;
501

  
502
    my $order = create_sales_order()->save->load;
503
    my $item = $order->items_sorted->[0];
504
    my $shipto = SL::DB::Shipto->new(trans_id => $order->id, module => 'OE')->save;
505

  
506
    ok(ref $order->custom_shipto eq 'SL::DB::Shipto', 'custom shipto is readable from order');
507

  
508
    test($price_rule, $order, $item, "$name -- default value", 0);
509

  
510
    $order->custom_shipto->cvar_by_name($name)->value(20);
511
    $order->custom_shipto->cvar_by_name($name)->save;
512
    test($price_rule, $order, $item, "$name -- not matching", 0);
513

  
514
    $order->custom_shipto->cvar_by_name($name)->value(15);
515
    $order->custom_shipto->cvar_by_name($name)->save;
516
    test($price_rule, $order, $item, "$name -- matching", 1);
517
  }
518

  
519
  {
520
    reset_db();
521

  
522
    my $name = "custom shipto cvar and price rule matching that";
523

  
524
    my $config = SL::DB::CustomVariableConfig->new(
525
      module => 'ShipTo',
526
      type => 'number',
527
      name => $name,
528
      description => $name,
529
      searchable  => 0,
530
      includeable => 0,
531
      included_by_default => 0,
532
      flags => '',
533
    )->save->load;
534

  
535
    my $price_rule = SL::DB::PriceRule->new(
536
      name  => $name,
537
      price => 1,
538
      type  => "customer",
539
      items => [
540
        SL::DB::PriceRuleItem->new(
541
          custom_variable_configs => $config,
542
          value_num               => 15,
543
          op                      => "eq",
544
          type                    => "cvar",
545
        ),
546
      ],
547
    )->save;
548

  
549
    my $order = create_sales_order()->save->load;
550
    my $item = $order->items_sorted->[0];
551
    my $shipto1 = SL::DB::Shipto->new;
552
    $order->shipto($shipto1);
553
    my $shipto2 = SL::DB::Shipto->new(trans_id => $order->id, module => 'OE')->save;
554
    $order->save->load;
555

  
556
    test($price_rule, $order, $item, "$name -- default value", 0);
557

  
558
    $order->custom_shipto->cvar_by_name($name)->value(20);
559
    $order->custom_shipto->cvar_by_name($name)->save;
560
    test($price_rule, $order, $item, "$name -- not matching custom", 0);
561

  
562
    $order->shipto->cvar_by_name($name)->value(15);
563
    $order->shipto->cvar_by_name($name)->save;
564
    test($price_rule, $order, $item, "$name -- not matching custom, matching shipto", 0);
565

  
566
    $order->custom_shipto->cvar_by_name($name)->value(15);
567
    $order->custom_shipto->cvar_by_name($name)->save;
568
    test($price_rule, $order, $item, "$name -- matching both", 1);
569

  
570
    $order->shipto->cvar_by_name($name)->value(20);
571
    $order->shipto->cvar_by_name($name)->save;
572
    test($price_rule, $order, $item, "$name -- matching custom, not matching shipto", 1);
573
  }
574

  
575
  {
576
    reset_db();
577

  
578
    my $name = "no price rule, but cvars exist with module requirementsspecs or type text";
579

  
580
    my $config1 = SL::DB::CustomVariableConfig->new(
581
      module => 'RequirementSpecs',
582
      type => 'number',
583
      name => $name,
584
      description => $name,
585
      searchable  => 0,
586
      includeable => 0,
587
      included_by_default => 0,
588
      flags => '',
589
    )->save->load;
590

  
591
    my $config2 = SL::DB::CustomVariableConfig->new(
592
      module => 'Customer',
593
      type => 'text',
594
      name => $name,
595
      description => $name,
596
      searchable  => 0,
597
      includeable => 0,
598
      included_by_default => 0,
599
      flags => '',
600
    )->save->load;
601

  
602
    my $order = create_sales_order()->save->load;
603
    my $item = $order->items_sorted->[0];
604
    $order->save->load;
605

  
606
    test(undef, $order, $item, "$name -- nothing to match", 0);
607
  }
422 608
}
423 609

  
424 610
reset_db();

Auch abrufbar als: Unified diff