use Rose::Object::MakeMethods::Generic
(
scalar => [ qw(table makemodel_columns) ],
- 'scalar --get_set_init' => [ qw(bg_by settings parts_by price_factors_by units_by partsgroups_by
+ 'scalar --get_set_init' => [ qw(bg_by settings parts_by price_factors_by classification_by units_by partsgroups_by
warehouses_by bins_by
translation_columns all_pricegroups) ],
);
article_number_policy => 'update_prices',
shoparticle_if_missing => '0',
part_type => 'part',
+ part_classification => 0,
default_buchungsgruppe => ($bugru ? $bugru->id : undef),
apply_buchungsgruppe => 'all',
);
return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_bg } } ) } qw(id description) };
}
+sub init_classification_by {
+ my ($self) = @_;
+ my $all_classifications = SL::DB::Manager::PartClassification->get_all;
+ $_->abbreviation($::locale->text($_->abbreviation)) for @{ $all_classifications };
+ return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_classifications } } ) } qw(id abbreviation) };
+}
+
sub init_price_factors_by {
my ($self) = @_;
return { map { ( $_ => $self->controller->profile->get($_) ) } qw(apply_buchungsgruppe default_buchungsgruppe article_number_policy
sellprice_places sellprice_adjustment sellprice_adjustment_type
- shoparticle_if_missing part_type default_unit) };
+ shoparticle_if_missing part_type classification_id default_unit) };
}
sub init_all_cvar_configs {
$i++;
}
- $self->add_columns(qw(part_type)) if $self->settings->{part_type} eq 'mixed';
+ $self->add_columns(qw(part_type classification_id)) if $self->settings->{part_type} eq 'mixed';
$self->add_columns(qw(buchungsgruppen_id unit));
$self->add_columns(map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw (price_factor payment partsgroup warehouse bin));
$self->add_columns(qw(shop)) if $self->settings->{shoparticle_if_missing};
# $bg ||= SL::DB::Buchungsgruppe->new(inventory_accno_id => 1); # does this case ever occur?
my $part_type = $self->settings->{part_type};
- if ($part_type eq 'mixed') {
- $part_type = $entry->{raw_data}->{part_type} =~ m/^p/i ? 'part'
- : $entry->{raw_data}->{part_type} =~ m/^s/i ? 'service'
+ if ($part_type eq 'mixed' && $entry->{raw_data}->{part_type}) {
+ $part_type = $entry->{raw_data}->{part_type} =~ m/^p/i ? 'part'
+ : $entry->{raw_data}->{part_type} =~ m/^s/i ? 'service'
: $entry->{raw_data}->{part_type} =~ m/^assem/i ? 'assembly'
: $entry->{raw_data}->{part_type} =~ m/^assor/i ? 'assortment'
- : undef;
+ : $self->settings->{part_type};
+ }
+ my $classification_id = $self->settings->{classification_id};
+
+ if ( $entry->{raw_data}->{pclass} && length($entry->{raw_data}->{pclass}) >= 2 ) {
+ my $abbr1 = substr($entry->{raw_data}->{pclass},0,1);
+ my $abbr2 = substr($entry->{raw_data}->{pclass},1);
+
+ if ( $self->classification_by->{abbreviation}->{$abbr2} ) {
+ my $tmp_classification_id = $self->classification_by->{abbreviation}->{$abbr2}->id;
+ $classification_id = $tmp_classification_id if $tmp_classification_id;
+ }
+ if ($part_type eq 'mixed') {
+ $part_type = $abbr1 eq $::locale->text('Part (typeabbreviation)') ? 'part'
+ : $abbr1 eq $::locale->text('Service (typeabbreviation)') ? 'service'
+ : $abbr1 eq $::locale->text('Assembly (typeabbreviation)') ? 'assembly'
+ : $abbr1 eq $::locale->text('Assortment (typeabbreviation)') ? 'assortment'
+ : undef;
+ }
}
# when saving income_accno_id or expense_accno_id use ids from the selected
}
$entry->{object}->part_type($part_type);
+ $entry->{object}->classification_id( $classification_id );
return 1;
}
# Check whether or not part group ID is valid.
if ($object->partsgroup_id && !$self->partsgroups_by->{id}->{ $object->partsgroup_id }) {
- push @{ $entry->{errors} }, $::locale->text('Error: Invalid parts group');
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid parts group id #1', $object->partsgroup_id);
return 0;
}
my $pg = $self->partsgroups_by->{partsgroup}->{ $entry->{raw_data}->{partsgroup} };
if (!$pg) {
- push @{ $entry->{errors} }, $::locale->text('Error: Invalid parts group');
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid parts group name #1', $entry->{raw_data}->{partsgroup});
return 0;
}
foreach my $pricegroup (@{ $self->all_pricegroups }) {
$idx++;
my $sellprice = $entry->{raw_data}->{"pricegroup_${idx}"};
- next if $sellprice eq '';
+ next if ($sellprice // '') eq '';
push @prices, SL::DB::Price->new(pricegroup_id => $pricegroup->id,
price => $::form->parse_amount(\%::myconfig, $sellprice));
my %old_makemodels_by_mm = map { $_->make . $; . $_->model => $_ } $entry->{part}->makemodels;
my @new_makemodels;
- foreach my $makemodel ($object->makemodels()) {
+ foreach my $makemodel (@{ $object->makemodels_sorted }) {
my $makemodel_orig = $old_makemodels_by_mm{$makemodel->make,$makemodel->model};
$found_any = 1;
}
}
- $entry->{part}->makemodels([ $entry->{part}->makemodels, @new_makemodels ]) if @new_makemodels;
+ $entry->{part}->makemodels([ @{$entry->{part}->makemodels_sorted}, @new_makemodels ]) if @new_makemodels;
# reindex makemodels
my $i = 0;
- $_->sortorder(++$i) for @{ $entry->{part}->makemodels };
+ $_->sortorder(++$i) for @{ $entry->{part}->makemodels_sorted };
$self->save_with_cascade(1) if $found_any;
}
sub set_various_fields {
my ($self, $entry) = @_;
- $entry->{object}->priceupdate(DateTime->now_local);
+ my $object = $entry->{object_to_save} || $entry->{object};
+
+ $object->priceupdate(DateTime->now_local);
}
sub init_profile {
my $without_number = [ grep { $_->{object}->partnumber eq '####' } @{ $self->controller->data } ];
map { $_->{object}->partnumber('') } @{ $without_number };
-
$self->SUPER::save_objects(data => $with_number);
$self->SUPER::save_objects(data => $without_number);
}
$self->add_displayable_columns({ name => 'bin_id', description => $::locale->text('Bin (database ID)') },
{ name => 'bin', description => $::locale->text('Bin (name)') },
- { name => 'buchungsgruppen_id', description => $::locale->text('Booking group (database ID)') },
- { name => 'buchungsgruppe', description => $::locale->text('Booking group (name)') },
+ { name => 'buchungsgruppen_id', description => $::locale->text('Booking group (database ID)') },
+ { name => 'buchungsgruppe', description => $::locale->text('Booking group (name)') },
{ name => 'description', description => $::locale->text('Description') },
{ name => 'drawing', description => $::locale->text('Drawing') },
{ name => 'ean', description => $::locale->text('EAN') },
{ name => 'partnumber', description => $::locale->text('Part Number') },
{ name => 'partsgroup_id', description => $::locale->text('Partsgroup (database ID)') },
{ name => 'partsgroup', description => $::locale->text('Partsgroup (name)') },
+ { name => 'part_classification',description => $::locale->text('Article classification') . ' [3]' },
{ name => 'payment_id', description => $::locale->text('Payment terms (database ID)') },
{ name => 'payment', description => $::locale->text('Payment terms (name)') },
{ name => 'price_factor_id', description => $::locale->text('Price factor (database ID)') },
{ name => 'price_factor', description => $::locale->text('Price factor (name)') },
{ name => 'rop', description => $::locale->text('ROP') },
{ name => 'sellprice', description => $::locale->text('Sellprice') },
- { name => 'shop', description => $::locale->text('Shop article') },
- { name => 'type', description => $::locale->text('Article type') . ' [3]' },
+ { name => 'shop', description => $::locale->text('Shop article') },
+ { name => 'type', description => $::locale->text('Article type') . ' [3]' },
{ name => 'unit', description => $::locale->text('Unit (if missing or empty default unit will be used)') },
{ name => 've', description => $::locale->text('Verrechnungseinheit') },
{ name => 'warehouse_id', description => $::locale->text('Warehouse (database ID)') },
- { name => 'warehouse', description => $::locale->text('Warehouse (name)') },
+ { name => 'warehouse', description => $::locale->text('Warehouse (name)') },
{ name => 'weight', description => $::locale->text('Weight') },
);