Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 77e57dde

Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt

  • ID 77e57ddebc8187458a660721d6ecd9495554510c
  • Vorgänger 74448c30
  • Nachfolger 4836a949

Records: Workflow-Methoden angepasst und vereinheitlicht

Unterschiede anzeigen:

SL/Controller/DeliveryOrder.pm
33 33
use SL::DB::Warehouse;
34 34
use SL::DB::Helper::RecordLink qw(set_record_link_conversions);
35 35
use SL::DB::Helper::TypeDataProxy;
36
use SL::DB::Helper::Record qw(get_object_name_from_type get_class_from_type);
36 37
use SL::DB::DeliveryOrder;
37 38
use SL::DB::DeliveryOrder::TypeData qw(:types);
38 39
use SL::DB::Order::TypeData qw(:types);
......
98 99
  );
99 100
}
100 101

  
101
sub action_add_from_order {
102
sub action_add_from_record {
102 103
  my ($self) = @_;
103
  # this interfers with init_order
104
  $self->{converted_from_oe_id} = delete $::form->{id};
105

  
106
  $self->type_data->validate;
107

  
108
  my $order = SL::DB::Order->new(id => $self->{converted_from_oe_id})->load;
109

  
110
  my $target_type = $::form->{type};
111
  my $delivery_order = SL::Model::Record->new_from_workflow($order, $target_type);
112
  $self->order($delivery_order);
104
  my $from_type = $::form->{from_type};
105
  my $from_id   = $::form->{from_id};
113 106

  
114
  $self->action_add;
115
}
116

  
117
sub action_add_from_reclamation {
118
  my ($self) = @_;
107
  unless ($from_type && $from_id) {
108
    $self->js->flash('error', t8("Can't create new record."));
109
    $self->js->flash('error', t8("No 'from_type' was given.")) unless ($from_type);
110
    $self->js->flash('error', t8("No 'from_id' was given."))   unless ($from_id);
111
    return $self->js->render();
112
  }
119 113

  
120
  my $reclamation = SL::DB::Reclamation->new(id => $::form->{from_id})->load;
121
  my $target_type = $reclamation->is_sales ? 'rma_delivery_order'
122
                                           : 'supplier_delivery_order';
123
  my $delivery_order = SL::Model::Record->new_from_workflow($reclamation, $target_type);
124
  $self->{converted_from_reclamation_id} = $::form->{from_id};
114
  my $record = SL::Model::Record->get_record($from_type, $from_id);
115
  my $delivery_order = SL::Model::Record->new_from_workflow($record, $self->type);
125 116
  $self->order($delivery_order);
126 117

  
127 118
  $self->action_add;
......
507 498
  $self->redirect_to(@redirect_params);
508 499
}
509 500

  
501
sub action_save_and_new_record {
502
  my ($self) = @_;
503
  my $to_type = $::form->{to_type};
504
  my $to_controller = get_object_name_from_type($to_type);
505

  
506
  $self->save();
507
  flash_later('info', $self->type_data->text('saved'));
508

  
509
  $self->redirect_to(
510
    controller => $to_controller,
511
    action     => 'add_from_record',
512
    type       => $to_type,
513
    from_id    => $self->order->id,
514
    from_type  => $self->order->type,
515
  );
516
}
517

  
510 518
# save the order and redirect to the frontend subroutine for a new
511 519
# delivery order
512 520
sub action_save_and_delivery_order {
SL/Controller/Order.pm
34 34
use SL::DB::ValidityToken;
35 35
use SL::DB::Helper::RecordLink qw(set_record_link_conversions RECORD_ID RECORD_ITEM_ID);
36 36
use SL::DB::Helper::TypeDataProxy;
37
use SL::DB::Helper::Record qw(get_object_name_from_type get_class_from_type);
37 38
use SL::Model::Record;
38 39
use SL::DB::Order::TypeData qw(:types);
39 40
use SL::DB::Reclamation::TypeData qw(:types);
......
95 96
  );
96 97
}
97 98

  
98
sub action_add_from_reclamation {
99
sub action_add_from_record {
99 100
  my ($self) = @_;
101
  my $from_type = $::form->{from_type};
102
  my $from_id   = $::form->{from_id};
100 103

  
101
  my $reclamation = SL::DB::Reclamation->new(id => $::form->{from_id})->load;
102
  my %params;
103
  my $target_type = $reclamation->is_sales ? SALES_ORDER_TYPE()
104
                                           : PURCHASE_ORDER_TYPE();
105
  my $order = SL::Model::Record->new_from_workflow($reclamation, $target_type);
106

  
107
  $self->{converted_from_reclamation_id}       = $order->{ RECORD_ID()      };
108
  $_   ->{converted_from_reclamation_items_id} = $_    ->{ RECORD_ITEM_ID() } for @{ $order->items_sorted };
104
  unless ($from_type && $from_id) {
105
    $self->js->flash('error', t8("Can't create new record."));
106
    $self->js->flash('error', t8("No 'from_type' was given.")) unless ($from_type);
107
    $self->js->flash('error', t8("No 'from_id' was given."))   unless ($from_id);
108
    return $self->js->render();
109
  }
109 110

  
111
  my $record = SL::Model::Record->get_record($from_type, $from_id);
112
  my $order = SL::Model::Record->new_from_workflow($record, $self->type);
110 113
  $self->order($order);
111 114

  
115
  if (ref($record) eq 'SL::DB::Reclamation') {
116
    $self->{converted_from_reclamation_id}       = $order->{ RECORD_ID()      };
117
    $_   ->{converted_from_reclamation_items_id} = $_    ->{ RECORD_ITEM_ID() } for @{ $order->items_sorted };
118
  }
119

  
120

  
112 121
  $self->recalc();
113 122
  $self->pre_render();
114 123

  
......
118 127

  
119 128
  $self->render(
120 129
    'order/form',
121
    title => $self->type_data->text('edit'),
130
    title => $self->type_data->text('add'),
122 131
    %{$self->{template_args}}
123 132
  );
124 133
}
......
753 762
  $_[0]->render(\ !!$has_active_periodic_invoices, { type => 'text' });
754 763
}
755 764

  
756
# save the order and redirect to the frontend subroutine for a new
757
# delivery order
758
sub action_save_and_delivery_order {
765
sub action_save_and_new_record {
759 766
  my ($self) = @_;
767
  my $to_type = $::form->{to_type};
768
  my $to_controller = get_object_name_from_type($to_type);
760 769

  
761
  $self->save_and_redirect_to(
762
    controller => 'oe.pl',
763
    action     => 'oe_delivery_order_from_order',
764
  );
765
}
766

  
767
sub action_save_and_supplier_delivery_order {
768
  my ($self) = @_;
770
  $self->save();
771
  flash_later('info', $self->type_data->text('saved'));
769 772

  
770
  $self->save_and_redirect_to(
771
    controller => 'controller.pl',
772
    action     => 'DeliveryOrder/add_from_order',
773
    type       => 'supplier_delivery_order',
773
  $self->redirect_to(
774
    controller => $to_controller,
775
    action     => 'add_from_record',
776
    type       => $to_type,
777
    from_id    => $self->order->id,
778
    from_type  => $self->order->type,
774 779
  );
775 780
}
776 781

  
777
# save the order and redirect to the frontend subroutine for a new reclamation
778
sub action_save_and_reclamation {
782
# save the order and redirect to the frontend subroutine for a new
783
# delivery order
784
sub action_save_and_delivery_order {
779 785
  my ($self) = @_;
780 786

  
781
  # can't use save_and_redirect_to, because id is set!
782
  $self->save();
783

  
784
  my $to_type = $self->order->is_sales ? SALES_RECLAMATION_TYPE()
785
                                       : PURCHASE_RECLAMATION_TYPE();
786
  $self->redirect_to(
787
    controller => 'Reclamation',
788
    action     => 'add_from_order',
789
    type       => $to_type,
790
    from_id    => $self->order->id,
787
  $self->save_and_redirect_to(
788
    controller => 'oe.pl',
789
    action     => 'oe_delivery_order_from_order',
791 790
  );
792 791
}
793 792

  
SL/Controller/Reclamation.pm
27 27
use SL::DB::ValidityToken;
28 28
use SL::DB::Helper::RecordLink qw(RECORD_ID RECORD_TYPE_REF RECORD_ITEM_ID RECORD_ITEM_TYPE_REF);
29 29
use SL::DB::Helper::TypeDataProxy;
30
use SL::DB::Helper::Record qw(get_object_name_from_type get_class_from_type);
30 31

  
31 32
use SL::Helper::CreatePDF qw(:all);
32 33
use SL::Helper::PrintOptions;
......
67 68
                        only => [qw(
68 69
                          save save_as_new print preview_pdf send_email
69 70
                          save_and_show_email_dialog
70
                          workflow_save_and_sales_or_purchase_reclamation
71
                          save_and_order
72
                          save_and_delivery_order
71
                          save_and_new_record
73 72
                          save_and_credit_note
74 73
                       )]);
75 74

  
......
77 76
                        only => [qw(
78 77
                          save save_as_new print preview_pdf send_email
79 78
                          save_and_show_email_dialog
80
                          workflow_save_and_sales_or_purchase_reclamation
81
                          save_and_order
82
                          save_and_delivery_order
79
                          save_and_new_record
83 80
                          save_and_credit_note
84 81
                        )]);
85 82

  
......
87 84
                        only => [qw(
88 85
                          save save_as_new print preview_pdf send_email
89 86
                          save_and_show_email_dialog
90
                          workflow_save_and_sales_or_purchase_reclamation
91
                          save_and_order
92
                          save_and_delivery_order
87
                          save_and_new_record
93 88
                          save_and_credit_note
94 89
                        )]);
95 90

  
......
116 111
  );
117 112
}
118 113

  
119
sub action_add_from_order {
114
sub action_add_from_record {
120 115
  my ($self) = @_;
116
  my $from_type = $::form->{from_type};
117
  my $from_id   = $::form->{from_id};
121 118

  
122
  unless ($::form->{from_id}) {
123
    $self->js->flash('error', t8("Can't create new reclamation. No 'from_id' was given."));
119
  unless ($from_type && $from_id) {
120
    $self->js->flash('error', t8("Can't create new record."));
121
    $self->js->flash('error', t8("No 'from_type' was given.")) unless ($from_type);
122
    $self->js->flash('error', t8("No 'from_id' was given."))   unless ($from_id);
124 123
    return $self->js->render();
125 124
  }
126 125

  
127
  my $order = SL::DB::Order->new(id => $::form->{from_id})->load;
128
  my $reclamation = SL::Model::Record->new_from_workflow($order, $self->type);
129

  
130
  $self->reclamation($reclamation);
131

  
132
  $self->reinit_after_new_reclamation();
133

  
134
  if (!$::form->{form_validity_token}) {
135
    $::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE())->token;
136
  }
137

  
138
  $self->render(
139
    'reclamation/form',
140
    title => $self->type_data->text('add'),
141
    %{$self->{template_args}},
142
  );
143
}
144

  
145
sub action_add_from_delivery_order {
146
  my ($self) = @_;
147

  
148
  unless ($::form->{from_id}) {
149
    $self->js->flash('error', t8("Can't create new reclamation. No 'from_id' was given."));
150
    return $self->js->render();
151
  }
152

  
153
  my $delivery_order = SL::DB::DeliveryOrder->new(id => $::form->{from_id})->load;
154
  my $reclamation = SL::Model::Record->new_from_workflow($delivery_order, $self->type);
155

  
126
  my $record = SL::Model::Record->get_record($from_type, $from_id);
127
  my $reclamation = SL::Model::Record->new_from_workflow($record, $self->type);
156 128
  $self->reclamation($reclamation);
157 129

  
158
  $self->reinit_after_new_reclamation();
159

  
160
  if (!$::form->{form_validity_token}) {
161
    $::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE())->token;
162
  }
163

  
164
  $self->render(
165
    'reclamation/form',
166
    title => $self->type_data->text('add'),
167
    %{$self->{template_args}},
168
  );
169
}
170

  
171
sub action_add_from_sales_invoice {
172
  my ($self) = @_;
173

  
174
  unless ($::form->{from_id}) {
175
    $self->js->flash('error', t8("Can't create new reclamation. No 'from_id' was given."));
176
    return $self->js->render();
177
  }
178

  
179
  my $invoice = SL::DB::Invoice->new(id => $::form->{from_id})->load;
180
  my $reclamation = SL::Model::Record->new_from_workflow($invoice, $self->type);
181

  
182
  $self->reclamation($reclamation);
183

  
184
  $self->reinit_after_new_reclamation();
185

  
186
  if (!$::form->{form_validity_token}) {
187
    $::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE())->token;
188
  }
189

  
190
  $self->render(
191
    'reclamation/form',
192
    title => $self->type_data->text('add'),
193
    %{$self->{template_args}},
194
  );
195
}
196

  
197
sub action_add_from_purchase_invoice {
198
  my ($self) = @_;
199

  
200
  unless ($::form->{from_id}) {
201
    $self->js->flash('error', t8("Can't create new reclamation. No 'from_id' was given."));
202
    return $self->js->render();
130
  if ($record->type eq SALES_RECLAMATION_TYPE()) { # check for direct delivery
131
    # copy shipto in custom shipto (custom shipto will be copied by new_from() in case)
132
    if ($::form->{use_shipto}) {
133
      my $custom_shipto = $record->shipto->clone('SL::DB::Reclamation');
134
      $self->reclamation->custom_shipto($custom_shipto) if $custom_shipto;
135
    } else {
136
      # remove any custom shipto if not wanted
137
      $self->reclamation->custom_shipto(SL::DB::Shipto->new(module => 'RC', custom_variables => []));
138
    }
203 139
  }
204 140

  
205
  require SL::DB::PurchaseInvoice;
206
  my $invoice = SL::DB::PurchaseInvoice->new(id => $::form->{from_id})->load;
207
  $invoice->{type} = $invoice->invoice_type; #can't add type → invoice_type in SL/DB/PurchaseInvoice
208
  my $reclamation = SL::Model::Record->new_from_workflow($invoice, ref($self->reclamaiton), $self->type);
209

  
210
  $self->reclamation($reclamation);
211

  
212 141
  $self->reinit_after_new_reclamation();
213 142

  
214 143
  if (!$::form->{form_validity_token}) {
......
573 502
  $self->redirect_to(@redirect_params);
574 503
}
575 504

  
576
sub action_save_and_order {
577
  my ($self) = @_;
578

  
579
  my $to_type = $self->reclamation->is_sales ? SALES_ORDER_TYPE()
580
                                             : PURCHASE_ORDER_TYPE();
581

  
582
  $self->save();
583

  
584
  flash_later('info', t8('The reclamation has been saved'));
585
  $self->redirect_to(
586
    controller => 'Order',
587
    action     => 'add_from_reclamation',
588
    type       => $to_type,
589
    from_id    => $self->reclamation->id,
590
  );
591
}
592

  
593
# workflow from purchase to sales reclamation
594
sub action_save_and_sales_reclamation {
505
sub action_save_and_new_record {
595 506
  my ($self) = @_;
507
  my $to_type = $::form->{to_type};
508
  my $to_controller = get_object_name_from_type($to_type);
596 509

  
597 510
  $self->save();
598

  
599 511
  flash_later('info', t8('The reclamation has been saved'));
600
  $self->redirect_to(
601
    controller => 'Reclamation',
602
    action     => 'add_from_reclamation',
603
    from_id => $self->reclamation->id,
604
    type => SALES_RECLAMATION_TYPE(),
605
  );
606
}
607

  
608
# workflow from sales to purchase reclamation
609
sub action_save_and_purchase_reclamation {
610
  my ($self) = @_;
611

  
612
  $self->save();
613 512

  
614
  flash_later('info', t8('The reclamation has been saved'));
615 513
  $self->redirect_to(
616
    controller => 'Reclamation',
617
    action     => 'add_from_reclamation',
618
    from_id => $self->reclamation->id,
619
    type => PURCHASE_RECLAMATION_TYPE(),
620
  );
621
}
622

  
623
# save the reclamation and redirect to the frontend subroutine for a new
624
# delivery order
625

  
626
sub action_save_and_delivery_order {
627
  my ($self) = @_;
628

  
629
  my $to_type = $self->reclamation->is_sales ? 'rma_delivery_order'
630
                                             : 'supplier_delivery_order';
631
  $self->save();
632

  
633
  flash_later('info', t8('The reclamation has been saved'));
634
  $self->redirect_to(
635
    controller => 'controller.pl',
636
    action     => 'DeliveryOrder/add_from_reclamation',
514
    controller => $to_controller,
515
    action     => 'add_from_record',
637 516
    type       => $to_type,
638 517
    from_id    => $self->reclamation->id,
518
    from_type  => $self->reclamation->type,
639 519
  );
640 520
}
641 521

  
......
1708 1588
  delete $::form->{form_validity_token};
1709 1589
}
1710 1590

  
1711
# sales → purchase or purchase → sales
1712
sub action_add_from_reclamation {
1713
  my ($self) = @_;
1714

  
1715
  my $destination_type = $::form->{destination_type};
1716

  
1717
  my $source_reclamation = SL::DB::Reclamation->new(id => $::form->{from_id})->load;
1718

  
1719
  $self->reclamation(
1720
    SL::DB::Reclamation->new_from(
1721
      $source_reclamation,
1722
      destination_type => $::form->{type},
1723
  ));
1724

  
1725
  # check for direct delivery
1726
  # copy shipto in custom shipto (custom shipto will be copied by new_from() in case)
1727
  if (!$self->type_data->properties('is_customer')) {
1728
    if ($::form->{use_shipto}) {
1729
      my $custom_shipto = $source_reclamation->shipto->clone('SL::DB::Reclamation');
1730
      $self->reclamation->custom_shipto($custom_shipto) if $custom_shipto;
1731
    } else {
1732
      # remove any custom shipto if not wanted
1733
      $self->reclamation->custom_shipto(SL::DB::Shipto->new(module => 'RC', custom_variables => []));
1734
    }
1735
  }
1736

  
1737
  $self->reinit_after_new_reclamation();
1738

  
1739
  if (!$::form->{form_validity_token}) {
1740
    $::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE())->token;
1741
  }
1742

  
1743
  $self->render(
1744
    'reclamation/form',
1745
    title => $self->type_data->text('add'),
1746
    %{$self->{template_args}}
1747
  );
1748
}
1749

  
1750 1591
sub reinit_after_new_reclamation {
1751 1592
  my ($self) = @_;
1752 1593

  
bin/mozilla/do.pl
1352 1352

  
1353 1353
sub save_and_reclamation {
1354 1354
  my $form     = $main::form;
1355
  my $id       = $form->{id};
1355 1356
  my $type     = $form->{type};
1356 1357

  
1357 1358
  # save the delivery order
......
1361 1362
    $type eq 'sales_delivery_order' ? 'sales_reclamation'
1362 1363
                                    : 'purchase_reclamation';
1363 1364
  $form->{callback} =
1364
    'controller.pl?action=Reclamation/add_from_delivery_order' .
1365
    '&type=' . $to_reclamation_type .
1366
    '&from_id=' . $form->escape($form->{id});
1365
    'controller.pl?action=Reclamation/add_from_record'
1366
    . '&type='      . $to_reclamation_type
1367
    . '&from_id='   . $form->escape($id)
1368
    . '&from_type=' . $form->escape($type)
1369
    ;
1367 1370
  $form->redirect;
1368 1371
}
1369 1372

  
bin/mozilla/io.pl
1120 1120

  
1121 1121
sub sales_reclamation {
1122 1122
  my $id = $::form->{id};
1123
  my $type = $::form->{type};
1123 1124

  
1124 1125
  require SL::Controller::Reclamation;
1125 1126
  my $c = SL::Controller::Reclamation->new();
1126 1127
  $c->redirect_to(
1127 1128
    controller => 'Reclamation',
1128
    action => 'add_from_sales_invoice',
1129
    from_id => $id,
1130
    type => 'sales_reclamation',
1129
    action     => 'add_from_record',
1130
    type       => 'sales_reclamation',
1131
    from_id    => $id,
1132
    from_type  => $type,
1131 1133
  );
1132 1134
}
1133 1135

  
1134 1136
sub purchase_reclamation {
1135 1137
  my $id = $::form->{id};
1138
  my $type = $::form->{type};
1136 1139

  
1137 1140
  require SL::Controller::Reclamation;
1138 1141
  my $c = SL::Controller::Reclamation->new();
1139 1142
  $c->redirect_to(
1140 1143
    controller => 'Reclamation',
1141
    action => 'add_from_purchase_invoice',
1142
    from_id => $id,
1143
    type => 'purchase_reclamation',
1144
    action     => 'add_from_record',
1145
    type       => 'purchase_reclamation',
1146
    from_id    => $id,
1147
    from_type  => $type,
1144 1148
  );
1145 1149
}
1146 1150

  

Auch abrufbar als: Unified diff