Revision e4bcffbd
Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt
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, $target_type);
|
||
my $delivery_order = SL::Model::Record->new_from_workflow($order, ref($self->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, $target_type);
|
||
my $delivery_order = SL::Model::Record->new_from_workflow($reclamation, ref($self->order), $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, $target_type, sort_sources_by => 'transdate');
|
||
my $delivery_order = SL::Model::Record->new_from_workflow_multi(\@multi_orders, ref($self->order), $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, $destination_type, {});
|
||
my $delivery_order = SL::Model::Record->new_from_workflow($self->order, ref($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, $destination_type, {});
|
||
my $delivery_order = SL::Model::Record->new_from_workflow($self->order, ref($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, $target_type);
|
||
my $order = SL::Model::Record->new_from_workflow($reclamation, ref($self->order), $target_type);
|
||
$self->{converted_from_reclamation_id} = $::form->{from_id};
|
||
|
||
$self->order($order);
|
||
... | ... | |
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, $target_type, sort_sources_by => 'transdate');
|
||
my $order = SL::Model::Record->new_from_workflow_multi(\@multi_orders, ref($self->order), $target_type, sort_sources_by => 'transdate');
|
||
$self->order($order);
|
||
|
||
$self->action_edit();
|
SL/Controller/Reclamation.pm | ||
---|---|---|
}
|
||
|
||
my $order = SL::DB::Order->new(id => $::form->{from_id})->load;
|
||
my $reclamation = SL::Model::Record->new_from_workflow($order, $self->type);
|
||
my $reclamation = SL::Model::Record->new_from_workflow($order, ref($self->reclamaiton), $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, $self->type);
|
||
my $reclamation = SL::Model::Record->new_from_workflow($delivery_order, ref($self->reclamaiton), $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, $self->type);
|
||
my $reclamation = SL::Model::Record->new_from_workflow($invoice, ref($self->reclamaiton), $self->type);
|
||
|
||
$self->reclamation($reclamation);
|
||
|
||
... | ... | |
require SL::DB::PurchaseInvoice;
|
||
my $invoice = SL::DB::PurchaseInvoice->new(id => $::form->{from_id})->load;
|
||
$invoice->{type} = $invoice->invoice_type; #can't add type → invoice_type in SL/DB/PurchaseInvoice
|
||
my $reclamation = SL::Model::Record->new_from_workflow($invoice, $self->type);
|
||
my $reclamation = SL::Model::Record->new_from_workflow($invoice, ref($self->reclamaiton), $self->type);
|
||
|
||
$self->reclamation($reclamation);
|
||
|
SL/Model/Record.pm | ||
---|---|---|
}
|
||
|
||
sub new_from_workflow {
|
||
my ($class, $source_object, $target_subtype, %flags) = @_;
|
||
my ($class, $source_object, $target_type, $target_subtype, %flags) = @_;
|
||
|
||
$flags{destination_type} = $target_subtype;
|
||
my %defaults_flags = (
|
||
... | ... | |
);
|
||
%flags = (%defaults_flags, %flags);
|
||
|
||
my %subtype_to_type = (
|
||
# Order
|
||
REQUEST_QUOTATION_TYPE() => "SL::DB::Order",
|
||
PURCHASE_ORDER_TYPE() => "SL::DB::Order",
|
||
SALES_QUOTATION_TYPE() => "SL::DB::Order",
|
||
SALES_ORDER_TYPE() => "SL::DB::Order",
|
||
# DeliveryOrder
|
||
SALES_DELIVERY_ORDER_TYPE() => "SL::DB::DeliveryOrder",
|
||
PURCHASE_DELIVERY_ORDER_TYPE() => "SL::DB::DeliveryOrder",
|
||
RMA_DELIVERY_ORDER_TYPE() => "SL::DB::DeliveryOrder",
|
||
SUPPLIER_DELIVERY_ORDER_TYPE() => "SL::DB::DeliveryOrder",
|
||
# Reclamation
|
||
SALES_RECLAMATION_TYPE() => "SL::DB::Reclamation",
|
||
PURCHASE_RECLAMATION_TYPE() => "SL::DB::Reclamation",
|
||
);
|
||
my $target_type = $subtype_to_type{$target_subtype};
|
||
unless ($target_type) {
|
||
croak("Conversion not supported to $target_subtype");
|
||
}
|
||
|
||
my $target_object = ${target_type}->new_from($source_object, %flags);
|
||
return $target_object;
|
||
}
|
||
|
||
sub new_from_workflow_multi {
|
||
my ($class, $source_objects, $target_subtype, %flags) = @_;
|
||
|
||
my %subtype_to_type = (
|
||
# Order
|
||
SALES_ORDER_TYPE() => "SL::DB::Order",
|
||
);
|
||
my $target_type = $subtype_to_type{$target_subtype};
|
||
unless ($target_type) {
|
||
croak("Conversion not supported to $target_subtype");
|
||
}
|
||
my ($class, $source_objects, $target_type, $target_subtype, %flags) = @_;
|
||
|
||
my $target_object = ${target_type}->new_from_multi($source_objects, %flags);
|
||
|
||
... | ... | |
$new_attrs{employee} = SL::DB::Manager::Employee->current;
|
||
|
||
|
||
my $new_record = SL::Model::Record->new_from_workflow($changed_record, $saved_record->type, no_linked_records => 1, attributes => \%new_attrs);
|
||
my $new_record = SL::Model::Record->new_from_workflow($changed_record, ref($changed_record), $saved_record->type, no_linked_records => 1, attributes => \%new_attrs);
|
||
|
||
# return: nichts
|
||
# fehler: exception
|
||
... | ... | |
|
||
=item C<new_from_workflow>
|
||
|
||
Expects source_object, target_object, can have flags.
|
||
Creates a new record from a source_subtype by target_type->new_from(source_record).
|
||
Set default flag no_link_record to false and looks up the correct target_type.
|
||
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).
|
||
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 and a target_object, can have flags.
|
||
Creates a new record object from one or more source objects. For now only for orders.
|
||
Looks up the correct target type and throws an error if it doesn't exist.
|
||
Expects an arrayref with source_objects, target_type, target_subtype and can have flags.
|
||
Creates a new record object from one or more source objects.
|
||
|
||
Returns the new record object.
|
||
|
t/model/records.t | ||
---|---|---|
use Data::Dumper;
|
||
use Support::TestSetup;
|
||
use Test::Exception;
|
||
use List::Util qw(pairs);
|
||
|
||
use SL::DB::PaymentTerm;
|
||
use SL::DB::DeliveryTerm;
|
||
... | ... | |
|
||
|
||
note "testing new_from_workflow for quotation";
|
||
foreach my $target_record_type ( qw(sales_order sales_delivery_order) ) {
|
||
foreach my $pair ( pairs @{['SL::DB::Order' => 'sales_order', 'SL::DB::DeliveryOrder' => 'sales_delivery_order']} ) {
|
||
# TODO: invoice
|
||
note " testing from quotation -> $target_record_type";
|
||
my $new_record = SL::Model::Record->new_from_workflow($sales_quotation1, $target_record_type);
|
||
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);
|
||
|
||
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_type netamount ok") if $new_record->can('netamount');
|
||
cmp_ok($new_record->netamount, '==', 710, "converted $target_record_subtype netamount ok") if $new_record->can('netamount');
|
||
|
||
# test whether quotations get closed when sales_order is created
|
||
if ( $target_record_type eq 'sales_order' ) {
|
||
if ( $target_record_subtype 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_type");
|
||
test_record_links($new_record, "converted $target_record_subtype");
|
||
};
|
||
|
||
note "testing new_from_workflow for order";
|
||
foreach my $target_record_type ( qw(sales_delivery_order sales_reclamation) ) {
|
||
foreach my $pair (pairs @{['SL::DB::DeliveryOrder' => 'sales_delivery_order', 'SL::DB::Reclamation' => 'sales_reclamation']}) {
|
||
# TODO: invoice
|
||
note " testing from quotation -> $target_record_type";
|
||
my $new_record = SL::Model::Record->new_from_workflow($sales_order1, $target_record_type);
|
||
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);
|
||
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_type, addition => 'SAVED');
|
||
my $record_history = SL::DB::Manager::History->find_by(trans_id => $new_record->id, what_done => $target_record_subtype, addition => 'SAVED');
|
||
|
||
ok($record_history->snumbers =~ m/_/, "history snumbers of record " . $record_history->snumbers . " ok");
|
||
|
||
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");
|
||
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");
|
||
};
|
||
|
||
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, 'sales_order')->save->load) for 1 .. 3;
|
||
my $combined_order = SL::Model::Record->new_from_workflow_multi(\@sales_orders, 'sales_order', sort_sources_by => 'transdate');
|
||
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');
|
||
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, 'sales_reclamation');
|
||
my $converted_sales_reclamation = SL::Model::Record->new_from_workflow($sales_delivery_order, 'SL::DB::Reclamation', '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, 'purchase_reclamation');
|
||
my $converted_purchase_reclamation = SL::Model::Record->new_from_workflow($purchase_delivery_order, 'SL::DB::Reclamation', '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, 'rma_delivery_order')->save->load;
|
||
my $converted_purchase_delivery_order = SL::Model::Record->new_from_workflow($purchase_reclamation, 'supplier_delivery_order')->save->load;
|
||
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;
|
||
|
||
|
||
#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, "sales_reclamation");
|
||
my $converted_sales_reclamation =SL::Model::Record->new_from_workflow($sales_invoice, 'SL::DB::Reclamation', "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, "purchase_reclamation");
|
||
my $converted_purchase_reclamation = SL::Model::Record->new_from_workflow($purchase_invoice, 'SL::DB::Reclamation', "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, "sales_reclamation");
|
||
my $converted_sales_reclamation = SL::Model::Record->new_from_workflow($sales_order, 'SL::DB::Reclamation', "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, "purchase_reclamation");
|
||
my $converted_purchase_reclamation = SL::Model::Record->new_from_workflow($purchase_order, 'SL::DB::Reclamation', "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, 'sales_order')->save->load;
|
||
my $converted_purchase_order = SL::Model::Record->new_from_workflow($purchase_reclamation, 'purchase_order')->save->load;
|
||
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;
|
||
|
||
|
||
#get items before strip
|
t/workflow/reclamation_reclamation.t | ||
---|---|---|
)->load;
|
||
|
||
# new
|
||
my $new_sales_reclamation = SL::Model::Record->new_from_workflow($sales_reclamation, 'sales_reclamation')->save->load;
|
||
my $new_purchase_reclamation = SL::Model::Record->new_from_workflow($purchase_reclamation, 'purchase_reclamation')->save->load;
|
||
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;
|
||
|
||
# convert
|
||
my $converted_purchase_reclamation = SL::Model::Record->new_from_workflow($sales_reclamation, 'purchase_reclamation');
|
||
my $converted_purchase_reclamation = SL::Model::Record->new_from_workflow($sales_reclamation, 'SL::DB::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, 'sales_reclamation');
|
||
my $converted_sales_reclamation = SL::Model::Record->new_from_workflow($purchase_reclamation, 'SL::DB::Reclamation', 'sales_reclamation');
|
||
$converted_sales_reclamation->customer_id($sales_reclamation->{customer_id});
|
||
$converted_sales_reclamation->save->load;
|
||
|
Auch abrufbar als: Unified diff
Model::Record: übergebe Typ für new_from_workflow und ..._multi