Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision bcbdd909

Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt

  • ID bcbdd90905edd2aa0086e0912524b329755c96b4
  • Vorgänger 1d11b99c
  • Nachfolger 1c934069

Model::Record: Funktionsaufruf angepasst für new_from_worklow ...

und new_from_workflow_multi

Unterschiede anzeigen:

SL/Controller/DeliveryOrder.pm
my $order = SL::DB::Order->new(id => $self->{converted_from_oe_id})->load;
my $target_type = $::form->{type};
my $delivery_order = SL::Model::Record->new_from_workflow($order, ref($self->order), $target_type);
my $delivery_order = SL::Model::Record->new_from_workflow($order, $target_type);
$self->order($delivery_order);
$self->action_add;
......
my $reclamation = SL::DB::Reclamation->new(id => $::form->{from_id})->load;
my $target_type = $reclamation->is_sales ? 'rma_delivery_order'
: 'supplier_delivery_order';
my $delivery_order = SL::Model::Record->new_from_workflow($reclamation, ref($self->order), $target_type);
my $delivery_order = SL::Model::Record->new_from_workflow($reclamation, $target_type);
$self->{converted_from_reclamation_id} = $::form->{from_id};
$self->order($delivery_order);
......
my @multi_orders = map { SL::DB::DeliveryOrder->new(id => $_)->load } @multi_ids;
$self->{converted_from_oe_id} = join ' ', map { $_->id } @multi_orders;
my $target_type = SALES_DELIVERY_ORDER_TYPE();
my $delivery_order = SL::Model::Record->new_from_workflow_multi(\@multi_orders, ref($self->order), $target_type, sort_sources_by => 'transdate');
my $delivery_order = SL::Model::Record->new_from_workflow_multi(\@multi_orders, $target_type, sort_sources_by => 'transdate');
$self->order($delivery_order);
$self->action_edit();
......
# always save
$self->save();
my $delivery_order = SL::Model::Record->new_from_workflow($self->order, ref($self->order), $destination_type);
my $delivery_order = SL::Model::Record->new_from_workflow($self->order, $destination_type);
$self->order($delivery_order);
$self->{converted_from_oe_id} = delete $::form->{id};
......
# always save
$self->save();
my $delivery_order = SL::Model::Record->new_from_workflow($self->order, ref($self->order), $destination_type);
my $delivery_order = SL::Model::Record->new_from_workflow($self->order, $destination_type);
$self->order($delivery_order);
$self->{converted_from_oe_id} = delete $::form->{id};
SL/Controller/Order.pm
my %params;
my $target_type = $reclamation->is_sales ? SALES_ORDER_TYPE()
: PURCHASE_ORDER_TYPE();
my $order = SL::Model::Record->new_from_workflow($reclamation, 'SL::DB::Order', ref($self->order), $target_type);
my $order = SL::Model::Record->new_from_workflow($reclamation, $target_type);
$self->{converted_from_reclamation_id} = $order->{ RECORD_ID() };
$_ ->{converted_from_reclamation_items_id} = $_ ->{ RECORD_ITEM_ID() } for @{ $order->items_sorted };
......
my @multi_orders = map { SL::DB::Order->new(id => $_)->load } @multi_ids;
$self->{converted_from_oe_id} = join ' ', map { $_->id } @multi_orders;
my $target_type = "sales_order";
my $order = SL::Model::Record->new_from_workflow_multi(\@multi_orders, ref($self->order), $target_type, sort_sources_by => 'transdate');
my $order = SL::Model::Record->new_from_workflow_multi(\@multi_orders, $target_type, sort_sources_by => 'transdate');
$self->order($order);
$self->action_edit();
......
my $no_linked_records = (any { $destination_type eq $_ } (SALES_QUOTATION_TYPE(), REQUEST_QUOTATION_TYPE()))
&& $from_side eq $to_side;
$self->order(SL::Model::Record->new_from_workflow($self->order, 'SL::DB::Order', $destination_type, no_linked_records => $no_linked_records));
$self->order(SL::Model::Record->new_from_workflow($self->order, $destination_type, no_linked_records => $no_linked_records));
delete $::form->{id};
SL/Controller/Reclamation.pm
}
my $order = SL::DB::Order->new(id => $::form->{from_id})->load;
my $reclamation = SL::Model::Record->new_from_workflow($order, ref($self->reclamation), $self->type);
my $reclamation = SL::Model::Record->new_from_workflow($order, $self->type);
$self->reclamation($reclamation);
......
}
my $delivery_order = SL::DB::DeliveryOrder->new(id => $::form->{from_id})->load;
my $reclamation = SL::Model::Record->new_from_workflow($delivery_order, ref($self->reclamaiton), $self->type);
my $reclamation = SL::Model::Record->new_from_workflow($delivery_order, $self->type);
$self->reclamation($reclamation);
......
}
my $invoice = SL::DB::Invoice->new(id => $::form->{from_id})->load;
my $reclamation = SL::Model::Record->new_from_workflow($invoice, ref($self->reclamaiton), $self->type);
my $reclamation = SL::Model::Record->new_from_workflow($invoice, $self->type);
$self->reclamation($reclamation);
SL/Model/Record.pm
use SL::DB::Order::TypeData qw(:types);
use SL::DB::DeliveryOrder::TypeData qw(:types);
use SL::DB::Reclamation::TypeData qw(:types);
use SL::DB::Helper::Record qw(get_class_from_type);
use SL::Util qw(trim);
use SL::Locale::String qw(t8);
......
}
sub new_from_workflow {
my ($class, $source_object, $target_type, $target_subtype, %flags) = @_;
my ($class, $source_object, $target_type, %flags) = @_;
$flags{destination_type} = $target_subtype;
$flags{destination_type} = $target_type;
my %defaults_flags = (
no_linked_records => 0,
);
%flags = (%defaults_flags, %flags);
my $target_object = ${target_type}->new_from($source_object, %flags);
my $target_class = get_class_from_type($target_type);
my $target_object = ${target_class}->new_from($source_object, %flags);
return $target_object;
}
sub new_from_workflow_multi {
my ($class, $source_objects, $target_type, $target_subtype, %flags) = @_;
my ($class, $source_objects, $target_type, %flags) = @_;
my $target_object = ${target_type}->new_from_multi($source_objects, %flags);
my $target_class = get_class_from_type($target_type);
my $target_object = ${target_class}->new_from_multi($source_objects, %flags);
return $target_object;
}
......
$new_attrs{employee} = SL::DB::Manager::Employee->current;
my $new_record = SL::Model::Record->new_from_workflow($changed_record, ref($changed_record), $saved_record->type, no_linked_records => 1, attributes => \%new_attrs);
my $new_record = SL::Model::Record->new_from_workflow($changed_record, $saved_record->type, no_linked_records => 1, attributes => \%new_attrs);
return $new_record;
}
......
This module contains shared behaviour among the main record object types. A given record needs to be already parsed into a Rose object.
All records are treated agnostically and the underlying class needs to implement a type_data call to query for differing behaviour.
Currently the following types and subtypes are supported:
Currently the following classes and types are supported:
=over 4
......
=item C<new_from_workflow>
Expects source_object, target_type, target_subtype and can have flags.
Creates a new record from a target_subtype by target_type->new_from(source_record).
Expects source_object, target_type and can have flags.
Creates a new record from a by target_class->new_from(source_record).
Set default flag no_link_record to false.
Throws an error if the target_type doesn't exist.
......
=item C<new_from_workflow_multi>
Expects an arrayref with source_objects, target_type, target_subtype and can have flags.
Expects an arrayref with source_objects, target_type and can have flags.
Creates a new record object from one or more source objects.
Returns the new record object.
t/model/records.t
note "testing new_from_workflow for quotation";
foreach my $pair ( pairs @{['SL::DB::Order' => 'sales_order', 'SL::DB::DeliveryOrder' => 'sales_delivery_order']} ) {
foreach my $target_record_type (qw(sales_order sales_delivery_order)) {
# TODO: invoice
my ($target_record_type, $target_record_subtype) = @$pair;
note " testing from quotation -> $target_record_subtype";
my $new_record = SL::Model::Record->new_from_workflow($sales_quotation1, $target_record_type, $target_record_subtype);
note " testing from quotation -> $target_record_type";
my $new_record = SL::Model::Record->new_from_workflow($sales_quotation1, $target_record_type);
is($new_record->closed, 0, "new quotation is open");
# in the future closing sales quotations should probably happen as an after-save hook of orders,
......
SL::Model::Record->save($new_record, objects_to_close => [ $sales_quotation1 ]);
$new_record->load;
cmp_ok($new_record->netamount, '==', 710, "converted $target_record_subtype netamount ok") if $new_record->can('netamount');
cmp_ok($new_record->netamount, '==', 710, "converted $target_record_type netamount ok") if $new_record->can('netamount');
# test whether quotations get closed when sales_order is created
if ( $target_record_subtype eq 'sales_order' ) {
if ( $target_record_type eq 'sales_order' ) {
$sales_quotation1->load;
is($sales_quotation1->closed, 1, "quotation is closed after creating an order");
}
......
my $record_history = SL::DB::Manager::History->find_by(trans_id => $new_record->id, addition => 'SAVED');
ok($record_history->snumbers =~ m/_/, "history snumbers of record " . $record_history->snumbers . " ok");
test_record_links($new_record, "converted $target_record_subtype");
test_record_links($new_record, "converted $target_record_type");
};
note "testing new_from_workflow for order";
foreach my $pair (pairs @{['SL::DB::DeliveryOrder' => 'sales_delivery_order', 'SL::DB::Reclamation' => 'sales_reclamation']}) {
foreach my $target_record_type (qw(sales_delivery_order sales_reclamation)) {
# TODO: invoice
my ($target_record_type, $target_record_subtype) = @$pair;
note " testing from quotation -> $target_record_subtype";
my $new_record = SL::Model::Record->new_from_workflow($sales_order1, $target_record_type, $target_record_subtype);
note " testing from quotation -> $target_record_type";
my $new_record = SL::Model::Record->new_from_workflow($sales_order1, $target_record_type);
if ( 'SL::DB::Reclamation' eq ref($new_record) ) {
$_->reason($reclamation_reason) foreach @{ $new_record->items };
};
SL::Model::Record->save($new_record);
$new_record->load;
my $record_history = SL::DB::Manager::History->find_by(trans_id => $new_record->id, what_done => $target_record_subtype, addition => 'SAVED');
my $record_history = SL::DB::Manager::History->find_by(trans_id => $new_record->id, what_done => $target_record_type, addition => 'SAVED');
ok($record_history->snumbers =~ m/_/, "history snumbers of record " . $record_history->snumbers . " ok");
cmp_ok($new_record->netamount, '==', 710, "converted $target_record_subtype netamount ok") if $new_record->can('netamount');
test_record_links($new_record, "converted $target_record_subtype");
cmp_ok($new_record->netamount, '==', 710, "converted $target_record_type netamount ok") if $new_record->can('netamount');
test_record_links($new_record, "converted $target_record_type");
};
note ('testing multi');
......
note('combining several sales orders to one combined order');
my @sales_orders;
push(@sales_orders, SL::Model::Record->new_from_workflow($sales_quotation1, 'SL::DB::Order', 'sales_order')->save->load) for 1 .. 3;
my $combined_order = SL::Model::Record->new_from_workflow_multi(\@sales_orders, 'SL::DB::Order','sales_order', sort_sources_by => 'transdate');
push(@sales_orders, SL::Model::Record->new_from_workflow($sales_quotation1, 'sales_order')->save->load) for 1 .. 3;
my $combined_order = SL::Model::Record->new_from_workflow_multi(\@sales_orders, sort_sources_by => 'transdate');
SL::Model::Record->save($combined_order);
cmp_ok($combined_order->netamount, '==', 3*710, "netamount of combined order ok");
t/workflow/delivery_order_reclamation.t
)->load;
# convert order → reclamation
my $converted_sales_reclamation = SL::Model::Record->new_from_workflow($sales_delivery_order, 'SL::DB::Reclamation', 'sales_reclamation');
my $converted_sales_reclamation = SL::Model::Record->new_from_workflow($sales_delivery_order, 'sales_reclamation');
$converted_sales_reclamation->items_sorted->[0]->reason($reclamation_reason);
$converted_sales_reclamation->items_sorted->[1]->reason($reclamation_reason);
$converted_sales_reclamation->save->load;
my $converted_purchase_reclamation = SL::Model::Record->new_from_workflow($purchase_delivery_order, 'SL::DB::Reclamation', 'purchase_reclamation');
my $converted_purchase_reclamation = SL::Model::Record->new_from_workflow($purchase_delivery_order, 'purchase_reclamation');
$converted_purchase_reclamation->items_sorted->[0]->reason($reclamation_reason);
$converted_purchase_reclamation->items_sorted->[1]->reason($reclamation_reason);
$converted_purchase_reclamation->save->load;
# convert reclamation → order
my $converted_sales_delivery_order = SL::Model::Record->new_from_workflow($sales_reclamation, 'SL::DB::DeliveryOrder', 'rma_delivery_order')->save->load;
my $converted_purchase_delivery_order = SL::Model::Record->new_from_workflow($purchase_reclamation, 'SL::DB::DeliveryOrder', 'supplier_delivery_order')->save->load;
my $converted_sales_delivery_order = SL::Model::Record->new_from_workflow($sales_reclamation, 'rma_delivery_order')->save->load;
my $converted_purchase_delivery_order = SL::Model::Record->new_from_workflow($purchase_reclamation, 'supplier_delivery_order')->save->load;
#get items before strip
t/workflow/invoice_to_reclamation.t
)->load;
# convert invoice → reclamation
my $converted_sales_reclamation =SL::Model::Record->new_from_workflow($sales_invoice, 'SL::DB::Reclamation', "sales_reclamation");
my $converted_sales_reclamation =SL::Model::Record->new_from_workflow($sales_invoice, "sales_reclamation");
$converted_sales_reclamation->items_sorted->[0]->reason($reclamation_reason);
$converted_sales_reclamation->items_sorted->[1]->reason($reclamation_reason);
$converted_sales_reclamation->save->load;
my $converted_purchase_reclamation = SL::Model::Record->new_from_workflow($purchase_invoice, 'SL::DB::Reclamation', "purchase_reclamation");
my $converted_purchase_reclamation = SL::Model::Record->new_from_workflow($purchase_invoice, "purchase_reclamation");
$converted_purchase_reclamation->items_sorted->[0]->reason($reclamation_reason);
$converted_purchase_reclamation->items_sorted->[1]->reason($reclamation_reason);
$converted_purchase_reclamation->save->load;
t/workflow/order_reclamation.t
)->load;
# convert order → reclamation
my $converted_sales_reclamation = SL::Model::Record->new_from_workflow($sales_order, 'SL::DB::Reclamation', "sales_reclamation");
my $converted_sales_reclamation = SL::Model::Record->new_from_workflow($sales_order, "sales_reclamation");
$converted_sales_reclamation->items_sorted->[0]->reason($reclamation_reason);
$converted_sales_reclamation->items_sorted->[1]->reason($reclamation_reason);
$converted_sales_reclamation->save->load;
my $converted_purchase_reclamation = SL::Model::Record->new_from_workflow($purchase_order, 'SL::DB::Reclamation', "purchase_reclamation");
my $converted_purchase_reclamation = SL::Model::Record->new_from_workflow($purchase_order, "purchase_reclamation");
$converted_purchase_reclamation->items_sorted->[0]->reason($reclamation_reason);
$converted_purchase_reclamation->items_sorted->[1]->reason($reclamation_reason);
$converted_purchase_reclamation->save->load;
# convert reclamation → order
my $converted_sales_order = SL::Model::Record->new_from_workflow($sales_reclamation, 'SL::DB::Order', 'sales_order')->save->load;
my $converted_purchase_order = SL::Model::Record->new_from_workflow($purchase_reclamation, 'SL::DB::Order', 'purchase_order')->save->load;
my $converted_sales_order = SL::Model::Record->new_from_workflow($sales_reclamation, 'sales_order')->save->load;
my $converted_purchase_order = SL::Model::Record->new_from_workflow($purchase_reclamation, 'purchase_order')->save->load;
#get items before strip
t/workflow/reclamation_reclamation.t
# new
my $new_sales_reclamation = SL::Model::Record->new_from_workflow($sales_reclamation, 'SL::DB::Reclamation', 'sales_reclamation')->save->load;
my $new_purchase_reclamation = SL::Model::Record->new_from_workflow($purchase_reclamation, 'SL::DB::Reclamation', 'purchase_reclamation')->save->load;
my $new_purchase_reclamation = SL::Model::Record->new_from_workflow($purchase_reclamation, 'purchase_reclamation')->save->load;
# convert
my $converted_purchase_reclamation = SL::Model::Record->new_from_workflow($sales_reclamation, 'SL::DB::Reclamation', 'purchase_reclamation');
my $converted_purchase_reclamation = SL::Model::Record->new_from_workflow($sales_reclamation, 'purchase_reclamation');
$converted_purchase_reclamation->vendor_id($purchase_reclamation->{vendor_id});
$converted_purchase_reclamation->save->load;
my $converted_sales_reclamation = SL::Model::Record->new_from_workflow($purchase_reclamation, 'SL::DB::Reclamation', 'sales_reclamation');
my $converted_sales_reclamation = SL::Model::Record->new_from_workflow($purchase_reclamation, 'sales_reclamation');
$converted_sales_reclamation->customer_id($sales_reclamation->{customer_id});
$converted_sales_reclamation->save->load;

Auch abrufbar als: Unified diff