use Rose::Object::MakeMethods::Generic
(
- scalar => [ qw(controller file csv save_with_cascade) ],
+ scalar => [ qw(controller file csv test_run save_with_cascade) ],
'scalar --get_set_init' => [ qw(profile displayable_columns existing_objects class manager_class cvar_columns all_cvar_configs all_languages payment_terms_by all_vc vc_by) ],
);
sub run {
- my ($self) = @_;
+ my ($self, %params) = @_;
+
+ $self->test_run($params{test_run});
$self->controller->track_progress(phase => 'parsing csv', progress => 0);
use SL::Helper::Csv;
+use SL::DBUtils;
use SL::DB::Buchungsgruppe;
use SL::DB::CustomVariable;
use SL::DB::CustomVariableConfig;
sub init_parts_by {
my ($self) = @_;
- my $parts_by = { id => { map { ( $_->id => $_ ) } grep { !$_->assembly } @{ $self->existing_objects } },
- partnumber => { part => { },
- service => { } } };
-
- foreach my $part (@{ $self->existing_objects }) {
- next if $part->assembly;
- $parts_by->{partnumber}->{ $part->type }->{ $part->partnumber } = $part;
+# my $parts_by = { id => { map { ( $_->id => $_ ) } grep { !$_->assembly } @{ $self->existing_objects } },
+# partnumber => { part => { },
+# service => { } } };
+#
+# foreach my $part (@{ $self->existing_objects }) {
+# next if $part->assembly;
+# $parts_by->{partnumber}->{ $part->type }->{ $part->partnumber } = $part;
+# }
+
+ my $parts_by = {};
+ my $sth = prepare_execute_query($::form, $::form->get_standard_dbh, 'SELECT partnumber FROM parts');
+ while (my ($partnumber) = $sth->fetchrow_array()) {
+ $parts_by->{partnumber}{$partnumber} = 1;
}
return $parts_by;
my $object = $entry->{object};
- $entry->{part} = SL::DB::Manager::Part->find_by(
- SL::DB::Manager::Part->type_filter($object->type),
- ( partnumber => $object->partnumber ) x!! $object->partnumber,
- );
+ if (!$self->test_run && $object->partnumber && $self->parts_by->{partnumber}{$object->partnumber}) {
+ $entry->{part} = SL::DB::Manager::Part->find_by(
+ SL::DB::Manager::Part->type_filter($object->type),
+ ( partnumber => $object->partnumber ) x!! $object->partnumber,
+ );
+ }
if ($self->settings->{article_number_policy} eq 'update_prices') {
+ if ($object->partnumber && $self->parts_by->{partnumber}{$object->partnumber}) {
+ push @{ $entry->{information} }, $::locale->text('Updating prices of existing entry in database');
+ }
if ($entry->{part}) {
map { $entry->{part}->$_( $object->$_ ) if defined $object->$_ } qw(sellprice listprice lastcost);