Revision 7a06d7c0
Von Tamino Steinert vor fast 3 Jahren hinzugefügt
SL/DB/DeliveryOrder.pm | ||
---|---|---|
|
||
use SL::Helper::Number qw(_format_total _round_total);
|
||
|
||
use Rose::DB::Object::Helpers qw(as_tree strip);
|
||
use List::Util qw(first);
|
||
use List::MoreUtils qw(any pairwise);
|
||
use Math::Round qw(nhimult);
|
||
... | ... | |
);
|
||
$record_args{cp_id} = $source->contact_id;
|
||
$record_args{cusordnumber} = $source->cv_record_number;
|
||
$record_args{is_sales} = $source->is_sales;
|
||
# }}} for vim folds
|
||
}
|
||
|
SL/DB/DeliveryOrderItem.pm | ||
---|---|---|
|
||
use strict;
|
||
|
||
use Rose::DB::Object::Helpers qw(as_tree strip);
|
||
|
||
use SL::DB::MetaSetup::DeliveryOrderItem;
|
||
use SL::DB::Helper::ActsAsList;
|
||
use SL::DB::Helper::LinkedRecords;
|
SL/DB/Order.pm | ||
---|---|---|
use SL::DB::Helper::TransNumberGenerator;
|
||
use SL::Locale::String qw(t8);
|
||
use SL::RecordLinks;
|
||
use Rose::DB::Object::Helpers qw(as_tree);
|
||
use Rose::DB::Object::Helpers qw(as_tree strip);
|
||
|
||
__PACKAGE__->meta->add_relationship(
|
||
orderitems => {
|
SL/DB/OrderItem.pm | ||
---|---|---|
},
|
||
);
|
||
use SL::Helper::ShippedQty;
|
||
use Rose::DB::Object::Helpers qw(as_tree strip);
|
||
|
||
__PACKAGE__->meta->initialize;
|
||
|
SL/DB/Reclamation.pm | ||
---|---|---|
use SL::DB::Helper::TransNumberGenerator;
|
||
use SL::Locale::String qw(t8);
|
||
use SL::RecordLinks;
|
||
use Rose::DB::Object::Helpers qw(as_tree);
|
||
use Rose::DB::Object::Helpers qw(as_tree strip);
|
||
|
||
__PACKAGE__->meta->add_relationship(
|
||
|
||
... | ... | |
|
||
1;
|
||
})) {
|
||
return undef;
|
||
return undef, $self->db->error->db_error->db_error;
|
||
}
|
||
|
||
return $order;
|
||
... | ... | |
return undef, $self->db->error->db_error->db_error;
|
||
}
|
||
|
||
return $delivery_order, undef;
|
||
return $delivery_order;
|
||
}
|
||
|
||
#TODO(Werner): überprüfen ob alle Felder richtig gestetzt werden
|
||
... | ... | |
$record_args{vendor_id} = undef;
|
||
$record_args{salesman_id} = undef;
|
||
$record_args{payment_id} = undef;
|
||
$record_args{delivery_term_id} = undef;
|
||
}
|
||
|
||
|
SL/DB/ReclamationItem.pm | ||
---|---|---|
use strict;
|
||
|
||
use List::MoreUtils qw(any);
|
||
use Rose::DB::Object::Helpers qw(as_tree strip);
|
||
|
||
use SL::DB::MetaSetup::ReclamationItem;
|
||
use SL::DB::Manager::ReclamationItem;
|
||
... | ... | |
|
||
my $item = $class->new(%item_args);
|
||
|
||
if ( $source->record->is_sales() && ($parent_type =~ m{sales}) ) {
|
||
if ( $source->record->is_sales() && ($parent_type =~ m{purchase}) ) {
|
||
$item->sellprice($source->lastcost);
|
||
$item->discount(0);
|
||
}
|
||
if ( !$source->record->is_sales() && ($parent_type =~ m{purchase}) ) {
|
||
if ( !$source->record->is_sales() && ($parent_type =~ m{sales}) ) {
|
||
$item->lastcost($source->sellprice);
|
||
}
|
||
|
SL/Dev/Record.pm | ||
---|---|---|
create_delivery_order_item
|
||
create_sales_delivery_order
|
||
create_purchase_delivery_order
|
||
create_sales_reclamation
|
||
create_purchase_reclamation
|
||
create_project create_department
|
||
create_ap_transaction
|
||
create_ar_transaction
|
||
... | ... | |
sales_order => 'SL::DB::OrderItem',
|
||
purchase_order => 'SL::DB::OrderItem',
|
||
sales_delivery_order => 'SL::DB::DeliveryOrderItem',
|
||
purchase_delivery_order => 'SL::DB::DeliveryOrderItem',
|
||
sales_reclamation => 'SL::DB::ReclamationItem',
|
||
purchase_reclamation => 'SL::DB::ReclamationItem',
|
||
);
|
||
|
||
sub create_sales_invoice {
|
||
... | ... | |
return $order;
|
||
};
|
||
|
||
sub create_sales_reclamation {
|
||
my (%params) = @_;
|
||
|
||
my $record_type = 'sales_reclamation';
|
||
my $reclamation_items = delete $params{reclamation_items} // _create_two_items($record_type);
|
||
_check_items($reclamation_items, $record_type);
|
||
|
||
my $save = delete $params{save} // 0;
|
||
|
||
my $customer = $params{customer} // new_customer(name => 'Test_Customer')->save;
|
||
die "'customer' is not of type SL::DB::Customer" unless ref($customer) eq 'SL::DB::Customer';
|
||
|
||
my $reclamation = SL::DB::Reclamation->new(
|
||
customer_id => delete $params{customer_id} // $customer->id,
|
||
taxzone_id => delete $params{taxzone_id} // $customer->taxzone->id,
|
||
currency_id => delete $params{currency_id} // $::instance_conf->get_currency_id,
|
||
taxincluded => delete $params{taxincluded} // 0,
|
||
transdate => delete $params{transdate} // DateTime->today,
|
||
'closed' => undef,
|
||
reclamation_items => $reclamation_items,
|
||
);
|
||
$reclamation->assign_attributes(%params) if %params;
|
||
|
||
if ( $save ) {
|
||
$reclamation->calculate_prices_and_taxes; # not tested
|
||
$reclamation->save;
|
||
}
|
||
return $reclamation;
|
||
}
|
||
|
||
sub create_purchase_reclamation {
|
||
my (%params) = @_;
|
||
|
||
my $record_type = 'sales_reclamation';
|
||
my $reclamation_items = delete $params{reclamation_items} // _create_two_items($record_type);
|
||
_check_items($reclamation_items, $record_type);
|
||
|
||
my $save = delete $params{save} // 0;
|
||
|
||
my $vendor = $params{vendor} // new_vendor(name => 'Test_Vendor')->save;
|
||
die "'vendor' is not of type SL::DB::Vendor" unless ref($vendor) eq 'SL::DB::Vendor';
|
||
|
||
my $reclamation = SL::DB::Reclamation->new(
|
||
vendor_id => delete $params{vendor_id} // $vendor->id,
|
||
taxzone_id => delete $params{taxzone_id} // $vendor->taxzone->id,
|
||
currency_id => delete $params{currency_id} // $::instance_conf->get_currency_id,
|
||
taxincluded => delete $params{taxincluded} // 0,
|
||
transdate => delete $params{transdate} // DateTime->today,
|
||
'closed' => undef,
|
||
reclamation_items => $reclamation_items,
|
||
);
|
||
$reclamation->assign_attributes(%params) if %params;
|
||
|
||
if ( $save ) {
|
||
$reclamation->calculate_prices_and_taxes; # not tested
|
||
$reclamation->save;
|
||
}
|
||
return $reclamation;
|
||
}
|
||
|
||
sub _check_items {
|
||
my ($items, $record_type) = @_;
|
||
|
||
... | ... | |
return _create_item(record_type => 'sales_delivery_order', %params);
|
||
}
|
||
|
||
sub create_reclamation_item {
|
||
my (%params) = @_;
|
||
|
||
# record_type can be sales or purchase; make sure one is set
|
||
return _create_item(record_type => 'sales_reclamation', %params);
|
||
}
|
||
|
||
sub _create_item {
|
||
my (%params) = @_;
|
||
|
js/kivi.Reclamation.js | ||
---|---|---|
$('<input type="hidden" name="use_shipto">').appendTo('#reclamation_form').val('1');
|
||
}
|
||
|
||
kivi.submit_form_with_action($('#reclamation_form'), 'Reclamation/purchase_reclamation');
|
||
kivi.submit_form_with_action($('#reclamation_form'), 'Reclamation/save_and_purchase_reclamation');
|
||
};
|
||
|
||
ns.direct_delivery_dialog = function(shipto) {
|
t/workflow/delivery_order_reclamation.t | ||
---|---|---|
use Test::More;
|
||
|
||
use strict;
|
||
|
||
use lib 't';
|
||
use utf8;
|
||
|
||
use Carp;
|
||
use Data::Dumper;
|
||
use Data::Compare;
|
||
use Support::TestSetup;
|
||
use Test::Exception;
|
||
use List::Util qw(zip);
|
||
|
||
use SL::DB::DeliveryOrder;
|
||
use SL::DB::Reclamation;
|
||
use SL::DB::ReclamationReason;
|
||
use SL::DB::Customer;
|
||
use SL::DB::Vendor;
|
||
use SL::DB::Department;
|
||
use SL::DB::Currency;
|
||
use SL::DB::PaymentTerm;
|
||
use SL::DB::DeliveryTerm;
|
||
use SL::DB::Employee;
|
||
use SL::DB::Part;
|
||
use SL::DB::Unit;
|
||
|
||
use Rose::DB::Object::Helpers qw(clone);
|
||
|
||
use SL::Dev::ALL qw(:ALL);
|
||
|
||
my (
|
||
$customer, $vendor,
|
||
$employee,
|
||
$payment_term,
|
||
$delivery_term,
|
||
$unit,
|
||
@parts,
|
||
$department,
|
||
$relamation_reason,
|
||
);
|
||
|
||
|
||
sub clear_up {
|
||
foreach (qw(
|
||
DeliveryOrder DeliveryOrderItem
|
||
Reclamation ReclamationItem
|
||
Part
|
||
Customer Vendor
|
||
Department PaymentTerm DeliveryTerm
|
||
)) {
|
||
"SL::DB::Manager::${_}"->delete_all(all => 1);
|
||
}
|
||
SL::DB::Manager::Employee->delete_all(where => [ login => 'testuser' ]);
|
||
};
|
||
|
||
sub reset_state {
|
||
my %params = @_;
|
||
|
||
clear_up();
|
||
|
||
$unit = SL::DB::Manager::Unit->find_by(name => 'kg') || die "Can't find unit 'kg'";
|
||
|
||
$employee = SL::DB::Employee->new(
|
||
'login' => 'testuser',
|
||
'name' => 'Test User',
|
||
)->save;
|
||
|
||
$department = SL::DB::Department->new(
|
||
'description' => 'Test Department',
|
||
)->save;
|
||
|
||
$payment_term = create_payment_terms(
|
||
'description' => '14Tage 2%Skonto, 30Tage netto',
|
||
'description_long' => "Innerhalb von 14 Tagen abzüglich 2 % Skonto, innerhalb von 30 Tagen rein netto.|Bei einer Zahlung bis zum <%skonto_date%> gewähren wir 2 % Skonto (EUR <%skonto_amount%>) entspricht EUR <%total_wo_skonto%>.Bei einer Zahlung bis zum <%netto_date%> ist der fällige Betrag in Höhe von <%total%> <%currency%> zu überweisen.",
|
||
'percent_skonto' => '0.02',
|
||
'terms_netto' => 30,
|
||
'terms_skonto' => 14
|
||
);
|
||
|
||
$delivery_term = SL::DB::DeliveryTerm->new(
|
||
'description' => 'Test Delivey Term',
|
||
'description_long' => 'Test Delivey Term Test Delivey Term',
|
||
)->save;
|
||
|
||
# some parts/services
|
||
@parts = ();
|
||
push @parts, new_part(
|
||
partnumber => 'Part_1_KG',
|
||
unit => $unit->name,
|
||
)->save;
|
||
push @parts, new_service(
|
||
partnumber => 'Serv_1',
|
||
)->save;
|
||
push @parts, new_part(
|
||
partnumber => 'Part_2',
|
||
)->save;
|
||
push @parts, new_service(
|
||
partnumber => 'Serv_2'
|
||
)->save;
|
||
|
||
$relamation_reason = SL::DB::ReclamationReason->new(
|
||
name => "test_reason",
|
||
description => "",
|
||
position => 1,
|
||
);
|
||
}
|
||
|
||
Support::TestSetup::login();
|
||
|
||
reset_state();
|
||
|
||
#####
|
||
|
||
my $sales_reclamation = SL::Dev::Record::create_sales_reclamation(
|
||
save => 1,
|
||
employee => $employee,
|
||
shippingpoint => "sp",
|
||
transaction_description => "td1",
|
||
payment => $payment_term,
|
||
delivery_term => $delivery_term,
|
||
taxincluded => 0,
|
||
reclamation_items => [
|
||
SL::Dev::Record::create_reclamation_item(
|
||
part => $parts[0], qty => 3, sellprice => 70,
|
||
reason => $relamation_reason,
|
||
),
|
||
SL::Dev::Record::create_reclamation_item(
|
||
part => $parts[1], qty => 10, sellprice => 50,
|
||
reason => $relamation_reason,
|
||
),
|
||
],
|
||
)->load;
|
||
|
||
my $purchase_reclamation = SL::Dev::Record::create_purchase_reclamation(
|
||
save => 1,
|
||
employee => $employee,
|
||
shippingpoint => "sp",
|
||
transaction_description => "td2",
|
||
payment => $payment_term,
|
||
delivery_term => $delivery_term,
|
||
taxincluded => 0,
|
||
reclamation_items => [
|
||
SL::Dev::Record::create_reclamation_item(
|
||
part => $parts[0], qty => 3, sellprice => 70,
|
||
reason => $relamation_reason,
|
||
),
|
||
SL::Dev::Record::create_reclamation_item(
|
||
part => $parts[1], qty => 10, sellprice => 50,
|
||
reason => $relamation_reason,
|
||
),
|
||
],
|
||
)->load;
|
||
|
||
|
||
my $sales_delivery_order = SL::Dev::Record::create_sales_delivery_order(
|
||
save => 1,
|
||
employee => $employee,
|
||
shippingpoint => "sp",
|
||
transaction_description => "td3",
|
||
payment_terms => $payment_term,
|
||
delivery_term => $delivery_term,
|
||
taxincluded => 0,
|
||
is_sales => 1,
|
||
orderitems => [ SL::Dev::Record::create_delivery_order_item(part => $parts[0], qty => 3, sellprice => 70),
|
||
SL::Dev::Record::create_delivery_order_item(part => $parts[1], qty => 10, sellprice => 50),
|
||
]
|
||
)->load;
|
||
|
||
my $purchase_delivery_order = SL::Dev::Record::create_purchase_delivery_order(
|
||
save => 1,
|
||
employee => $employee,
|
||
shippingpoint => "sp",
|
||
transaction_description => "td4",
|
||
payment_terms => $payment_term,
|
||
delivery_term => $delivery_term,
|
||
taxincluded => 0,
|
||
is_sales => 0,
|
||
orderitems => [ SL::Dev::Record::create_delivery_order_item(part => $parts[0], qty => 3, sellprice => 70),
|
||
SL::Dev::Record::create_delivery_order_item(part => $parts[1], qty => 10, sellprice => 50),
|
||
]
|
||
)->load;
|
||
|
||
# convert order → reclamation
|
||
my $converted_sales_reclamation = $sales_delivery_order->convert_to_reclamation;
|
||
$converted_sales_reclamation->items_sorted->[0]->reason($relamation_reason);
|
||
$converted_sales_reclamation->items_sorted->[1]->reason($relamation_reason);
|
||
$converted_sales_reclamation->save->load;
|
||
my $converted_purchase_reclamation = $purchase_delivery_order->convert_to_reclamation;
|
||
$converted_purchase_reclamation->items_sorted->[0]->reason($relamation_reason);
|
||
$converted_purchase_reclamation->items_sorted->[1]->reason($relamation_reason);
|
||
$converted_purchase_reclamation->save->load;
|
||
|
||
# convert reclamation → order
|
||
my $converted_sales_delivery_order = $sales_reclamation->convert_to_delivery_order->save->load;
|
||
my $converted_purchase_delivery_order = $purchase_reclamation->convert_to_delivery_order->save->load;
|
||
|
||
|
||
#get items before strip
|
||
my @purchase_reclamation_items = $purchase_reclamation->items_sorted;
|
||
my @sales_reclamation_items = $sales_reclamation->items_sorted;
|
||
my @converted_purchase_reclamation_items = $converted_purchase_reclamation->items_sorted;
|
||
my @converted_sales_reclamation_items = $converted_sales_reclamation->items_sorted;
|
||
my @purchase_delivery_order_items = $purchase_delivery_order->items_sorted;
|
||
my @sales_delivery_order_items = $sales_delivery_order->items_sorted;
|
||
my @converted_purchase_delivery_order_items = $converted_purchase_delivery_order->items_sorted;
|
||
my @converted_sales_delivery_order_items = $converted_sales_delivery_order->items_sorted;
|
||
|
||
|
||
### TESTS #####################################################################
|
||
|
||
## created sales und purchase reclamation should be nearly the same
|
||
my $sales_reclamation_tmp = clone($sales_reclamation);
|
||
my $purchase_reclamation_tmp = clone($purchase_reclamation);
|
||
# clean different values
|
||
foreach (qw(
|
||
customer_id vendor_id
|
||
id record_number
|
||
salesman_id
|
||
transaction_description
|
||
itime mtime
|
||
)) {
|
||
$sales_reclamation_tmp->$_(undef);
|
||
$purchase_reclamation_tmp->$_(undef);
|
||
}
|
||
foreach my $pair (zip(@purchase_reclamation_items, @sales_reclamation_items)) {
|
||
my ($first, $second) = @{$pair};
|
||
my $first_tmp = clone($first);
|
||
my $second_tmp = clone($second);
|
||
foreach (qw(
|
||
id reclamation_id
|
||
itime mtime
|
||
)) {
|
||
$first_tmp->$_(undef);
|
||
$second_tmp->$_(undef);
|
||
}
|
||
is_deeply($first_tmp->strip->as_tree, $second_tmp->strip->as_tree);
|
||
}
|
||
is_deeply($purchase_reclamation_tmp->strip->as_tree, $sales_reclamation_tmp->strip->as_tree);
|
||
|
||
## created sales und purchase delivery_order should be nearly the same
|
||
my $sales_delivery_order_tmp = clone($sales_delivery_order);
|
||
my $purchase_delivery_order_tmp = clone($purchase_delivery_order);
|
||
# clean different values
|
||
foreach (qw(
|
||
customer_id vendor_id
|
||
id is_sales order_type
|
||
donumber salesman_id
|
||
transaction_description
|
||
itime mtime
|
||
)) {
|
||
$sales_delivery_order_tmp->$_(undef);
|
||
$purchase_delivery_order_tmp->$_(undef);
|
||
}
|
||
foreach my $pair (zip(@purchase_delivery_order_items, @sales_delivery_order_items)) {
|
||
my ($first, $second) = @{$pair};
|
||
my $first_tmp = clone($first);
|
||
my $second_tmp = clone($second);
|
||
foreach (qw(
|
||
id delivery_order_id
|
||
itime mtime
|
||
)) {
|
||
$first_tmp->$_(undef);
|
||
$second_tmp->$_(undef);
|
||
}
|
||
is_deeply($first_tmp->strip->as_tree, $second_tmp->strip->as_tree);
|
||
}
|
||
is_deeply($purchase_delivery_order_tmp->strip->as_tree, $sales_delivery_order_tmp->strip->as_tree);
|
||
|
||
|
||
## converted have to be linked to parent
|
||
# sales
|
||
my $linked_sales_delivery_order = $converted_sales_reclamation->linked_records->[0];
|
||
my $linked_sales_reclamation = $converted_sales_delivery_order->linked_records->[0];
|
||
is_deeply($linked_sales_delivery_order->strip->as_tree, $sales_delivery_order->strip->as_tree);
|
||
is_deeply($linked_sales_reclamation->strip->as_tree, $sales_reclamation->load->strip->as_tree);
|
||
|
||
# purchase
|
||
my $linked_purchase_delivery_order = $converted_purchase_reclamation->linked_records->[0];
|
||
my $linked_purchase_reclamation = $converted_purchase_delivery_order->linked_records->[0];
|
||
is_deeply($linked_purchase_delivery_order->strip->as_tree, $purchase_delivery_order->strip->as_tree);
|
||
is_deeply($linked_purchase_reclamation->strip->as_tree, $purchase_reclamation->load->strip->as_tree);
|
||
|
||
|
||
## converted should be nealy the same
|
||
# sales
|
||
foreach my $pair (zip(@sales_delivery_order_items, @converted_sales_reclamation_items)) {
|
||
my ($first, $second) = @{$pair};
|
||
ok Compare($first->strip->as_tree, $second->strip->as_tree, {ignore_hash_keys => [qw(
|
||
id delivery_order_id reclamation_id itime mtime
|
||
cusordnumber marge_price_factor ordnumber transdate
|
||
description reason_description_ext reason_description_int reason_id
|
||
)]});
|
||
}
|
||
ok Compare($sales_delivery_order->strip->as_tree, $converted_sales_reclamation->strip->as_tree, {ignore_hash_keys => [qw(
|
||
id employee_id itime mtime reqdate
|
||
is_sales order_type ordnumber oreqnumber
|
||
amount exchangerate netamount
|
||
cp_id contact_id
|
||
cusordnumber cv_record_number
|
||
donumber record_number
|
||
)]});
|
||
|
||
foreach my $pair (zip(@sales_reclamation_items, @converted_sales_delivery_order_items)) {
|
||
my ($first, $second) = @{$pair};
|
||
ok Compare($first->strip->as_tree, $second->strip->as_tree, {ignore_hash_keys => [qw(
|
||
id delivery_order_id reclamation_id itime mtime
|
||
cusordnumber marge_price_factor ordnumber transdate
|
||
description reason_description_ext reason_description_int reason_id
|
||
)]});
|
||
}
|
||
ok Compare($sales_reclamation->strip->as_tree, $converted_sales_delivery_order->strip->as_tree, {ignore_hash_keys => [qw(
|
||
id employee_id itime mtime delivered reqdate
|
||
is_sales order_type ordnumber oreqnumber
|
||
amount exchangerate netamount
|
||
cp_id contact_id
|
||
cusordnumber cv_record_number
|
||
donumber record_number
|
||
)]});
|
||
|
||
|
||
# purchase
|
||
foreach my $pair (zip(@purchase_delivery_order_items, @converted_purchase_reclamation_items)) {
|
||
my ($first, $second) = @{$pair};
|
||
ok Compare($first->strip->as_tree, $second->strip->as_tree, {ignore_hash_keys => [qw(
|
||
id delivery_order_id reclamation_id itime mtime
|
||
cusordnumber marge_price_factor ordnumber transdate
|
||
description reason_description_ext reason_description_int reason_id
|
||
)]});
|
||
}
|
||
ok Compare($purchase_delivery_order->strip->as_tree, $converted_purchase_reclamation->strip->as_tree, {ignore_hash_keys => [qw(
|
||
id employee_id itime mtime reqdate
|
||
is_sales order_type ordnumber oreqnumber
|
||
amount exchangerate netamount
|
||
cp_id contact_id
|
||
cusordnumber cv_record_number
|
||
donumber record_number
|
||
)]});
|
||
|
||
foreach my $pair (zip(@purchase_reclamation_items, @converted_purchase_delivery_order_items)) {
|
||
my ($first, $second) = @{$pair};
|
||
ok Compare($first->strip->as_tree, $second->strip->as_tree, {ignore_hash_keys => [qw(
|
||
id delivery_order_id reclamation_id itime mtime
|
||
cusordnumber marge_price_factor ordnumber transdate
|
||
description reason_description_ext reason_description_int reason_id
|
||
)]});
|
||
}
|
||
ok Compare($purchase_reclamation->strip->as_tree, $converted_purchase_delivery_order->strip->as_tree, {ignore_hash_keys => [qw(
|
||
id employee_id itime mtime delivered reqdate
|
||
is_sales order_type ordnumber oreqnumber
|
||
amount exchangerate netamount
|
||
cp_id contact_id
|
||
cusordnumber cv_record_number
|
||
donumber record_number
|
||
)]});
|
||
|
||
|
||
|
||
#diag Dumper($purchase_reclamation->strip->as_tree);
|
||
#diag Dumper($linked_purchase_reclamation->strip->as_tree);
|
||
|
||
|
||
####
|
||
clear_up();
|
||
|
||
done_testing;
|
||
|
||
1;
|
t/workflow/order_reclamation.t | ||
---|---|---|
use Test::More;
|
||
|
||
use strict;
|
||
|
||
use lib 't';
|
||
use utf8;
|
||
|
||
use Carp;
|
||
use Data::Dumper;
|
||
use Data::Compare;
|
||
use Support::TestSetup;
|
||
use Test::Exception;
|
||
use List::Util qw(zip);
|
||
|
||
use SL::DB::Order;
|
||
use SL::DB::Reclamation;
|
||
use SL::DB::ReclamationReason;
|
||
use SL::DB::Customer;
|
||
use SL::DB::Vendor;
|
||
use SL::DB::Department;
|
||
use SL::DB::Currency;
|
||
use SL::DB::PaymentTerm;
|
||
use SL::DB::DeliveryTerm;
|
||
use SL::DB::Employee;
|
||
use SL::DB::Part;
|
||
use SL::DB::Unit;
|
||
|
||
use Rose::DB::Object::Helpers qw(clone);
|
||
|
||
use SL::Dev::ALL qw(:ALL);
|
||
|
||
my (
|
||
$customer, $vendor,
|
||
$employee,
|
||
$payment_term,
|
||
$delivery_term,
|
||
$unit,
|
||
@parts,
|
||
$department,
|
||
$relamation_reason,
|
||
);
|
||
|
||
|
||
sub clear_up {
|
||
foreach (qw(
|
||
Order OrderItem
|
||
Reclamation ReclamationItem
|
||
Part
|
||
Customer Vendor
|
||
Department PaymentTerm DeliveryTerm
|
||
)) {
|
||
"SL::DB::Manager::${_}"->delete_all(all => 1);
|
||
}
|
||
SL::DB::Manager::Employee->delete_all(where => [ login => 'testuser' ]);
|
||
};
|
||
|
||
sub reset_state {
|
||
my %params = @_;
|
||
|
||
clear_up();
|
||
|
||
$unit = SL::DB::Manager::Unit->find_by(name => 'kg') || die "Can't find unit 'kg'";
|
||
|
||
$employee = SL::DB::Employee->new(
|
||
'login' => 'testuser',
|
||
'name' => 'Test User',
|
||
)->save;
|
||
|
||
$department = SL::DB::Department->new(
|
||
'description' => 'Test Department',
|
||
)->save;
|
||
|
||
$payment_term = create_payment_terms(
|
||
'description' => '14Tage 2%Skonto, 30Tage netto',
|
||
'description_long' => "Innerhalb von 14 Tagen abzüglich 2 % Skonto, innerhalb von 30 Tagen rein netto.|Bei einer Zahlung bis zum <%skonto_date%> gewähren wir 2 % Skonto (EUR <%skonto_amount%>) entspricht EUR <%total_wo_skonto%>.Bei einer Zahlung bis zum <%netto_date%> ist der fällige Betrag in Höhe von <%total%> <%currency%> zu überweisen.",
|
||
'percent_skonto' => '0.02',
|
||
'terms_netto' => 30,
|
||
'terms_skonto' => 14
|
||
);
|
||
|
||
$delivery_term = SL::DB::DeliveryTerm->new(
|
||
'description' => 'Test Delivey Term',
|
||
'description_long' => 'Test Delivey Term Test Delivey Term',
|
||
)->save;
|
||
|
||
# some parts/services
|
||
@parts = ();
|
||
push @parts, new_part(
|
||
partnumber => 'Part_1_KG',
|
||
unit => $unit->name,
|
||
)->save;
|
||
push @parts, new_service(
|
||
partnumber => 'Serv_1',
|
||
)->save;
|
||
push @parts, new_part(
|
||
partnumber => 'Part_2',
|
||
)->save;
|
||
push @parts, new_service(
|
||
partnumber => 'Serv_2'
|
||
)->save;
|
||
|
||
$relamation_reason = SL::DB::ReclamationReason->new(
|
||
name => "test_reason",
|
||
description => "",
|
||
position => 1,
|
||
);
|
||
}
|
||
|
||
Support::TestSetup::login();
|
||
|
||
reset_state();
|
||
|
||
#####
|
||
|
||
my $sales_reclamation = SL::Dev::Record::create_sales_reclamation(
|
||
save => 1,
|
||
employee => $employee,
|
||
shippingpoint => "sp",
|
||
transaction_description => "td1",
|
||
payment => $payment_term,
|
||
delivery_term => $delivery_term,
|
||
taxincluded => 0,
|
||
reclamation_items => [
|
||
SL::Dev::Record::create_reclamation_item(
|
||
part => $parts[0], qty => 3, sellprice => 70,
|
||
reason => $relamation_reason,
|
||
),
|
||
SL::Dev::Record::create_reclamation_item(
|
||
part => $parts[1], qty => 10, sellprice => 50,
|
||
reason => $relamation_reason,
|
||
),
|
||
],
|
||
)->load;
|
||
|
||
my $purchase_reclamation = SL::Dev::Record::create_purchase_reclamation(
|
||
save => 1,
|
||
employee => $employee,
|
||
shippingpoint => "sp",
|
||
transaction_description => "td2",
|
||
payment => $payment_term,
|
||
delivery_term => $delivery_term,
|
||
taxincluded => 0,
|
||
reclamation_items => [
|
||
SL::Dev::Record::create_reclamation_item(
|
||
part => $parts[0], qty => 3, sellprice => 70,
|
||
reason => $relamation_reason,
|
||
),
|
||
SL::Dev::Record::create_reclamation_item(
|
||
part => $parts[1], qty => 10, sellprice => 50,
|
||
reason => $relamation_reason,
|
||
),
|
||
],
|
||
)->load;
|
||
|
||
|
||
my $sales_order = SL::Dev::Record::create_sales_order(
|
||
save => 1,
|
||
employee => $employee,
|
||
shippingpoint => "sp",
|
||
transaction_description => "td3",
|
||
payment_terms => $payment_term,
|
||
delivery_term => $delivery_term,
|
||
taxincluded => 0,
|
||
orderitems => [ SL::Dev::Record::create_order_item(part => $parts[0], qty => 3, sellprice => 70),
|
||
SL::Dev::Record::create_order_item(part => $parts[1], qty => 10, sellprice => 50),
|
||
]
|
||
)->load;
|
||
|
||
my $purchase_order = SL::Dev::Record::create_purchase_order(
|
||
save => 1,
|
||
employee => $employee,
|
||
shippingpoint => "sp",
|
||
transaction_description => "td4",
|
||
payment_terms => $payment_term,
|
||
delivery_term => $delivery_term,
|
||
taxincluded => 0,
|
||
orderitems => [ SL::Dev::Record::create_order_item(part => $parts[0], qty => 3, sellprice => 70),
|
||
SL::Dev::Record::create_order_item(part => $parts[1], qty => 10, sellprice => 50),
|
||
]
|
||
)->load;
|
||
|
||
# convert order → reclamation
|
||
my $converted_sales_reclamation = $sales_order->convert_to_reclamation;
|
||
$converted_sales_reclamation->items_sorted->[0]->reason($relamation_reason);
|
||
$converted_sales_reclamation->items_sorted->[1]->reason($relamation_reason);
|
||
$converted_sales_reclamation->save->load;
|
||
my $converted_purchase_reclamation = $purchase_order->convert_to_reclamation;
|
||
$converted_purchase_reclamation->items_sorted->[0]->reason($relamation_reason);
|
||
$converted_purchase_reclamation->items_sorted->[1]->reason($relamation_reason);
|
||
$converted_purchase_reclamation->save->load;
|
||
|
||
# convert reclamation → order
|
||
my $converted_sales_order = $sales_reclamation->convert_to_order->save->load;
|
||
my $converted_purchase_order = $purchase_reclamation->convert_to_order->save->load;
|
||
|
||
|
||
#get items before strip
|
||
my @purchase_reclamation_items = $purchase_reclamation->items_sorted;
|
||
my @sales_reclamation_items = $sales_reclamation->items_sorted;
|
||
my @converted_purchase_reclamation_items = $converted_purchase_reclamation->items_sorted;
|
||
my @converted_sales_reclamation_items = $converted_sales_reclamation->items_sorted;
|
||
my @purchase_order_items = $purchase_order->items_sorted;
|
||
my @sales_order_items = $sales_order->items_sorted;
|
||
my @converted_purchase_order_items = $converted_purchase_order->items_sorted;
|
||
my @converted_sales_order_items = $converted_sales_order->items_sorted;
|
||
|
||
|
||
### TESTS #####################################################################
|
||
|
||
## created sales und purchase reclamation should be nearly the same
|
||
my $sales_reclamation_tmp = clone($sales_reclamation);
|
||
my $purchase_reclamation_tmp = clone($purchase_reclamation);
|
||
# clean different values
|
||
foreach (qw(
|
||
customer_id vendor_id
|
||
id record_number
|
||
salesman_id
|
||
transaction_description
|
||
itime mtime
|
||
)) {
|
||
$sales_reclamation_tmp->$_(undef);
|
||
$purchase_reclamation_tmp->$_(undef);
|
||
}
|
||
foreach my $pair (zip(@purchase_reclamation_items, @sales_reclamation_items)) {
|
||
my ($first, $second) = @{$pair};
|
||
my $first_tmp = clone($first);
|
||
my $second_tmp = clone($second);
|
||
foreach (qw(
|
||
id reclamation_id
|
||
itime mtime
|
||
)) {
|
||
$first_tmp->$_(undef);
|
||
$second_tmp->$_(undef);
|
||
}
|
||
is_deeply($first_tmp->strip->as_tree, $second_tmp->strip->as_tree);
|
||
}
|
||
is_deeply($purchase_reclamation_tmp->strip->as_tree, $sales_reclamation_tmp->strip->as_tree);
|
||
|
||
## created sales und purchase order should be nearly the same
|
||
my $sales_order_tmp = clone($sales_order);
|
||
my $purchase_order_tmp = clone($purchase_order);
|
||
# clean different values
|
||
foreach (qw(
|
||
customer_id vendor_id
|
||
id
|
||
ordnumber salesman_id
|
||
transaction_description
|
||
itime mtime
|
||
)) {
|
||
$sales_order_tmp->$_(undef);
|
||
$purchase_order_tmp->$_(undef);
|
||
}
|
||
foreach my $pair (zip(@purchase_order_items, @sales_order_items)) {
|
||
my ($first, $second) = @{$pair};
|
||
my $first_tmp = clone($first);
|
||
my $second_tmp = clone($second);
|
||
foreach (qw(
|
||
id trans_id
|
||
itime mtime
|
||
)) {
|
||
$first_tmp->$_(undef);
|
||
$second_tmp->$_(undef);
|
||
}
|
||
is_deeply($first_tmp->strip->as_tree, $second_tmp->strip->as_tree);
|
||
}
|
||
is_deeply($purchase_order_tmp->strip->as_tree, $sales_order_tmp->strip->as_tree);
|
||
|
||
|
||
## converted have to be linked to parent
|
||
# sales
|
||
my $linked_sales_order = $converted_sales_reclamation->linked_records->[0];
|
||
my $linked_sales_reclamation = $converted_sales_order->linked_records->[0];
|
||
is_deeply($linked_sales_order->strip->as_tree, $sales_order->strip->as_tree);
|
||
is_deeply($linked_sales_reclamation->strip->as_tree, $sales_reclamation->load->strip->as_tree);
|
||
|
||
# purchase
|
||
my $linked_purchase_order = $converted_purchase_reclamation->linked_records->[0];
|
||
my $linked_purchase_reclamation = $converted_purchase_order->linked_records->[0];
|
||
is_deeply($linked_purchase_order->strip->as_tree, $purchase_order->strip->as_tree);
|
||
is_deeply($linked_purchase_reclamation->strip->as_tree, $purchase_reclamation->load->strip->as_tree);
|
||
|
||
|
||
## converted should be nealy the same
|
||
# sales
|
||
foreach my $pair (zip(@sales_order_items, @converted_sales_reclamation_items)) {
|
||
my ($first, $second) = @{$pair};
|
||
ok Compare($first->strip->as_tree, $second->strip->as_tree, {ignore_hash_keys => [qw(
|
||
id trans_id reclamation_id itime mtime
|
||
cusordnumber marge_percent marge_price_factor marge_total optional ordnumber ship subtotal transdate
|
||
reason_description_ext reason_description_int reason_id
|
||
)]});
|
||
}
|
||
ok Compare($sales_order->strip->as_tree, $converted_sales_reclamation->strip->as_tree, {ignore_hash_keys => [qw(
|
||
id employee_id itime mtime reqdate transdate
|
||
delivery_customer_id delivery_vendor_id expected_billing_date marge_percent marge_total order_probability proforma quonumber quotation
|
||
cp_id contact_id
|
||
cusordnumber cv_record_number
|
||
ordnumber record_number
|
||
)]});
|
||
|
||
foreach my $pair (zip(@sales_reclamation_items, @converted_sales_order_items)) {
|
||
my ($first, $second) = @{$pair};
|
||
ok Compare($first->strip->as_tree, $second->strip->as_tree, {ignore_hash_keys => [qw(
|
||
id trans_id reclamation_id itime mtime
|
||
cusordnumber marge_percent marge_price_factor marge_total optional ordnumber ship subtotal transdate
|
||
reason_description_ext reason_description_int reason_id
|
||
)]});
|
||
}
|
||
ok Compare($sales_reclamation->strip->as_tree, $converted_sales_order->strip->as_tree, {ignore_hash_keys => [qw(
|
||
id employee_id itime mtime reqdate transdate
|
||
delivery_customer_id delivery_vendor_id expected_billing_date marge_percent marge_total order_probability proforma quonumber quotation
|
||
cp_id contact_id
|
||
cusordnumber cv_record_number
|
||
ordnumber record_number
|
||
)]});
|
||
|
||
# purchase
|
||
foreach my $pair (zip(@purchase_order_items, @converted_purchase_reclamation_items)) {
|
||
my ($first, $second) = @{$pair};
|
||
ok Compare($first->strip->as_tree, $second->strip->as_tree, {ignore_hash_keys => [qw(
|
||
id trans_id reclamation_id itime mtime
|
||
cusordnumber marge_percent marge_price_factor marge_total optional ordnumber ship subtotal transdate
|
||
reason_description_ext reason_description_int reason_id
|
||
)]});
|
||
}
|
||
ok Compare($purchase_order->strip->as_tree, $converted_purchase_reclamation->strip->as_tree, {ignore_hash_keys => [qw(
|
||
id employee_id itime mtime reqdate transdate
|
||
delivery_customer_id delivery_vendor_id expected_billing_date marge_percent marge_total order_probability proforma quonumber quotation
|
||
cp_id contact_id
|
||
cusordnumber cv_record_number
|
||
ordnumber record_number
|
||
)]});
|
||
|
||
foreach my $pair (zip(@purchase_reclamation_items, @converted_purchase_order_items)) {
|
||
my ($first, $second) = @{$pair};
|
||
ok Compare($first->strip->as_tree, $second->strip->as_tree, {ignore_hash_keys => [qw(
|
||
id trans_id reclamation_id itime mtime
|
||
cusordnumber marge_percent marge_price_factor marge_total optional ordnumber ship subtotal transdate
|
||
reason_description_ext reason_description_int reason_id
|
||
)]});
|
||
}
|
||
ok Compare($purchase_reclamation->strip->as_tree, $converted_purchase_order->strip->as_tree, {ignore_hash_keys => [qw(
|
||
id employee_id itime mtime reqdate transdate
|
||
delivery_customer_id delivery_vendor_id expected_billing_date marge_percent marge_total order_probability proforma quonumber quotation
|
||
cp_id contact_id
|
||
cusordnumber cv_record_number
|
||
ordnumber record_number
|
||
)]});
|
||
|
||
####
|
||
clear_up();
|
||
|
||
done_testing;
|
||
|
||
1;
|
t/workflow/reclamation_reclamation.t | ||
---|---|---|
use Test::More;
|
||
|
||
use strict;
|
||
|
||
use lib 't';
|
||
use utf8;
|
||
|
||
use Carp;
|
||
use Data::Dumper;
|
||
use Support::TestSetup;
|
||
use Test::Exception;
|
||
use List::Util qw(zip);
|
||
|
||
use SL::DB::Reclamation;
|
||
use SL::DB::ReclamationReason;
|
||
use SL::DB::Customer;
|
||
use SL::DB::Vendor;
|
||
use SL::DB::Department;
|
||
use SL::DB::Currency;
|
||
use SL::DB::PaymentTerm;
|
||
use SL::DB::DeliveryTerm;
|
||
use SL::DB::Employee;
|
||
use SL::DB::Part;
|
||
use SL::DB::Unit;
|
||
|
||
use Rose::DB::Object::Helpers qw(clone);
|
||
|
||
use SL::Dev::ALL qw(:ALL);
|
||
|
||
my (
|
||
$customer, $vendor,
|
||
$employee,
|
||
$payment_term,
|
||
$delivery_term,
|
||
$unit,
|
||
@parts,
|
||
$department,
|
||
$relamation_reason,
|
||
);
|
||
|
||
|
||
sub clear_up {
|
||
foreach (qw(
|
||
Reclamation ReclamationItem
|
||
Part
|
||
Customer Vendor
|
||
Department PaymentTerm DeliveryTerm
|
||
)) {
|
||
"SL::DB::Manager::${_}"->delete_all(all => 1);
|
||
}
|
||
SL::DB::Manager::Employee->delete_all(where => [ login => 'testuser' ]);
|
||
};
|
||
|
||
sub reset_state {
|
||
my %params = @_;
|
||
|
||
clear_up();
|
||
|
||
$unit = SL::DB::Manager::Unit->find_by(name => 'kg') || die "Can't find unit 'kg'";
|
||
|
||
$employee = SL::DB::Employee->new(
|
||
'login' => 'testuser',
|
||
'name' => 'Test User',
|
||
)->save;
|
||
|
||
$department = SL::DB::Department->new(
|
||
'description' => 'Test Department',
|
||
)->save;
|
||
|
||
$payment_term = create_payment_terms(
|
||
'description' => '14Tage 2%Skonto, 30Tage netto',
|
||
'description_long' => "Innerhalb von 14 Tagen abzüglich 2 % Skonto, innerhalb von 30 Tagen rein netto.|Bei einer Zahlung bis zum <%skonto_date%> gewähren wir 2 % Skonto (EUR <%skonto_amount%>) entspricht EUR <%total_wo_skonto%>.Bei einer Zahlung bis zum <%netto_date%> ist der fällige Betrag in Höhe von <%total%> <%currency%> zu überweisen.",
|
||
'percent_skonto' => '0.02',
|
||
'terms_netto' => 30,
|
||
'terms_skonto' => 14
|
||
);
|
||
|
||
$delivery_term = SL::DB::DeliveryTerm->new(
|
||
'description' => 'Test Delivey Term',
|
||
'description_long' => 'Test Delivey Term Test Delivey Term',
|
||
)->save;
|
||
|
||
# some parts/services
|
||
@parts = ();
|
||
push @parts, new_part(
|
||
partnumber => 'Part_1_KG',
|
||
unit => $unit->name,
|
||
)->save;
|
||
push @parts, new_service(
|
||
partnumber => 'Serv_1',
|
||
)->save;
|
||
push @parts, new_part(
|
||
partnumber => 'Part_2',
|
||
)->save;
|
||
push @parts, new_service(
|
||
partnumber => 'Serv_2'
|
||
)->save;
|
||
|
||
$relamation_reason = SL::DB::ReclamationReason->new(
|
||
name => "test_reason",
|
||
description => "",
|
||
position => 1,
|
||
);
|
||
}
|
||
|
||
Support::TestSetup::login();
|
||
|
||
reset_state();
|
||
|
||
#####
|
||
|
||
my $sales_reclamation = SL::Dev::Record::create_sales_reclamation(
|
||
save => 1,
|
||
employee => $employee,
|
||
shippingpoint => "sp",
|
||
transaction_description => "td1",
|
||
payment => $payment_term,
|
||
delivery_term => $delivery_term,
|
||
taxincluded => 0,
|
||
reclamation_items => [
|
||
SL::Dev::Record::create_reclamation_item(
|
||
part => $parts[0], qty => 3, sellprice => 70,
|
||
reason => $relamation_reason,
|
||
),
|
||
SL::Dev::Record::create_reclamation_item(
|
||
part => $parts[1], qty => 10, sellprice => 50,
|
||
reason => $relamation_reason,
|
||
),
|
||
],
|
||
)->load;
|
||
|
||
my $purchase_reclamation = SL::Dev::Record::create_purchase_reclamation(
|
||
save => 1,
|
||
employee => $employee,
|
||
shippingpoint => "sp",
|
||
transaction_description => "td2",
|
||
payment => $payment_term,
|
||
delivery_term => $delivery_term,
|
||
taxincluded => 0,
|
||
reclamation_items => [
|
||
SL::Dev::Record::create_reclamation_item(
|
||
part => $parts[0], qty => 3, sellprice => 70,
|
||
reason => $relamation_reason,
|
||
),
|
||
SL::Dev::Record::create_reclamation_item(
|
||
part => $parts[1], qty => 10, sellprice => 50,
|
||
reason => $relamation_reason,
|
||
),
|
||
],
|
||
)->load;
|
||
|
||
# new
|
||
my $new_sales_reclamation = SL::DB::Reclamation->new_from($sales_reclamation, destination_type => 'sales_reclamation')->save->load;
|
||
my $new_purchase_reclamation = SL::DB::Reclamation->new_from($purchase_reclamation, destination_type => 'purchase_reclamation')->save->load;
|
||
|
||
# convert
|
||
my $converted_purchase_reclamation = SL::DB::Reclamation->new_from($sales_reclamation, destination_type => 'purchase_reclamation');
|
||
$converted_purchase_reclamation->vendor_id($purchase_reclamation->{vendor_id});
|
||
$converted_purchase_reclamation->save->load;
|
||
my $converted_sales_reclamation = SL::DB::Reclamation->new_from($purchase_reclamation, destination_type => 'sales_reclamation');
|
||
$converted_sales_reclamation->customer_id($sales_reclamation->{customer_id});
|
||
$converted_sales_reclamation->save->load;
|
||
|
||
#get items before strip
|
||
my @purchase_reclamation_items = $purchase_reclamation->items_sorted;
|
||
my @sales_reclamation_items = $sales_reclamation->items_sorted;
|
||
my @new_purchase_reclamation_items = $new_purchase_reclamation->items_sorted;
|
||
my @new_sales_reclamation_items = $new_sales_reclamation->items_sorted;
|
||
my @converted_purchase_reclamation_items = $converted_purchase_reclamation->items_sorted;
|
||
my @converted_sales_reclamation_items = $converted_sales_reclamation->items_sorted;
|
||
|
||
|
||
### TESTS #####################################################################
|
||
|
||
## created sales und purchase reclamation should be nearly the same
|
||
my $sales_tmp = clone($sales_reclamation);
|
||
my $purchase_tmp = clone($purchase_reclamation);
|
||
# clean different values
|
||
foreach (qw(
|
||
customer_id vendor_id
|
||
id record_number transaction_description
|
||
itime mtime
|
||
)) {
|
||
$sales_tmp->$_(undef);
|
||
$purchase_tmp->$_(undef);
|
||
}
|
||
|
||
foreach my $pair (zip(@purchase_reclamation_items, @sales_reclamation_items)) {
|
||
my ($first, $second) = @{$pair};
|
||
my $first_tmp = clone($first);
|
||
my $second_tmp = clone($second);
|
||
foreach (qw(
|
||
id reclamation_id
|
||
itime mtime
|
||
)) {
|
||
$first_tmp->$_(undef);
|
||
$second_tmp->$_(undef);
|
||
}
|
||
is_deeply($first_tmp->strip->as_tree, $second_tmp->strip->as_tree);
|
||
}
|
||
is_deeply($purchase_tmp->strip->as_tree, $sales_tmp->strip->as_tree);
|
||
|
||
|
||
## converted have to be linked to parent
|
||
# new
|
||
my $linked_sales_reclamation_n = $new_sales_reclamation->linked_records->[0];
|
||
my $linked_purchase_reclamation_n = $new_purchase_reclamation->linked_records->[0];
|
||
is_deeply($linked_sales_reclamation_n->strip->as_tree, $sales_reclamation->load->strip->as_tree);
|
||
is_deeply($linked_purchase_reclamation_n->strip->as_tree, $purchase_reclamation->load->strip->as_tree);
|
||
|
||
# converted
|
||
my $linked_sales_reclamation_c = $converted_purchase_reclamation->linked_records->[0];
|
||
my $linked_purchase_reclamation_c = $converted_sales_reclamation->linked_records->[0];
|
||
is_deeply($linked_sales_reclamation_c->strip->as_tree, $sales_reclamation->load->strip->as_tree);
|
||
is_deeply($linked_purchase_reclamation_c->strip->as_tree, $purchase_reclamation->load->strip->as_tree);
|
||
|
||
|
||
## new reclamations should be nealy the same
|
||
my $new_sales_tmp = clone($new_sales_reclamation);
|
||
my $sales_tmp2 = clone($sales_reclamation);
|
||
my $new_purchase_tmp = clone($new_purchase_reclamation);
|
||
my $purchase_tmp2 = clone($purchase_reclamation);
|
||
# clean different values
|
||
foreach (qw(
|
||
id record_number
|
||
reqdate employee_id transdate
|
||
itime mtime
|
||
)) {
|
||
$new_sales_tmp->$_(undef);
|
||
$sales_tmp2->$_(undef);
|
||
$new_purchase_tmp->$_(undef);
|
||
$purchase_tmp2->$_(undef);
|
||
}
|
||
|
||
foreach my $pair (zip(@sales_reclamation_items, @new_sales_reclamation_items)) {
|
||
my ($first, $second) = @{$pair};
|
||
my $first_tmp = clone($first);
|
||
my $second_tmp = clone($second);
|
||
foreach (qw(
|
||
id reclamation_id
|
||
itime mtime
|
||
)) {
|
||
$first_tmp->$_(undef);
|
||
$second_tmp->$_(undef);
|
||
}
|
||
is_deeply($first_tmp->strip->as_tree, $second_tmp->strip->as_tree);
|
||
}
|
||
is_deeply($sales_tmp2->strip->as_tree, $new_sales_tmp->strip->as_tree);
|
||
|
||
foreach my $pair (zip(@purchase_reclamation_items, @new_purchase_reclamation_items)) {
|
||
my ($first, $second) = @{$pair};
|
||
my $first_tmp = clone($first);
|
||
my $second_tmp = clone($second);
|
||
foreach (qw(
|
||
id reclamation_id
|
||
itime mtime
|
||
)) {
|
||
$first_tmp->$_(undef);
|
||
$second_tmp->$_(undef);
|
||
}
|
||
is_deeply($first_tmp->strip->as_tree, $second_tmp->strip->as_tree);
|
||
}
|
||
is_deeply($purchase_tmp2->strip->as_tree, $new_purchase_tmp->strip->as_tree);
|
||
|
||
|
||
## converted reclamation should be nealy the same
|
||
my $sales_tmp3 = clone($sales_reclamation);
|
||
my $converted_sales_tmp = clone($converted_sales_reclamation);
|
||
my $purchase_tmp3 = clone($purchase_reclamation);
|
||
my $converted_purchase_tmp = clone($converted_purchase_reclamation);
|
||
# clean changing values
|
||
foreach (qw(
|
||
transdate
|
||
customer_id vendor_id
|
||
id record_number
|
||
employee_id reqdate
|
||
itime mtime
|
||
|
||
delivery_term_id
|
||
payment_id
|
||
)) {
|
||
$sales_tmp3->$_(undef);
|
||
$converted_sales_tmp->$_(undef);
|
||
$purchase_tmp3->$_(undef);
|
||
$converted_purchase_tmp->$_(undef);
|
||
}
|
||
|
||
# from sales to purchase
|
||
foreach my $pair (zip(@sales_reclamation_items, @converted_purchase_reclamation_items)) {
|
||
my ($first, $second) = @{$pair};
|
||
my $first_tmp = clone($first);
|
||
my $second_tmp = clone($second);
|
||
foreach (qw(
|
||
id reclamation_id
|
||
sellprice discount
|
||
itime mtime
|
||
)) {
|
||
$first_tmp->$_(undef);
|
||
$second_tmp->$_(undef);
|
||
}
|
||
is_deeply($first_tmp->strip->as_tree, $second_tmp->strip->as_tree);
|
||
}
|
||
is_deeply($sales_tmp3->strip->as_tree, $converted_purchase_tmp->strip->as_tree);
|
||
|
||
|
||
# from purchase to sales
|
||
foreach my $pair (zip(@purchase_reclamation_items, @converted_sales_reclamation_items)) {
|
||
my ($first, $second) = @{$pair};
|
||
my $first_tmp = clone($first);
|
||
my $second_tmp = clone($second);
|
||
foreach (qw(
|
||
id reclamation_id
|
||
lastcost
|
||
itime mtime
|
||
)) {
|
||
$first_tmp->$_(undef);
|
||
$second_tmp->$_(undef);
|
||
}
|
||
is_deeply($first_tmp->strip->as_tree, $second_tmp->strip->as_tree);
|
||
}
|
||
is_deeply($purchase_tmp3->strip->as_tree, $converted_sales_tmp->strip->as_tree);
|
||
|
||
#diag Dumper($first->strip->as_tree);
|
||
#diag Dumper($second->strip->as_tree);
|
||
|
||
####
|
||
clear_up();
|
||
|
||
done_testing;
|
||
|
||
1;
|
||
|
||
# set emacs to perl mode
|
||
# Local Variables:
|
||
# mode: perl
|
||
# End:
|
Auch abrufbar als: Unified diff
Reclamation: Test for workflow (reclamation, order, delivery_order)