Revision 3a21f30f
Von Jan Büren vor mehr als 2 Jahren hinzugefügt
SL/DB/Pricegroup.pm | ||
---|---|---|
7 | 7 |
use SL::DB::Helper::ActsAsList; |
8 | 8 |
|
9 | 9 |
__PACKAGE__->meta->initialize; |
10 |
__PACKAGE__->before_save('_before_save_remove_customer_pricegroup'); |
|
10 | 11 |
|
11 | 12 |
sub displayable_name { |
12 | 13 |
my $self = shift; |
... | ... | |
14 | 15 |
return join ' ', grep $_, $self->id, $self->pricegroup; |
15 | 16 |
} |
16 | 17 |
|
18 |
sub _before_save_remove_customer_pricegroup { |
|
19 |
my ($self) = @_; |
|
20 |
|
|
21 |
return 1 unless $::form->{SELF}{remove_customer_pricegroup}; |
|
22 |
|
|
23 |
my %attributes = (pricegroup_id => undef); |
|
24 |
require SL::DB::Customer; |
|
25 |
SL::DB::Manager::Customer->update_all( |
|
26 |
set => \%attributes, |
|
27 |
where => [ |
|
28 |
'pricegroup_id' => $self->id, |
|
29 |
], |
|
30 |
); |
|
31 |
|
|
32 |
return 1; |
|
33 |
} |
|
34 |
|
|
17 | 35 |
sub validate { |
18 | 36 |
my ($self) = @_; |
19 | 37 |
require SL::DB::Customer; |
20 | 38 |
|
21 | 39 |
my @errors; |
22 |
|
|
23 |
if ( $self->obsolete && SL::DB::Manager::Customer->get_all_count(query => [ pricegroup_id => $self->id ]) ) { |
|
24 |
push @errors, $::locale->text('The pricegroup is being used by customers.'); |
|
40 |
if (!$::form->{SELF}{remove_customer_pricegroup} && |
|
41 |
$self->obsolete && |
|
42 |
SL::DB::Manager::Customer->get_all_count(query => [ pricegroup_id => $self->id ]) ) { |
|
43 |
push @errors, $::locale->text('The pricegroup is being used by customers.'); |
|
25 | 44 |
} |
26 | 45 |
|
27 | 46 |
return @errors; |
Auch abrufbar als: Unified diff
Preisgruppen-Admin darf auch Preisgruppen bei allen verknüpften Kunden entfernen