Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 1f53f425

Von Tamino Steinert vor fast 2 Jahren hinzugefügt

  • ID 1f53f4251e8aa82251be5f50b56d49a5973b447e
  • Vorgänger fa1b9d49
  • Nachfolger b1695edc

Order: nutze Record-Type

Unterschiede anzeigen:

SL/Controller/Order.pm
1820 1820
  my $order;
1821 1821
  $order   = SL::DB::Order->new(id => $::form->{id})->load(with => [ 'orderitems', 'orderitems.part' ]) if $::form->{id};
1822 1822
  $order ||= SL::DB::Order->new(orderitems  => [],
1823
                                record_type => $self->type,
1823 1824
                                quotation   => (any { $self->type eq $_ } (SALES_QUOTATION_TYPE(), REQUEST_QUOTATION_TYPE())),
1824 1825
                                currency_id => $::instance_conf->get_currency_id(),);
1825 1826

  
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_TYPE()       if $self->customer_id && ! $self->quotation;
167
  return PURCHASE_ORDER_TYPE()    if $self->vendor_id   && ! $self->quotation;
168
  return SALES_QUOTATION_TYPE()   if $self->customer_id &&   $self->quotation;
169
  return REQUEST_QUOTATION_TYPE() if $self->vendor_id   &&   $self->quotation;
170

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

  
174 174
sub is_type {
......
444 444
    $args{shipto_id} = $source->shipto_id;
445 445
  }
446 446

  
447
  $args{record_type} = $destination_type;
448

  
447 449
  my $order = $class->new(%args);
448 450
  $order->assign_attributes(%{ $params{attributes} }) if $params{attributes};
449 451
  my $items = delete($params{items}) || $source->items_sorted;
SL/DB/ShopOrder.pm
34 34
  croak "param employee is missing" unless ref($employee) eq 'SL::DB::Employee';
35 35

  
36 36
  require SL::DB::Order;
37
  use SL::DB::Order::TypeData qw(:types);
37 38
  require SL::DB::OrderItem;
38 39
  require SL::DB::Part;
39 40
  require SL::DB::Shipto;
......
102 103
      currency_id             => $customer->currency_id,
103 104
      transaction_description => $shop->transaction_description,
104 105
      transdate               => $transdate,
106
      record_type             => SALES_ORDER_TYPE(),
105 107
    );
106 108
     return $order;
107 109
   }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