use Rose::Object::MakeMethods::Generic
(
- scalar => [ qw(controller file csv) ],
+ scalar => [ qw(controller file csv 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) ],
);
my $object = $entry->{object_to_save} || $entry->{object};
- if (!$object->save) {
+ if ( !$object->save(cascade => !!$self->save_with_cascade()) ) {
push @{ $entry->{errors} }, $::locale->text('Error when saving: #1', $entry->{object}->db->error);
} else {
$self->controller->num_imported($self->controller->num_imported + 1);
sub handle_makemodel {
my ($self, $entry) = @_;
+ my $object = $entry->{object};
+ my $found_any;
my @makemodels;
foreach my $idx (map { substr $_, 5 } grep { m/^make_\d+$/ && $entry->{raw_data}->{$_} } keys %{ $entry->{raw_data} }) {
push @{ $entry->{errors} }, $::locale->text('Error: Invalid vendor in column make_#1', $idx);
} else {
+ $found_any = 1;
push @makemodels, SL::DB::MakeModel->new(make => $vendor->id,
model => $entry->{raw_data}->{"model_${idx}"},
lastcost_as_number => $entry->{raw_data}->{"lastcost_${idx}"});
}
}
- $entry->{object}->makemodels(\@makemodels);
- $entry->{object}->makemodel(scalar(@makemodels) ? 1 : 0);
+ $object->makemodels(\@makemodels);
+ $object->makemodel(scalar(@makemodels) ? 1 : 0);
+
+ if ( !$entry->{part} || $self->settings->{article_number_policy} ne 'update_prices' ) {
+ return;
+ }
+
+ my %old_makemodels_by_make = map { $_->make => $_ } $entry->{part}->makemodels;
+
+ foreach my $makemodel ($object->makemodels()) {
+ my $makemodel_orig = $old_makemodels_by_make{$makemodel->make};
+ $found_any = 1;
+
+ if ($makemodel_orig) {
+ $makemodel_orig->model($makemodel->model);
+ $makemodel_orig->lastcost($makemodel->lastcost);
+
+ } else {
+ $entry->{part}->add_makemodels($makemodel);
+ }
+ }
+
+ $entry->{part}->makemodel($object->makemodel);
+
+ $self->save_with_cascade(1) if $found_any;
}
sub set_various_fields {