Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 4cdf2968

Von Tamino Steinert vor etwa 1 Jahr hinzugefügt

  • ID 4cdf29685e0a9e5d448b514ba86c23493902047a
  • Vorgänger 8f4fd78c
  • Nachfolger f4d75dd4

Order: nutze Record-Type

Unterschiede anzeigen:

SL/Controller/Order.pm
1876 1876
  my $order;
1877 1877
  $order   = SL::DB::Order->new(id => $::form->{id})->load(with => [ 'orderitems', 'orderitems.part' ]) if $::form->{id};
1878 1878
  $order ||= SL::DB::Order->new(orderitems  => [],
1879
                                record_type => $self->type,
1879 1880
                                quotation   => (any { $self->type eq $_ } (SALES_QUOTATION_TYPE(), REQUEST_QUOTATION_TYPE(), PURCHASE_QUOTATION_INTAKE_TYPE())),
1880 1881
                                intake      => (any { $self->type eq $_ } (SALES_ORDER_INTAKE_TYPE(), PURCHASE_QUOTATION_INTAKE_TYPE())),
1881 1882
                                currency_id => $::instance_conf->get_currency_id(),);
SL/Controller/RequirementSpecOrder.pm
10 10

  
11 11
use SL::DB::Customer;
12 12
use SL::DB::Order;
13
use SL::DB::Order::TypeData qw(:types);
13 14
use SL::DB::Part;
14 15
use SL::DB::RequirementSpec;
15 16
use SL::DB::RequirementSpecOrder;
......
368 369
  my $reqdate    = !$::form->{quotation} ? undef
369 370
                 : $customer->payment_id ? $customer->payment->calc_date
370 371
                 :                         DateTime->today_local->next_workday(extra_days => $::instance_conf->get_reqdate_interval)->to_kivitendo;
372
  my $record_type = $::form->{quotation} ? SALES_QUOTATION_TYPE() : SALES_ORDER_TYPE();
371 373
  my $order      = SL::DB::Order->new(
374
    record_type             => $record_type,
372 375
    globalproject_id        => $self->requirement_spec->project_id,
373 376
    transdate               => DateTime->today_local,
374 377
    reqdate                 => $reqdate,
SL/DB/Order.pm
162 162

  
163 163
sub type {
164 164
  my $self = shift;
165

  
166
  return SALES_ORDER_INTAKE_TYPE()        if $self->customer_id &&   $self->intake;
167
  return SALES_ORDER_TYPE()               if $self->customer_id && ! $self->quotation;
168
  return PURCHASE_ORDER_TYPE()            if $self->vendor_id   && ! $self->quotation;
169
  return SALES_QUOTATION_TYPE()           if $self->customer_id &&   $self->quotation;
170
  return REQUEST_QUOTATION_TYPE()         if $self->vendor_id   &&   $self->quotation  && ! $self->intake;
171
  return PURCHASE_QUOTATION_INTAKE_TYPE() if $self->vendor_id   &&   $self->quotation  &&   $self->intake;
172

  
173
  return;
165
  die "invalid type: " . $self->record_type if (!any { $self->record_type eq $_ } (
166
      SALES_ORDER_INTAKE_TYPE(),
167
      SALES_ORDER_TYPE(),
168
      PURCHASE_ORDER_TYPE(),
169
      REQUEST_QUOTATION_TYPE(),
170
      SALES_QUOTATION_TYPE(),
171
      PURCHASE_QUOTATION_INTAKE_TYPE(),
172
    ));
173
  return $self->record_type;
174 174
}
175 175

  
176 176
sub is_type {
......
469 469
    $args{shipto_id} = $source->shipto_id;
470 470
  }
471 471

  
472
  $args{record_type} = $destination_type;
473

  
472 474
  my $order = $class->new(%args);
473 475
  $order->assign_attributes(%{ $params{attributes} }) if $params{attributes};
474 476
  my $items = delete($params{items}) || $source->items_sorted;
SL/DB/ShopOrder.pm
47 47
          : @{ $self->shop_order_items };
48 48

  
49 49
  require SL::DB::Order;
50
  use SL::DB::Order::TypeData qw(:types);
50 51
  require SL::DB::OrderItem;
51 52
  require SL::DB::Part;
52 53
  require SL::DB::Shipto;
......
115 116
      currency_id             => $customer->currency_id,
116 117
      transaction_description => $shop->transaction_description,
117 118
      transdate               => $transdate,
119
      record_type             => SALES_ORDER_TYPE(),
118 120
    );
119 121
     return $order;
120 122
   }else{
SL/Dev/Record.pm
32 32

  
33 33
use SL::DB::Invoice;
34 34
use SL::DB::InvoiceItem;
35
use SL::DB::Order;
36
use SL::DB::Order::TypeData qw(:types);
35 37
use SL::DB::DeliveryOrder::TypeData qw(:types);
36 38
use SL::DB::Employee;
37 39
use SL::Dev::Part qw(new_part);
......
52 54
                                 credit_note          => 'SL::DB::InvoiceItem',
53 55
                                 sales_order          => 'SL::DB::OrderItem',
54 56
                                 sales_quotation      => 'SL::DB::OrderItem',
55
                                 purchase_quotation   => 'SL::DB::OrderItem',
57
                                 request_quotation    => 'SL::DB::OrderItem',
56 58
                                 purchase_order       => 'SL::DB::OrderItem',
57 59
                                 sales_delivery_order => 'SL::DB::DeliveryOrderItem',
58 60
                                 purchase_delivery_order => 'SL::DB::DeliveryOrderItem',
......
216 218

  
217 219
sub create_sales_quotation {
218 220
  my (%params) = @_;
219
  $params{type} = 'sales_quotation';
221
  $params{type} = SALES_QUOTATION_TYPE();
220 222
  _create_sales_order_or_quotation(%params);
221 223
}
222 224

  
223 225
sub create_sales_order {
224 226
  my (%params) = @_;
225
  $params{type} = 'sales_order';
227
  $params{type} = SALES_ORDER_TYPE();
226 228
  _create_sales_order_or_quotation(%params);
227 229
}
228 230

  
229 231
sub create_purchase_quotation {
230 232
  my (%params) = @_;
231
  $params{type} = 'purchase_quotation';
233
  $params{type} = REQUEST_QUOTATION_TYPE();
232 234
  # TODO: set a with reqdate
233 235
  _create_purchase_order_or_quotation(%params);
234 236
}
235 237

  
236 238
sub create_purchase_order {
237 239
  my (%params) = @_;
238
  $params{type} = 'purchase_order';
240
  $params{type} = PURCHASE_ORDER_TYPE();
239 241
  _create_purchase_order_or_quotation(%params);
240 242
}
241 243

  
......
737 739
  my (%params) = @_;
738 740

  
739 741
  my $record_type = $params{type};
740
  die "illegal type" unless $record_type eq 'sales_order' or $record_type eq 'sales_quotation';
742
  die "illegal type" unless $record_type eq SALES_ORDER_TYPE() or $record_type eq SALES_QUOTATION_TYPE();
741 743

  
742 744
  my $orderitems = delete $params{orderitems} // _create_two_items($record_type);
743 745
  _check_items($orderitems, $record_type);
......
748 750
  die "illegal customer" unless ref($customer) eq 'SL::DB::Customer';
749 751

  
750 752
  my $record = SL::DB::Order->new(
753
    record_type  => delete $params{type},
751 754
    customer_id  => delete $params{customer_id} // $customer->id,
752 755
    taxzone_id   => delete $params{taxzone_id}  // $customer->taxzone->id,
753 756
    currency_id  => delete $params{currency_id} // $::instance_conf->get_currency_id,
......
770 773
  my (%params) = @_;
771 774

  
772 775
  my $record_type = $params{type};
773
  die "illegal type" unless $record_type eq 'purchase_order' or $record_type eq 'purchase_quotation';
776
  die "illegal type" unless $record_type eq PURCHASE_ORDER_TYPE() or $record_type eq REQUEST_QUOTATION_TYPE();
774 777
  my $orderitems = delete $params{orderitems} // _create_two_items($record_type);
775 778
  _check_items($orderitems, $record_type);
776 779

  
......
780 783
  die "illegal vendor" unless ref($vendor) eq 'SL::DB::Vendor';
781 784

  
782 785
  my $record = SL::DB::Order->new(
786
    record_type  => delete $params{type},
783 787
    vendor_id    => delete $params{vendor_id}   // $vendor->id,
784 788
    taxzone_id   => delete $params{taxzone_id}  // $vendor->taxzone->id,
785 789
    currency_id  => delete $params{currency_id} // $::instance_conf->get_currency_id,
786 790
    taxincluded  => delete $params{taxincluded} // 0,
787 791
    transdate    => delete $params{transdate}   // DateTime->today,
788 792
    'closed'     => undef,
789
    quotation    => $record_type eq 'purchase_quotation' ? 1 : 0,
793
    quotation    => $record_type eq REQUEST_QUOTATION_TYPE() ? 1 : 0,
790 794
    orderitems   => $orderitems,
791 795
  );
792 796
  $record->assign_attributes(%params) if %params;
t/db_helper/record_links.t
18 18
use SL::DB::Employee;
19 19
use SL::DB::Invoice;
20 20
use SL::DB::Order;
21
use SL::DB::Order::TypeData qw(:types);
21 22
use SL::DB::DeliveryOrder;
22 23
use SL::DB::DeliveryOrder::TypeData qw(:types);
23 24
use SL::DB::Part;
......
68 69
  my %params  = @_;
69 70

  
70 71
  return SL::DB::Order->new(
72
    record_type => SALES_ORDER_TYPE(),
71 73
    customer_id => $customer->id,
72 74
    currency_id => $currency_id,
73 75
    employee_id => $employee->id,

Auch abrufbar als: Unified diff