+sub cache_parts {
+  my ($self, @ids) = @_;
+
+  my $parts = !@ids ? [] : SL::DB::Manager::Part->get_all(
+    where        => [ id => \@ids ],
+    with_objects => [ qw(unit_obj) ],
+  );
+
+  $self->parts({ map { ($_->id => $_) } @{ $parts } });
+}
+
+sub do_update_sections {
+  my ($self)           = @_;
+
+  my $order            = $self->rs_order->order;
+  my $sections         = $self->requirement_spec->sections_sorted;
+  my %orderitems_by_id = map { ($_->id => $_) } @{ $order->orderitems };
+  my %sections_by_id   = map { ($_->id => $_) } @{ $sections };
+  my $language_id      = $self->requirement_spec->customer->language_id;
+
+  $self->cache_parts(uniq map { $_->order_part_id } @{ $sections });
+
+  my %sections_seen;
+
+  foreach my $attributes (@{ $::form->{orderitems} || [] }) {
+    my $orderitem = $orderitems_by_id{ $attributes->{id}         };
+    my $section   = $sections_by_id{   $attributes->{section_id} };
+    next unless $orderitem && $section;
+
+    $self->create_order_item(section => $section, item => $orderitem, language_id => $language_id)->save;
+    $sections_seen{ $section->id } = 1;
+  }
+
+  my @new_orderitems = map  { $self->create_order_item(section => $_, language_id => $language_id) }
+                       grep { !$sections_seen{ $_->id } }
+                       @{ $sections };
+
+  return @new_orderitems;
+}
+
+sub do_update_additional_parts {
+  my ($self)        = @_;
+
+  my $order         = $self->rs_order->order;
+  my $add_parts     = $self->requirement_spec->parts_sorted;
+  my %orderitems_by = map { (($_->parts_id . '-' . $_->description) => $_) } @{ $order->items };
+  my $language_id   = $self->requirement_spec->customer->language_id;
+
+  $self->cache_parts(uniq map { $_->part_id } @{ $add_parts });
+
+  my %add_part_seen;
+  my @new_orderitems;
+
+  foreach my $add_part (@{ $add_parts }) {
+    my $key       = $add_part->part_id . '-' . $add_part->description;
+    my $orderitem = $orderitems_by{$key};
+
+    if ($orderitem) {
+      $self->create_additional_part_order_item(additional_part => $add_part, item => $orderitem, language_id => $language_id)->save;
+
+    } else {
+      push @new_orderitems, $self->create_additional_part_order_item(additional_part => $add_part, language_id => $language_id);
+    }
+  }
+
+  return @new_orderitems;
+}
+
+sub create_order_item {
+  my ($self, %params) = @_;
+
+  my $section         = $params{section};
+  my $item            = $params{item} || SL::DB::OrderItem->new;
+  my $part            = $self->parts->{ $section->order_part_id };
+  my $is_time_based   = $part->unit_obj->is_time_based;
+  my $translation     = $params{language_id} ? first { $params{language_id} == $_->language_id } @{ $part->translations } : {};
+  my $description     = $section->{keep_description} ? $item->description : ($translation->{translation} || $part->description);
+  my $longdescription = $translation->{longdescription} || $part->notes;
+
+  if (!$section->{keep_description}) {
+    $description     = '<%fb_number%> <%title%>' unless $description =~ m{<%};
+    $longdescription = '<%description%>'   unless $longdescription =~ m{<%};
+
+    $description     =~ s{<% (.+?) %>}{ $section->can($1) ? $section->$1 : '<' . t8('Invalid variable #1', $1) . '>' }egx;
+    $longdescription =~ s{\<\% description \%\>}{!!!!DESCRIPTION!!!!}gx;
+    $longdescription =~ s{<[pP]> !!!!DESCRIPTION!!!! </[pP]>}{!!!!DESCRIPTION!!!!}gx;
+    $longdescription =~ s{\<\% (.+?) \%\>}{ $section->can($1) ? $::locale->quote_special_chars('HTML', $section->$1 // '') : '<' . t8('Invalid variable #1', $1) . '>' }egx;
+    $longdescription =~ s{!!!!DESCRIPTION!!!!}{ $section->description // '' }egx;
+  }
+
+  $item->assign_attributes(
+    parts_id        => $part->id,
+    description     => $description,
+    longdescription => $longdescription,
+    qty             => $is_time_based ? $section->time_estimation * 1 : 1,
+    unit            => $is_time_based ? $self->h_unit_name            : $part->unit,
+    sellprice       => $::form->round_amount($self->requirement_spec->hourly_rate * ($is_time_based ? 1 : $section->time_estimation), 2),
+    lastcost        => $part->lastcost,
+    discount        => 0,
+    project_id      => $self->requirement_spec->project_id,
+  );
+
+  return $item;
+}
+
+sub create_additional_part_order_item {
+  my ($self, %params) = @_;
+
+  my $add_part        = $params{additional_part};
+  my $item            = $params{item} || SL::DB::OrderItem->new;
+  my $part            = $self->parts->{ $add_part->part_id };
+  my $translation     = $params{language_id} ? first { $params{language_id} == $_->language_id } @{ $part->translations } : {};
+  my $description     = $item->description              || $add_part->description;
+  my $longdescription = $translation->{longdescription} || $part->notes;
+
+  $item->assign_attributes(
+    parts_id        => $part->id,
+    description     => $description,
+    longdescription => $longdescription,
+    qty             => $add_part->qty,
+    unit            => $add_part->unit->name,
+    sellprice       => $add_part->unit->convert_to($part->sellprice, $part->unit_obj),
+    lastcost        => $part->lastcost,
+    discount        => 0,
+    project_id      => $self->requirement_spec->project_id,
+  );
+
+  return $item;
+}
+
+sub create_order {
+  my ($self, %params) = @_;
+
+  my @part_ids = (
+    map({ $_->{order_part_id} } @{ $params{sections} }),
+    map({ $_->part_id         } @{ $params{additional_parts} }),
+  );
+  $self->{parts} = { map { ($_->{id} => $_) } @{ SL::DB::Manager::Part->get_all(where => [ id => [ uniq @part_ids ] ]) } };
+
+  my $customer   = SL::DB::Customer->new(id => $::form->{customer_id})->load;
+  my @orderitems = map { $self->create_order_item(                section => $_,         language_id => $customer->language_id) } @{ $params{sections} };
+  my @add_items  = map { $self->create_additional_part_order_item(additional_part => $_, language_id => $customer->language_id) } @{ $params{additional_parts} };
+  my $employee   = SL::DB::Manager::Employee->current;
+  my $order      = SL::DB::Order->new(
+    globalproject_id        => $self->requirement_spec->project_id,
+    transdate               => DateTime->today_local,
+    reqdate                 => $::form->{quotation} && $customer->payment_id ? $customer->payment->calc_date : undef,
+    quotation               => !!$::form->{quotation},
+    orderitems              => [ @orderitems, @add_items ],
+    customer_id             => $customer->id,
+    taxincluded             => $customer->taxincluded,
+    intnotes                => $customer->notes,
+    language_id             => $customer->language_id,
+    payment_id              => $customer->payment_id,
+    taxzone_id              => $customer->taxzone_id,
+    employee_id             => $employee->id,
+    salesman_id             => $employee->id,
+    transaction_description => $self->requirement_spec->displayable_name,
+    currency_id             => $::instance_conf->get_currency_id,
+  );
+
+  $order->calculate_prices_and_taxes;
+
+  return $order;
+}