Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision ad04be0a

Von Sven Schöling vor etwa 3 Jahren hinzugefügt

  • ID ad04be0a69322e1d3e103f3e0eeed771dbc82649
  • Vorgänger f855da37
  • Nachfolger fc6b8640

DeliveryOrder: type data zentralisiert um das verhalten besser generalisieren zu können

Unterschiede anzeigen:

SL/Controller/DeliveryOrder.pm
33 33
use SL::Helper::UserPreferences::UpdatePositions;
34 34

  
35 35
use SL::Controller::Helper::GetModels;
36
use SL::Controller::DeliveryOrder::TypeData;
36 37

  
37 38
use List::Util qw(first sum0);
38 39
use List::UtilsBy qw(sort_by uniq_by);
......
65 66
  my ($self) = @_;
66 67

  
67 68
  $self->order->transdate(DateTime->now_local());
68
  my $extra_days = $self->type eq sales_quotation_type() ? $::instance_conf->get_reqdate_interval       :
69
                   $self->type eq sales_order_type()     ? $::instance_conf->get_delivery_date_interval : 1;
70

  
71
  if (   ($self->type eq sales_order_type()     &&  $::instance_conf->get_deliverydate_on)
72
      || ($self->type eq sales_quotation_type() &&  $::instance_conf->get_reqdate_on)
73
      && (!$self->order->reqdate)) {
74
    $self->order->reqdate(DateTime->today_local->next_workday(extra_days => $extra_days));
75
  }
69
  $self->set_reqdate_by_type;
76 70

  
77 71

  
78 72
  $self->pre_render();
......
152 146
    return $self->js->render();
153 147
  }
154 148

  
155
  my $text = $self->type eq sales_order_type()       ? $::locale->text('The order has been deleted')
156
           : $self->type eq purchase_order_type()    ? $::locale->text('The order has been deleted')
157
           : $self->type eq sales_quotation_type()   ? $::locale->text('The quotation has been deleted')
158
           : $self->type eq request_quotation_type() ? $::locale->text('The rfq has been deleted')
159
           : '';
160
  flash_later('info', $text);
149
  flash_later('info', $self->type_data->text("delete"));
161 150

  
162 151
  my @redirect_params = (
163 152
    action => 'add',
......
178 167
    return $self->js->render();
179 168
  }
180 169

  
181
  my $text = $self->type eq sales_order_type()       ? $::locale->text('The order has been saved')
182
           : $self->type eq purchase_order_type()    ? $::locale->text('The order has been saved')
183
           : $self->type eq sales_quotation_type()   ? $::locale->text('The quotation has been saved')
184
           : $self->type eq request_quotation_type() ? $::locale->text('The rfq has been saved')
185
           : '';
186
  flash_later('info', $text);
170
  flash_later('info', $self->type_data->text("saved"));
187 171

  
188 172
  my @redirect_params = (
189 173
    action => 'edit',
......
221 205
                        : $order->transdate;
222 206

  
223 207
  # Set new reqdate unless changed if it is enabled in client config
224
  if ($order->reqdate == $saved_order->reqdate) {
225
    my $extra_days = $self->type eq sales_quotation_type() ? $::instance_conf->get_reqdate_interval       :
226
                     $self->type eq sales_order_type()     ? $::instance_conf->get_delivery_date_interval : 1;
227

  
228
    if (   ($self->type eq sales_order_type()     &&  !$::instance_conf->get_deliverydate_on)
229
        || ($self->type eq sales_quotation_type() &&  !$::instance_conf->get_reqdate_on)) {
230
      $new_attrs{reqdate} = '';
231
    } else {
232
      $new_attrs{reqdate} = DateTime->today_local->next_workday(extra_days => $extra_days);
233
    }
234
  } else {
235
    $new_attrs{reqdate} = $order->reqdate;
236
  }
208
  $new_attrs{reqdate} = $self->get_reqdate_by_type($order->reqdate, $saved_order->reqdate);
237 209

  
238 210
  # Update employee
239 211
  $new_attrs{employee}  = SL::DB::Manager::Employee->current;
......
1049 1021
# helpers
1050 1022
#
1051 1023

  
1052
sub init_valid_types {
1053
  [ sales_order_type(), purchase_order_type(), sales_quotation_type(), request_quotation_type() ];
1054
}
1055

  
1056 1024
sub init_type {
1057 1025
  my ($self) = @_;
1058 1026

  
......
1066 1034
sub init_cv {
1067 1035
  my ($self) = @_;
1068 1036

  
1069
  my $cv = (any { $self->type eq $_ } (sales_order_type(),    sales_quotation_type()))   ? 'customer'
1070
         : (any { $self->type eq $_ } (purchase_order_type(), request_quotation_type())) ? 'vendor'
1071
         : die "Not a valid type for order";
1072

  
1073
  return $cv;
1037
  return $self->type_data->customervendor;
1074 1038
}
1075 1039

  
1076 1040
sub init_search_cvpartnumber {
......
1104 1068

  
1105 1069
sub init_part_picker_classification_ids {
1106 1070
  my ($self)    = @_;
1107
  my $attribute = 'used_for_' . ($self->type =~ m{sales} ? 'sale' : 'purchase');
1108 1071

  
1109
  return [ map { $_->id } @{ SL::DB::Manager::PartClassification->get_all(where => [ $attribute => 1 ]) } ];
1072
  return [ map { $_->id } @{ SL::DB::Manager::PartClassification->get_all(where => $self->type_date->part_classification_query) } ];
1110 1073
}
1111 1074

  
1112 1075
sub check_auth {
1113 1076
  my ($self) = @_;
1114 1077

  
1115
  my $right_for = { map { $_ => $_.'_edit' } @{$self->valid_types} };
1116

  
1117
  my $right   = $right_for->{ $self->type };
1118
  $right    ||= 'DOES_NOT_EXIST';
1119

  
1120
  $::auth->assert($right);
1078
  $::auth->assert($self->type_data->access || 'DOES_NOT_EXIST');
1121 1079
}
1122 1080

  
1123 1081
# build the selection box for contacts
......
1204 1162
  my $order;
1205 1163
  $order   = SL::DB::DeliveryOrder->new(id => $::form->{id})->load(with => [ 'orderitems', 'orderitems.part' ]) if $::form->{id};
1206 1164
  $order ||= SL::DB::DeliveryOrder->new(orderitems  => [],
1207
                                quotation   => (any { $self->type eq $_ } (sales_quotation_type(), request_quotation_type())),
1165
                                quotation   => $self->type_data->is_quotation,
1208 1166
                                currency_id => $::instance_conf->get_currency_id(),);
1209 1167

  
1210 1168
  my $cv_id_method = $self->cv . '_id';
......
1485 1443
    return $self->js->render();
1486 1444
  }
1487 1445

  
1488
  my $destination_type = $::form->{type} eq sales_order_type() ? sales_quotation_type() : request_quotation_type();
1446
  my $destination_type = $self->type_data->workflow("to_quotation_type");
1489 1447

  
1490 1448
  $self->order(SL::DB::DeliveryOrder->new_from($self->order, destination_type => $destination_type));
1491 1449
  $self->{converted_from_oe_id} = delete $::form->{id};
......
1527 1485
    return $self->js->render();
1528 1486
  }
1529 1487

  
1530
  my $destination_type = $::form->{type} eq sales_quotation_type()   ? sales_order_type()
1531
                       : $::form->{type} eq request_quotation_type() ? purchase_order_type()
1532
                       : $::form->{type} eq purchase_order_type()    ? sales_order_type()
1533
                       : $::form->{type} eq sales_order_type()       ? purchase_order_type()
1534
                       : '';
1488
  my $destination_type = $self->type_data->workflow("to_order_type");
1535 1489

  
1536 1490
  # check for direct delivery
1537 1491
  # copy shipto in custom shipto (custom shipto will be copied by new_from() in case)
1538 1492
  my $custom_shipto;
1539
  if (   $::form->{type} eq sales_order_type() && $destination_type eq purchase_order_type()
1540
      && $::form->{use_shipto} && $self->order->shipto) {
1493
  if ($self->type_data->workflow("to_order_copy_shipto") && $::form->{use_shipto} && $self->order->shipto) {
1541 1494
    $custom_shipto = $self->order->shipto->clone('SL::DB::DeliveryOrder');
1542 1495
  }
1543 1496

  
......
1549 1502
    $item->{new_fake_id} = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
1550 1503
  }
1551 1504

  
1552
  if ($::form->{type} eq sales_order_type() && $destination_type eq purchase_order_type()) {
1505
  if ($self->type_data->workflow("to_order_copy_shipto")) {
1553 1506
    if ($::form->{use_shipto}) {
1554 1507
      $self->order->custom_shipto($custom_shipto) if $custom_shipto;
1555 1508
    } else {
......
1619 1572
    $item->active_discount_source($price_source->discount_from_source($item->active_discount_source));
1620 1573
  }
1621 1574

  
1622
  if (any { $self->type eq $_ } (sales_order_type(), purchase_order_type())) {
1623
    # Calculate shipped qtys here to prevent calling calculate for every item via the items method.
1624
    # Do not use write_to_objects to prevent order->delivered to be set, because this should be
1625
    # the value from db, which can be set manually or is set when linked delivery orders are saved.
1626
    SL::Helper::ShippedQty->new->calculate($self->order)->write_to(\@{$self->order->items});
1627
  }
1628

  
1629 1575
  if ($self->order->number && $::instance_conf->get_webdav) {
1630 1576
    my $webdav = SL::Webdav->new(
1631 1577
      type     => $self->type,
......
1648 1594
sub setup_edit_action_bar {
1649 1595
  my ($self, %params) = @_;
1650 1596

  
1651
  my $deletion_allowed = (any { $self->type eq $_ } (sales_quotation_type(), request_quotation_type()))
1652
                      || (($self->type eq sales_order_type())    && $::instance_conf->get_sales_order_show_delete)
1653
                      || (($self->type eq purchase_order_type()) && $::instance_conf->get_purchase_order_show_delete);
1597
  my $deletion_allowed = $self->type_data->show_menu("delete");
1654 1598

  
1655 1599
  for my $bar ($::request->layout->get('actionbar')) {
1656 1600
    $bar->add(
......
1675 1619
        action => [
1676 1620
          t8('Save and Quotation'),
1677 1621
          submit   => [ '#order_form', { action => "DeliveryOrder/sales_quotation" } ],
1678
          only_if  => (any { $self->type eq $_ } (sales_order_type())),
1622
          only_if  => $self->type_data->show_menu("save_and_quotation"),
1679 1623
        ],
1680 1624
        action => [
1681 1625
          t8('Save and RFQ'),
1682 1626
          submit   => [ '#order_form', { action => "DeliveryOrder/request_for_quotation" } ],
1683
          only_if  => (any { $self->type eq $_ } (purchase_order_type())),
1627
          only_if  => $self->type_data->show_menu("save_and_rfq"),
1684 1628
        ],
1685 1629
        action => [
1686 1630
          t8('Save and Sales Order'),
1687 1631
          submit   => [ '#order_form', { action => "DeliveryOrder/sales_order" } ],
1688
          only_if  => (any { $self->type eq $_ } (sales_quotation_type(), purchase_order_type())),
1632
          only_if  => $self->type_data->show_menu("save_and_sales_order"),
1689 1633
        ],
1690 1634
        action => [
1691 1635
          t8('Save and Purchase Order'),
1692 1636
          call      => [ 'kivi.Order.purchase_order_check_for_direct_delivery' ],
1693
          only_if   => (any { $self->type eq $_ } (sales_order_type(), request_quotation_type())),
1637
          only_if  => $self->type_data->show_menu("save_and_purchase_order"),
1694 1638
        ],
1695 1639
        action => [
1696 1640
          t8('Save and Delivery Order'),
1697 1641
          call      => [ 'kivi.Order.save', 'save_and_delivery_order', $::instance_conf->get_order_warn_duplicate_parts,
1698 1642
                                                                       $::instance_conf->get_order_warn_no_deliverydate,
1699 1643
                                                                                                                        ],
1700
          only_if   => (any { $self->type eq $_ } (sales_order_type(), purchase_order_type()))
1644
          only_if  => $self->type_data->show_menu("save_and_delivery_order"),
1701 1645
        ],
1702 1646
        action => [
1703 1647
          t8('Save and Invoice'),
......
1706 1650
        action => [
1707 1651
          t8('Save and AP Transaction'),
1708 1652
          call      => [ 'kivi.Order.save', 'save_and_ap_transaction', $::instance_conf->get_order_warn_duplicate_parts ],
1709
          only_if   => (any { $self->type eq $_ } (purchase_order_type()))
1653
          only_if  => $self->type_data->show_menu("save_and_ap_transaction"),
1710 1654
        ],
1711 1655

  
1712 1656
      ], # end of combobox "Workflow"
......
1748 1692
        call     => [ 'kivi.Order.delete_order' ],
1749 1693
        confirm  => $::locale->text('Do you really want to delete this object?'),
1750 1694
        disabled => !$self->order->id ? t8('This object has not been saved yet.') : undef,
1751
        only_if  => $deletion_allowed,
1695
        only_if  => $self->type_data->show_menu("delete"),
1752 1696
      ],
1753 1697

  
1754 1698
      combobox => [
......
1869 1813
  my ($self, $action) = @_;
1870 1814

  
1871 1815
  return '' if none { lc($action)} qw(add edit);
1872

  
1873
  # for locales:
1874
  # $::locale->text("Add Sales Order");
1875
  # $::locale->text("Add Purchase Order");
1876
  # $::locale->text("Add Quotation");
1877
  # $::locale->text("Add Request for Quotation");
1878
  # $::locale->text("Edit Sales Order");
1879
  # $::locale->text("Edit Purchase Order");
1880
  # $::locale->text("Edit Quotation");
1881
  # $::locale->text("Edit Request for Quotation");
1882

  
1883
  $action = ucfirst(lc($action));
1884
  return $self->type eq sales_order_type()       ? $::locale->text("$action Sales Order")
1885
       : $self->type eq purchase_order_type()    ? $::locale->text("$action Purchase Order")
1886
       : $self->type eq sales_quotation_type()   ? $::locale->text("$action Quotation")
1887
       : $self->type eq request_quotation_type() ? $::locale->text("$action Request for Quotation")
1888
       : '';
1816
  return $self->type_data->text($action);
1889 1817
}
1890 1818

  
1891 1819
sub get_item_cvpartnumber {
......
1927 1855
  return $texts;
1928 1856
}
1929 1857

  
1930
sub sales_order_type {
1931
  'sales_order';
1932
}
1933

  
1934
sub purchase_order_type {
1935
  'purchase_order';
1936
}
1937

  
1938
sub sales_quotation_type {
1939
  'sales_quotation';
1940
}
1941

  
1942
sub request_quotation_type {
1943
  'request_quotation';
1944
}
1945

  
1946 1858
sub nr_key {
1947
  return $_[0]->type eq sales_order_type()       ? 'ordnumber'
1948
       : $_[0]->type eq purchase_order_type()    ? 'ordnumber'
1949
       : $_[0]->type eq sales_quotation_type()   ? 'quonumber'
1950
       : $_[0]->type eq request_quotation_type() ? 'quonumber'
1951
       : '';
1859
  return $_[0]->type_data->nr_key;
1952 1860
}
1953 1861

  
1954 1862
sub save_and_redirect_to {
......
1961 1869
    return $self->js->render();
1962 1870
  }
1963 1871

  
1964
  my $text = $self->type eq sales_order_type()       ? $::locale->text('The order has been saved')
1965
           : $self->type eq purchase_order_type()    ? $::locale->text('The order has been saved')
1966
           : $self->type eq sales_quotation_type()   ? $::locale->text('The quotation has been saved')
1967
           : $self->type eq request_quotation_type() ? $::locale->text('The rfq has been saved')
1968
           : '';
1969
  flash_later('info', $text);
1872
  flash_later('info', $self->type_data->text("saved"));
1970 1873

  
1971 1874
  $self->redirect_to(%params, id => $self->order->id);
1972 1875
}
......
1974 1877
sub save_history {
1975 1878
  my ($self, $addition) = @_;
1976 1879

  
1977
  my $number_type = $self->order->type =~ m{order} ? 'ordnumber' : 'quonumber';
1880
  my $number_type = $self->nr_key;
1978 1881
  my $snumbers    = $number_type . '_' . $self->order->$number_type;
1979 1882

  
1980 1883
  SL::DB::History->new(
......
2026 1929
  return @errors;
2027 1930
}
2028 1931

  
1932
sub init_type_data {
1933
  SL::Controller::DeliveryOrder::TypeData->new($_[0]);
1934
}
1935

  
1936
sub init_valid_types {
1937
  $_[0]->type_data->valid_types;
1938
}
1939

  
2029 1940
1;
2030 1941

  
2031 1942
__END__
SL/Controller/DeliveryOrder/TypeData.pm
1
package SL::Controller::DeliveryOrder::TypeData;
2

  
3
use strict;
4
use Exporter qw(import);
5
use Scalar::Util qw(weaken);
6
use SL::Locale::String qw(t8);
7

  
8
use constant {
9
  SALES_ORDER_TYPE => 'sales_order',
10
  PURCHASE_ORDER_TYPE => 'purchase_order',
11
  SALES_QUOTATION_TYPE => 'sales_quotation',
12
  REQUEST_QUOTATION_TYPE => 'request_quotation'
13
};
14

  
15
our @EXPORT_OK = qw(SALES_ORDER_TYPE PURCHASE_ORDER_TYPE SALES_QUOTATION_TYPE REQUEST_QUOTATION_TYPE);
16

  
17
use Rose::Object::MakeMethods::Generic scalar => [ qw(c) ];
18

  
19
my %type_data = (
20
  SALES_ORDER_TYPE() => {
21
    text => {
22
      delete => t8('The order has been deleted'),
23
      saved  => t8('The order has been saved'),
24
      add    => t8("Add Sales Order"),
25
      edit   => t8("Edit Sales Order"),
26
    },
27
    show_menu => {
28
      save_and_quotation      => 1,
29
      save_and_rfq            => 0,
30
      save_and_sales_order    => 0,
31
      save_and_purchase_order => 1,
32
      save_and_delivery_order => 1,
33
      save_and_ap_transaction => 0,
34
      delete                  => sub { $::instance_conf->get_sales_order_show_delete },
35
    },
36
    workflow => {
37
      to_order_type        => "purchase_order",
38
      to_quotation_type    => "sales_quotation",
39
      to_order_copy_shipto => 1,
40
    },
41
    properties => {
42
      customervendor => "customer",
43
      is_quotation   => 0,
44
      nr_key         => "ordnumber",
45
    },
46
    part_classification_query => [ "used_for_sale" => 1 ],
47
    right => "sales_order_edit",
48
  },
49
  PURCHASE_ORDER_TYPE() => {
50
    text =>{
51
      delete => t8('The order has been deleted'),
52
      saved  => t8('The order has been saved'),
53
      add    => t8("Add Purchase Order"),
54
      edit   => t8("Edit Purchase Order"),
55
    },
56
    show_menu => {
57
      save_and_quotation      => 0,
58
      save_and_rfq            => 1,
59
      save_and_sales_order    => 1,
60
      save_and_purchase_order => 0,
61
      save_and_delivery_order => 1,
62
      save_and_ap_transaction => 1,
63
      delete                  => sub { $::instance_conf->get_purchase_order_show_delete },
64
    },
65
    workflow => {
66
      to_order_type        => "sales_order",
67
      to_quotation_type    => "request_quotation",
68
      to_order_copy_shipto => 0,
69
    },
70
    properties => {
71
      customervendor => "vendor",
72
      is_quotation   => 0,
73
      nr_key         => "ordnumber",
74
    },
75
    part_classification_query => [ "used_for_purchase" => 1 ],
76
    right => "purchase_order_edit",
77
  },
78
  SALES_QUOTATION_TYPE() => {
79
    text => {
80
      delete => t8('The quotation has been deleted'),
81
      saved  => t8('The quotation has been saved'),
82
      add    => t8("Add Quotation"),
83
      edit   => t8("Edit Quotation"),
84
    },
85
    show_menu => {
86
      save_and_quotation      => 0,
87
      save_and_rfq            => 0,
88
      save_and_sales_order    => 1,
89
      save_and_purchase_order => 0,
90
      save_and_delivery_order => 0,
91
      save_and_ap_transaction => 0,
92
      delete                  => 1,
93
    },
94
    workflow => {
95
      to_order_type        => "sales_order",
96
      to_quotation_type    => "request_quotation",
97
      to_order_copy_shipto => 0,
98
    },
99
    properties => {
100
      customervendor => "customer",
101
      is_quotation   => 1,
102
      nr_key         => "quonumber",
103
    },
104
    part_classification_query => [ "used_for_sale" => 1 ],
105
    right => "sales_quotation_edit",
106
  },
107
  REQUEST_QUOTATION_TYPE() => {
108
    text => {
109
      delete => t8('The rfq has been deleted'),
110
      saved  => t8('The rfq has been saved'),
111
      add    => t8("Add Request for Quotation"),
112
      edit   => t8("Edit Request for Quotation"),
113
    },
114
    show_menu => {
115
      save_and_quotation      => 0,
116
      save_and_rfq            => 0,
117
      save_and_sales_order    => 0,
118
      save_and_purchase_order => 1,
119
      save_and_delivery_order => 0,
120
      save_and_ap_transaction => 0,
121
      delete                  => 1,
122
    },
123
    workflow => {
124
      to_order_type        => "purchase_order",
125
      to_quotation_type    => "request_quotation",
126
      to_order_copy_shipto => 0,
127
    },
128
    properties => {
129
      customervendor => "vendor",
130
      is_quotation   => 1,
131
      nr_key         => "quonumber",
132
    },
133
    part_classification_query => [ "used_for_purchase" => 1 ],
134
    right => "request_quotation_edit",
135
  },
136
);
137

  
138
sub new {
139
  my ($class, $controller) = @_;
140
  my $o = bless {}, $class;
141
  $o->c($controller);
142
  weaken($o->{c});
143

  
144
  return $o;
145
}
146

  
147
sub valid_types {
148
  [
149
    SALES_ORDER_TYPE,
150
    PURCHASE_ORDER_TYPE,
151
    SALES_QUOTATION_TYPE,
152
    REQUEST_QUOTATION_TYPE,
153
  ];
154
}
155

  
156
sub type {
157
  $_[0]->c->type;
158
}
159

  
160
sub get {
161
  my ($self, $key) = @_;
162

  
163
  my $ret = $type_data{$self->type}->{$key} // die "unknown property '$key'";
164

  
165
  ref $ret eq 'CODE'
166
    ? $ret->()
167
    : $ret;
168
}
169

  
170
sub _get3 {
171
  my ($self, $topic, $key) = @_;
172

  
173
  my $ret = $type_data{$self->type}->{$topic}->{$key} // die "unknown property '$key' in topic '$topic'";
174

  
175
  ref $ret eq 'CODE'
176
    ? $ret->()
177
    : $ret;
178
}
179

  
180
sub text {
181
  my ($self, $string) = @_;
182
  _get3($self, "text", $string);
183
}
184

  
185
sub show_menu {
186
  my ($self, $string) = @_;
187
  _get3($self, "show_menu", $string);
188
}
189

  
190
sub workflow {
191
  my ($self, $string) = @_;
192
  _get3($self, "workflow", $string);
193
}
194

  
195
sub properties {
196
  my ($self, $string) = @_;
197
  _get3($self, "properties", $string);
198
}
199

  
200
sub is_valid_type {
201
  !!exists $type_data{$_[1]};
202
}
203

  
204
sub type_data {
205
  $type_data{ $_[0]->type } // die "unknown type";
206
}
207

  
208
sub access {
209
  $type_data{right};
210
}
211

  
212
sub is_quotation {
213
  _get3($_[0], "properties", "is_quotation");
214
}
215

  
216
sub customervendor {
217
  _get3($_[0], "properties", "customervendor");
218
}
219

  
220
sub nr_key {
221
  _get3($_[0], "properties", "nr_key");
222
}
223

  
224
sub part_classification_query {
225
  my ($self, $string) = @_;
226
  _get($self, "part_classification_query");
227
}
228

  
229
sub set_reqdate_by_type {
230
  my ($self) = @_;
231

  
232
  my $extra_days = $self->type eq SALES_QUOTATION_TYPE ? $::instance_conf->get_reqdate_interval       :
233
                   $self->type eq SALES_ORDER_TYPE     ? $::instance_conf->get_delivery_date_interval : 1;
234

  
235
  if (   ($self->type eq SALES_ORDER_TYPE     &&  $::instance_conf->get_deliverydate_on)
236
      || ($self->type eq SALES_QUOTATION_TYPE &&  $::instance_conf->get_reqdate_on)
237
      && (!$self->order->reqdate)) {
238
    $self->c->order->reqdate(DateTime->today_local->next_workday(extra_days => $extra_days));
239
  }
240
}
241

  
242
sub get_reqdate_by_type {
243
  my ($self, $reqdate, $saved_reqdate) = @_;
244

  
245
  if ($reqdate == $saved_reqdate) {
246
    my $extra_days = $self->type eq SALES_QUOTATION_TYPE ? $::instance_conf->get_reqdate_interval       :
247
                     $self->type eq SALES_ORDER_TYPE     ? $::instance_conf->get_delivery_date_interval : 1;
248

  
249
    if (   ($self->type eq SALES_ORDER_TYPE     &&  !$::instance_conf->get_deliverydate_on)
250
        || ($self->type eq SALES_QUOTATION_TYPE &&  !$::instance_conf->get_reqdate_on)) {
251
      return '';
252
    } else {
253
      return DateTime->today_local->next_workday(extra_days => $extra_days);
254
    }
255
  } else {
256
    return $reqdate;
257
  }
258
}

Auch abrufbar als: Unified diff