Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 121940b0

Von Tamino Steinert vor etwa 1 Jahr hinzugefügt

  • ID 121940b03b64e6d4c51821b65401b089b5061284
  • Vorgänger 9ddaf796
  • Nachfolger 7219b5f5

Order: nutze TypeData

Unterschiede anzeigen:

SL/Controller/Order.pm
91 91

  
92 92
  $self->render(
93 93
    'order/form',
94
    title => $self->get_title_for('add'),
94
    title => $self->type_data->text('add'),
95 95
    %{$self->{template_args}}
96 96
  );
97 97
}
......
119 119

  
120 120
  $self->render(
121 121
    'order/form',
122
    title => $self->get_title_for('edit'),
122
    title => $self->type_data->text('edit'),
123 123
    %{$self->{template_args}}
124 124
  );
125 125
}
......
159 159
  $self->pre_render();
160 160
  $self->render(
161 161
    'order/form',
162
    title => $self->get_title_for('edit'),
162
    title => $self->type_data->text('edit'),
163 163
    %{$self->{template_args}}
164 164
  );
165 165
}
......
492 492
                                  email_form    => $email_form,
493 493
                                  show_bcc      => $::auth->assert('email_bcc', 'may fail'),
494 494
                                  FILES         => \%files,
495
                                  is_customer   => $self->cv eq 'customer',
495
                                  is_customer   => $self->type_data->properties('is_customer'),
496 496
                                  ALL_EMPLOYEES => \@employees_with_email,
497 497
                                  ALL_PARTNER_EMAIL_ADDRESSES => $all_partner_email_addresses,
498 498
                                  is_final_version => $self->is_final_version,
......
926 926

  
927 927
  $self->render(
928 928
    'order/form',
929
    title => $self->get_title_for('edit'),
929
    title => $self->type_data->text('edit'),
930 930
    %{$self->{template_args}}
931 931
  );
932 932
}
......
986 986
sub action_show_customer_vendor_details_dialog {
987 987
  my ($self) = @_;
988 988

  
989
  my $is_customer = 'customer' eq $::form->{vc};
989
  my $is_customer = $self->type_data->properties('is_customer');
990 990
  my $cv;
991 991
  if ($is_customer) {
992 992
    $cv = SL::DB::Customer->new(id => $::form->{vc_id})->load;
......
1330 1330

  
1331 1331
  $self->render(
1332 1332
    'order/form',
1333
    title => $self->get_title_for('edit'),
1333
    title => $self->type_data->text('edit'),
1334 1334
    %{$self->{template_args}}
1335 1335
  );
1336 1336

  
......
1649 1649
sub init_cv {
1650 1650
  my ($self) = @_;
1651 1651

  
1652
  my $cv = (any { $self->type eq $_ } (SALES_ORDER_INTAKE_TYPE(), SALES_ORDER_TYPE(),       SALES_QUOTATION_TYPE()))           ? 'customer'
1653
         : (any { $self->type eq $_ } (PURCHASE_ORDER_TYPE(),     REQUEST_QUOTATION_TYPE(), PURCHASE_QUOTATION_INTAKE_TYPE())) ? 'vendor'
1654
         : die "Not a valid type for order";
1655

  
1656
  return $cv;
1652
  return $self->type_data->properties('customervendor');
1657 1653
}
1658 1654

  
1659 1655
sub init_search_cvpartnumber {
......
1687 1683

  
1688 1684
sub init_part_picker_classification_ids {
1689 1685
  my ($self)    = @_;
1690
  my $attribute = 'used_for_' . ($self->type =~ m{sales} ? 'sale' : 'purchase');
1691 1686

  
1692
  return [ map { $_->id } @{ SL::DB::Manager::PartClassification->get_all(where => [ $attribute => 1 ]) } ];
1687
  return [ map { $_->id } @{ SL::DB::Manager::PartClassification->get_all(
1688
    where => $self->type_data->part_classification_query()) } ];
1693 1689
}
1694 1690

  
1695 1691
sub init_is_final_version {
......
1708 1704

  
1709 1705
sub check_auth {
1710 1706
  my ($self) = @_;
1711

  
1712
  my $right_for = { map { $_ => $_.'_edit' . ' | ' . $_.'_view' } @{$self->valid_types} };
1713
  $right_for->{ SALES_ORDER_INTAKE_TYPE()        } = 'sales_order_edit | sales_order_view';
1714
  $right_for->{ PURCHASE_QUOTATION_INTAKE_TYPE() } = 'request_quotation_edit | request_quotation_view';
1715

  
1716
  my $right   = $right_for->{ $self->type };
1717
  $right    ||= 'DOES_NOT_EXIST';
1718

  
1719
  $::auth->assert($right);
1707
  $::auth->assert($self->type_data->rights('view'));
1720 1708
}
1721 1709

  
1722 1710
sub check_auth_for_edit {
1723 1711
  my ($self) = @_;
1724

  
1725
  my $right_for = { map { $_ => $_.'_edit' } @{$self->valid_types} };
1726
  $right_for->{ SALES_ORDER_INTAKE_TYPE()        } = 'sales_order_edit';
1727
  $right_for->{ PURCHASE_QUOTATION_INTAKE_TYPE() } = 'request_quotation_edit';
1728

  
1729
  my $right   = $right_for->{ $self->type };
1730
  $right    ||= 'DOES_NOT_EXIST';
1731

  
1732
  $::auth->assert($right);
1712
  $::auth->assert($self->type_data->rights('edit'));
1733 1713
}
1734 1714

  
1735 1715
# build the selection box for contacts
......
2242 2222
sub setup_edit_action_bar {
2243 2223
  my ($self, %params) = @_;
2244 2224

  
2245
  my $deletion_allowed = (any { $self->type eq $_ } (SALES_QUOTATION_TYPE(), REQUEST_QUOTATION_TYPE(), PURCHASE_QUOTATION_INTAKE_TYPE()))
2246
                      || (($self->type eq SALES_ORDER_TYPE())        && $::instance_conf->get_sales_order_show_delete)
2247
                      || (($self->type eq SALES_ORDER_INTAKE_TYPE()) && $::instance_conf->get_sales_order_show_delete)
2248
                      || (($self->type eq PURCHASE_ORDER_TYPE())     && $::instance_conf->get_purchase_order_show_delete);
2249

  
2250 2225
  my @req_trans_cost_art = qw(kivi.Order.check_transport_cost_article_presence) x!!$::instance_conf->get_transport_cost_reminder_article_number_id;
2251 2226
  my @req_cusordnumber   = qw(kivi.Order.check_cusordnumber_presence)           x(( any {$self->type eq $_} (SALES_ORDER_INTAKE_TYPE(), SALES_ORDER_TYPE()) ) && $::instance_conf->get_order_warn_no_cusordnumber);
2252 2227

  
......
2262 2237
    $has_final_invoice               = any {'SL::DB::Invoice' eq ref $_ && "final_invoice" eq $_->type} @$lr;
2263 2238
  }
2264 2239

  
2265
  my $right_for         = { map { $_ => $_.'_edit' } @{$self->valid_types} };
2266
  $right_for->{ SALES_ORDER_INTAKE_TYPE() } = 'sales_order_edit';
2267
  $right_for->{ PURCHASE_QUOTATION_INTAKE_TYPE() } = 'request_quotation_edit';
2268
  my $right             = $right_for->{ $self->type };
2269
  $right              ||= 'DOES_NOT_EXIST';
2270
  my $may_edit_create   = $::auth->assert($right, 'may fail');
2240
  my $may_edit_create   = $::auth->assert($self->type_data->rights('edit'), 'may fail');
2271 2241

  
2272 2242
  my $is_final_version = $self->is_final_version;
2273 2243

  
......
2329 2299
          t8('Save and Quotation'),
2330 2300
          call     => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => SALES_QUOTATION_TYPE()), '#order_form' ],
2331 2301
          checks   => [ @req_trans_cost_art, @req_cusordnumber ],
2332
          only_if  => (any { $self->type eq $_ } (SALES_ORDER_INTAKE_TYPE(), SALES_ORDER_TYPE(), REQUEST_QUOTATION_TYPE(), PURCHASE_QUOTATION_INTAKE_TYPE())),
2302
          only_if  => $self->type_data->show_menu('save_and_quotation'),
2333 2303
          disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2334 2304
        ],
2335 2305
        action => [
2336 2306
          t8('Save and RFQ'),
2337 2307
          call     => [ 'kivi.Order.purchase_check_for_direct_delivery', { to_type => REQUEST_QUOTATION_TYPE() } ],
2338
          only_if  => (any { $self->type eq $_ } (SALES_ORDER_INTAKE_TYPE(), SALES_ORDER_TYPE(), SALES_QUOTATION_TYPE(), PURCHASE_ORDER_TYPE())),
2308
          only_if  => $self->type_data->show_menu('save_and_rfq'),
2339 2309
          disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2340 2310
        ],
2341 2311
        action => [
......
2354 2324
          t8('Save and Sales Order Confirmation'),
2355 2325
          call     => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => SALES_ORDER_TYPE()), '#order_form' ],
2356 2326
          checks   => [ @req_trans_cost_art ],
2357
          only_if  => (any { $self->type eq $_ } (SALES_QUOTATION_TYPE(), SALES_ORDER_INTAKE_TYPE(), REQUEST_QUOTATION_TYPE(), PURCHASE_ORDER_TYPE(), PURCHASE_QUOTATION_INTAKE_TYPE())),
2327
          only_if  => $self->type_data->show_menu('save_and_sales_order'),
2358 2328
          disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2359 2329
        ],
2360 2330
        action => [
2361 2331
          t8('Save and Purchase Order'),
2362 2332
          call      => [ 'kivi.Order.purchase_check_for_direct_delivery', { to_type => PURCHASE_ORDER_TYPE() } ],
2363 2333
          checks    => [ @req_trans_cost_art, @req_cusordnumber ],
2364
          only_if   => (any { $self->type eq $_ } (SALES_ORDER_INTAKE_TYPE(), SALES_ORDER_TYPE(), REQUEST_QUOTATION_TYPE(), PURCHASE_QUOTATION_INTAKE_TYPE())),
2334
          only_if   => $self->type_data->show_menu('save_and_purchase_order'),
2365 2335
          disabled  => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2366 2336
        ],
2367 2337
        action => [
......
2373 2343
          checks    => [ 'kivi.Order.check_save_active_periodic_invoices',
2374 2344
                         @req_trans_cost_art, @req_cusordnumber,
2375 2345
          ],
2376
          only_if   => (any { $self->type eq $_ } (SALES_ORDER_TYPE(), PURCHASE_ORDER_TYPE())),
2346
          only_if   => $self->type_data->show_menu('save_and_delivery_order'),
2377 2347
          disabled  => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2378 2348
        ],
2379 2349
        action => [
......
2396 2366
          checks    => [ 'kivi.Order.check_save_active_periodic_invoices',
2397 2367
                         @req_trans_cost_art, @req_cusordnumber,
2398 2368
          ],
2399
          only_if   => (any { $self->type eq $_ } (PURCHASE_ORDER_TYPE())),
2369
          only_if   => $self->type_data->show_menu('save_and_supplier_delivery_order'),
2400 2370
          disabled  => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2401 2371
        ],
2402 2372
        action => [
......
2404 2374
          call      => [ 'kivi.Order.save', { action             => 'save_and_reclamation',
2405 2375
                                              warn_on_duplicates => $::instance_conf->get_order_warn_duplicate_parts },
2406 2376
          ],
2407
          only_if   => (any { $self->type eq $_ } (SALES_ORDER_TYPE(), PURCHASE_ORDER_TYPE()))
2377
          only_if   =>$self->type_data->show_menu('save_and_reclamation')
2408 2378
        ],
2409 2379
        action => [
2410 2380
          t8('Save and Invoice'),
......
2415 2385
                         @req_trans_cost_art, @req_cusordnumber,
2416 2386
          ],
2417 2387
          disabled  => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
2418
          not_if    => (any { $self->type eq $_ } (SALES_ORDER_INTAKE_TYPE(), PURCHASE_QUOTATION_INTAKE_TYPE())),
2388
          only_if   => $self->type_data->show_menu('save_and_invoice'),
2419 2389
        ],
2420 2390
        action => [
2421 2391
          ($has_invoice_for_advance_payment ? t8('Save and Further Invoice for Advance Payment') : t8('Save and Invoice for Advance Payment')),
......
2428 2398
          disabled  => !$may_edit_create  ? t8('You do not have the permissions to access this function.')
2429 2399
                     : $has_final_invoice ? t8('This order has already a final invoice.')
2430 2400
                     :                      undef,
2431
          only_if   => (any { $self->type eq $_ } (SALES_ORDER_TYPE())),
2401
          only_if   => $self->type_data->show_menu('save_and_invoice_for_advance_payment'),
2432 2402
        ],
2433 2403
        action => [
2434 2404
          t8('Save and Final Invoice'),
......
2441 2411
          disabled  => !$may_edit_create  ? t8('You do not have the permissions to access this function.')
2442 2412
                     : $has_final_invoice ? t8('This order has already a final invoice.')
2443 2413
                     :                      undef,
2444
          only_if   => (any { $self->type eq $_ } (SALES_ORDER_TYPE())) && $has_invoice_for_advance_payment,
2414
          only_if   => $self->type_data->show_menu('save_and_final_invoice') && $has_invoice_for_advance_payment,
2445 2415
        ],
2446 2416
        action => [
2447 2417
          t8('Save and AP Transaction'),
2448 2418
          call      => [ 'kivi.Order.save', { action             => 'save_and_ap_transaction',
2449 2419
                                              warn_on_duplicates => $::instance_conf->get_order_warn_duplicate_parts },
2450 2420
          ],
2451
          only_if   => (any { $self->type eq $_ } (PURCHASE_ORDER_TYPE())),
2421
          only_if   => $self->type_data->show_menu('save_and_ap_transaction'),
2452 2422
          disabled  => !$may_edit_create  ? t8('You do not have the permissions to access this function.') : undef,
2453 2423
        ],
2454 2424

  
......
2503 2473
        disabled => !$may_edit_create  ? t8('You do not have the permissions to access this function.')
2504 2474
                  : !$self->order->id  ? t8('This object has not been saved yet.')
2505 2475
                  :                      undef,
2506
        only_if  => $deletion_allowed,
2476
        only_if  => $self->type_data->show_menu('delete'),
2507 2477
      ],
2508 2478

  
2509 2479
      combobox => [
......
2648 2618
  return $active ? t8('active') : t8('inactive');
2649 2619
}
2650 2620

  
2651
sub get_title_for {
2652
  my ($self, $action) = @_;
2653

  
2654
  return '' if none { lc($action)} qw(add edit);
2655

  
2656
  # for locales:
2657
  # $::locale->text("Add Sales Order Intake");
2658
  # $::locale->text("Add Sales Order");
2659
  # $::locale->text("Add Purchase Order");
2660
  # $::locale->text("Add Quotation");
2661
  # $::locale->text("Add Request for Quotation");
2662
  # $::locale->text("Add Purchase Quotation Intake");
2663
  # $::locale->text("Edit Sales Order Intake");
2664
  # $::locale->text("Edit Sales Order");
2665
  # $::locale->text("Edit Purchase Order");
2666
  # $::locale->text("Edit Quotation");
2667
  # $::locale->text("Edit Request for Quotation");
2668
  # $::locale->text("Edit Purchase Quotation Intake");
2669

  
2670
  $action = ucfirst(lc($action));
2671
  return $self->type eq SALES_ORDER_INTAKE_TYPE()        ? $::locale->text("$action Sales Order Intake")
2672
       : $self->type eq SALES_ORDER_TYPE()               ? $::locale->text("$action Sales Order")
2673
       : $self->type eq PURCHASE_ORDER_TYPE()            ? $::locale->text("$action Purchase Order")
2674
       : $self->type eq SALES_QUOTATION_TYPE()           ? $::locale->text("$action Quotation")
2675
       : $self->type eq REQUEST_QUOTATION_TYPE()         ? $::locale->text("$action Request for Quotation")
2676
       : $self->type eq PURCHASE_QUOTATION_INTAKE_TYPE() ? $::locale->text("$action Purchase Quotation Intake")
2677
       : '';
2678
}
2679

  
2680 2621
sub get_item_cvpartnumber {
2681 2622
  my ($self, $item) = @_;
2682 2623

  
......
2752 2693
}
2753 2694

  
2754 2695
sub nr_key {
2755
  return $_[0]->type eq SALES_ORDER_INTAKE_TYPE()        ? 'ordnumber'
2756
       : $_[0]->type eq SALES_ORDER_TYPE()               ? 'ordnumber'
2757
       : $_[0]->type eq PURCHASE_ORDER_TYPE()            ? 'ordnumber'
2758
       : $_[0]->type eq SALES_QUOTATION_TYPE()           ? 'quonumber'
2759
       : $_[0]->type eq REQUEST_QUOTATION_TYPE()         ? 'quonumber'
2760
       : $_[0]->type eq PURCHASE_QUOTATION_INTAKE_TYPE() ? 'quonumber'
2761
       : '';
2696
  my ($self) = @_;
2697

  
2698
  return $self->type_data->properties('nr_key');
2762 2699
}
2763 2700

  
2764 2701
sub save_and_redirect_to {
......
2766 2703

  
2767 2704
  $self->save();
2768 2705

  
2769
  my $text = $self->type eq SALES_ORDER_INTAKE_TYPE()        ? $::locale->text('The order intake has been saved')
2770
           : $self->type eq SALES_ORDER_TYPE()               ? $::locale->text('The order confirmation has been saved')
2771
           : $self->type eq PURCHASE_ORDER_TYPE()            ? $::locale->text('The order has been saved')
2772
           : $self->type eq SALES_QUOTATION_TYPE()           ? $::locale->text('The quotation has been saved')
2773
           : $self->type eq REQUEST_QUOTATION_TYPE()         ? $::locale->text('The rfq has been saved')
2774
           : $self->type eq PURCHASE_QUOTATION_INTAKE_TYPE() ? $::locale->text('The quotation intake has been saved')
2775
           : '';
2776
  flash_later('info', $text);
2706
  flash_later('info', $self->type_data->text('saved'));
2777 2707

  
2778 2708
  $self->redirect_to(%params, id => $self->order->id);
2779 2709
}
SL/DB/Order.pm
26 26
use SL::RecordLinks;
27 27
use Rose::DB::Object::Helpers qw(as_tree strip);
28 28

  
29
use SL::DB::Order::TypeData qw(:types);
29
use SL::DB::Order::TypeData qw(:types validate_type);
30 30
use SL::DB::Reclamation::TypeData qw(:types);
31 31

  
32 32
__PACKAGE__->meta->add_relationship(
......
161 161

  
162 162
sub type {
163 163
  my $self = shift;
164
  die "invalid type: " . $self->record_type if (!any { $self->record_type eq $_ } (
165
      SALES_ORDER_INTAKE_TYPE(),
166
      SALES_ORDER_TYPE(),
167
      PURCHASE_ORDER_TYPE(),
168
      REQUEST_QUOTATION_TYPE(),
169
      SALES_QUOTATION_TYPE(),
170
      PURCHASE_QUOTATION_INTAKE_TYPE(),
171
    ));
164
  SL::DB::Order::TypeData::validate_type($self->record_type);
172 165
  return $self->record_type;
173 166
}
174 167

  
......
215 208
}
216 209

  
217 210
sub displayable_type {
218
  my $type = shift->type;
219

  
220
  return $::locale->text('Sales quotation')   if $type eq SALES_QUOTATION_TYPE();
221
  return $::locale->text('Request quotation') if $type eq REQUEST_QUOTATION_TYPE();
222
  return $::locale->text('Sales Order')       if $type eq SALES_ORDER_TYPE();
223
  return $::locale->text('Purchase Order')    if $type eq PURCHASE_ORDER_TYPE();
211
  my ($self) = @_;
224 212

  
225
  die 'invalid type';
213
  return $self->type_data->text('list');
226 214
}
227 215

  
228 216
sub displayable_name {
......
639 627
sub number {
640 628
  my $self = shift;
641 629

  
642
  return if !$self->type;
643

  
644
  my %number_method = (
645
    SALES_ORDER_INTAKE_TYPE()        => 'ordnumber',
646
    SALES_ORDER_TYPE()               => 'ordnumber',
647
    SALES_QUOTATION_TYPE()           => 'quonumber',
648
    PURCHASE_ORDER_TYPE()            => 'ordnumber',
649
    REQUEST_QUOTATION_TYPE()         => 'quonumber',
650
    PURCHASE_QUOTATION_INTAKE_TYPE() => 'quonumber',
651
  );
652

  
653
  return $self->${ \ $number_method{$self->type} }(@_);
630
  my $nr_key = $self->type_data->properties('nr_key');
631
  return $self->$nr_key(@_);
654 632
}
655 633

  
656 634
sub customervendor {

Auch abrufbar als: Unified diff