Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 28142a65

Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt

  • ID 28142a6541aa236a3f67dab418e68e0f1f55ed29
  • Vorgänger 9b8b347f
  • Nachfolger eecd5012

TypeData: nutzte Konstanten anstatt String für Typen

Unterschiede anzeigen:

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);
30
use SL::DB::Reclamation::TypeData qw(:types);
31

  
29 32
__PACKAGE__->meta->add_relationship(
30 33
  orderitems => {
31 34
    type         => 'one to many',
......
99 102
  my ($self) = @_;
100 103

  
101 104
  # force new project, if not set yet
102
  if ($::instance_conf->get_order_always_project && !$self->globalproject_id && ($self->type eq 'sales_order')) {
105
  if ($::instance_conf->get_order_always_project && !$self->globalproject_id && ($self->type eq SALES_ORDER_TYPE())) {
103 106

  
104 107
    die t8("Error while creating project with project number of new order number, project number #1 already exists!", $self->ordnumber)
105 108
      if SL::DB::Manager::Project->find_by(projectnumber => $self->ordnumber);
......
161 164
sub type {
162 165
  my $self = shift;
163 166

  
164
  return 'sales_order'       if $self->customer_id && ! $self->quotation;
165
  return 'purchase_order'    if $self->vendor_id   && ! $self->quotation;
166
  return 'sales_quotation'   if $self->customer_id &&   $self->quotation;
167
  return 'request_quotation' if $self->vendor_id   &&   $self->quotation;
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;
168 171

  
169 172
  return;
170 173
}
......
178 181
  # But this has a different meaning for sales quotations.
179 182
  # deliverydate can be used to determine tax if tax_point isn't set.
180 183

  
181
  return $_[0]->reqdate if $_[0]->type ne 'sales_quotation';
184
  return $_[0]->reqdate if $_[0]->type ne SALES_QUOTATION_TYPE();
182 185
}
183 186

  
184 187
sub effective_tax_point {
......
190 193
sub displayable_type {
191 194
  my $type = shift->type;
192 195

  
193
  return $::locale->text('Sales quotation')   if $type eq 'sales_quotation';
194
  return $::locale->text('Request quotation') if $type eq 'request_quotation';
195
  return $::locale->text('Sales Order')       if $type eq 'sales_order';
196
  return $::locale->text('Purchase Order')    if $type eq 'purchase_order';
196
  return $::locale->text('Sales quotation')   if $type eq SALES_QUOTATION_TYPE();
197
  return $::locale->text('Request quotation') if $type eq REQUEST_QUOTATION_TYPE();
198
  return $::locale->text('Sales Order')       if $type eq SALES_ORDER_TYPE();
199
  return $::locale->text('Purchase Order')    if $type eq PURCHASE_ORDER_TYPE();
197 200

  
198 201
  die 'invalid type';
199 202
}
......
212 215

  
213 216
  return 1 if $self->currency_id == $::instance_conf->get_currency_id;
214 217

  
215
  my $rate = (any { $self->is_type($_) } qw(sales_quotation sales_order))      ? 'buy'
216
           : (any { $self->is_type($_) } qw(request_quotation purchase_order)) ? 'sell'
218
  my $rate = (any { $self->is_type($_) } (SALES_QUOTATION_TYPE(), SALES_ORDER_TYPE()))      ? 'buy'
219
           : (any { $self->is_type($_) } (REQUEST_QUOTATION_TYPE(), PURCHASE_ORDER_TYPE())) ? 'sell'
217 220
           : undef;
218 221
  return if !$rate;
219 222

  
......
303 306

  
304 307
sub convert_to_reclamation {
305 308
  my ($self, %params) = @_;
306
  $params{destination_type} = $self->is_sales ? 'sales_reclamation'
307
                                              : 'purchase_reclamation';
309
  $params{destination_type} = $self->is_sales ? SALES_RECLAMATION_TYPE()
310
                                              : PURCHASE_RECLAMATION_TYPE();
308 311

  
309 312
  require SL::DB::Reclamation;
310 313
  my $reclamation = SL::DB::Reclamation->new_from($self, %params);
......
335 338
  my $destination_type  = delete $params{destination_type};
336 339

  
337 340
  my @from_tos = (
338
    { from => 'sales_quotation',   to => 'sales_order',       abbr => 'sqso' },
339
    { from => 'request_quotation', to => 'purchase_order',    abbr => 'rqpo' },
340
    { from => 'sales_quotation',   to => 'sales_quotation',   abbr => 'sqsq' },
341
    { from => 'sales_order',       to => 'sales_order',       abbr => 'soso' },
342
    { from => 'request_quotation', to => 'request_quotation', abbr => 'rqrq' },
343
    { from => 'purchase_order',    to => 'purchase_order',    abbr => 'popo' },
344
    { from => 'sales_order',       to => 'purchase_order',    abbr => 'sopo' },
345
    { from => 'purchase_order',    to => 'sales_order',       abbr => 'poso' },
346
    { from => 'sales_order',       to => 'sales_quotation',   abbr => 'sosq' },
347
    { from => 'purchase_order',    to => 'request_quotation', abbr => 'porq' },
348
    { from => 'request_quotation', to => 'sales_quotation',   abbr => 'rqsq' },
349
    { from => 'request_quotation', to => 'sales_order',       abbr => 'rqso' },
350
    { from => 'sales_quotation',   to => 'request_quotation', abbr => 'sqrq' },
351
    { from => 'sales_order',       to => 'request_quotation', abbr => 'sorq' },
352
    { from => 'sales_reclamation', to => 'sales_order',       abbr => 'srso' },
353
    { from => 'purchase_reclamation', to => 'purchase_order', abbr => 'prpo' },
341
    { from => SALES_QUOTATION_TYPE(),      to => SALES_ORDER_TYPE(),       abbr => 'sqso' },
342
    { from => REQUEST_QUOTATION_TYPE(),    to => PURCHASE_ORDER_TYPE(),    abbr => 'rqpo' },
343
    { from => SALES_QUOTATION_TYPE(),      to => SALES_QUOTATION_TYPE(),   abbr => 'sqsq' },
344
    { from => SALES_ORDER_TYPE(),          to => SALES_ORDER_TYPE(),       abbr => 'soso' },
345
    { from => REQUEST_QUOTATION_TYPE(),    to => REQUEST_QUOTATION_TYPE(), abbr => 'rqrq' },
346
    { from => PURCHASE_ORDER_TYPE(),       to => PURCHASE_ORDER_TYPE(),    abbr => 'popo' },
347
    { from => SALES_ORDER_TYPE(),          to => PURCHASE_ORDER_TYPE(),    abbr => 'sopo' },
348
    { from => PURCHASE_ORDER_TYPE(),       to => SALES_ORDER_TYPE(),       abbr => 'poso' },
349
    { from => SALES_ORDER_TYPE(),          to => SALES_QUOTATION_TYPE(),   abbr => 'sosq' },
350
    { from => PURCHASE_ORDER_TYPE(),       to => REQUEST_QUOTATION_TYPE(), abbr => 'porq' },
351
    { from => REQUEST_QUOTATION_TYPE(),    to => SALES_QUOTATION_TYPE(),   abbr => 'rqsq' },
352
    { from => REQUEST_QUOTATION_TYPE(),    to => SALES_ORDER_TYPE(),       abbr => 'rqso' },
353
    { from => SALES_QUOTATION_TYPE(),      to => REQUEST_QUOTATION_TYPE(), abbr => 'sqrq' },
354
    { from => SALES_ORDER_TYPE(),          to => REQUEST_QUOTATION_TYPE(), abbr => 'sorq' },
355
    { from => SALES_RECLAMATION_TYPE(),    to => SALES_ORDER_TYPE(),       abbr => 'srso' },
356
    { from => PURCHASE_RECLAMATION_TYPE(), to => PURCHASE_ORDER_TYPE(),    abbr => 'prpo' },
354 357
  );
355 358
  my $from_to = (grep { $_->{from} eq $source->type && $_->{to} eq $destination_type} @from_tos)[0];
356 359
  croak("Cannot convert from '" . $source->type . "' to '" . $destination_type . "'") if !$from_to;
......
571 574
  push @items, @{$_->items_sorted} for @$sources;
572 575
  # make order from first source and all items
573 576
  my $order = $class->new_from($sources->[0],
574
                               destination_type => 'sales_order',
577
                               destination_type => SALES_ORDER_TYPE(),
575 578
                               attributes       => \%attributes,
576 579
                               items            => \@items,
577 580
                               %params);
......
585 588
  return if !$self->type;
586 589

  
587 590
  my %number_method = (
588
    sales_order       => 'ordnumber',
589
    sales_quotation   => 'quonumber',
590
    purchase_order    => 'ordnumber',
591
    request_quotation => 'quonumber',
591
    SALES_ORDER_TYPE()       => 'ordnumber',
592
    SALES_QUOTATION_TYPE()   => 'quonumber',
593
    PURCHASE_ORDER_TYPE()    => 'ordnumber',
594
    REQUEST_QUOTATION_TYPE() => 'quonumber',
592 595
  );
593 596

  
594 597
  return $self->${ \ $number_method{$self->type} }(@_);

Auch abrufbar als: Unified diff