ShopOrder: billing_email zusätzlich als invoice_mail ...
[kivitendo-erp.git] / SL / DB / PartsGroup.pm
1 # This file has been auto-generated only because it didn't exist.
2 # Feel free to modify it at will; it will not be overwritten automatically.
3
4 package SL::DB::PartsGroup;
5
6 use strict;
7
8 use SL::DB::MetaSetup::PartsGroup;
9 use SL::DB::Manager::PartsGroup;
10 use SL::DB::Helper::ActsAsList;
11
12 __PACKAGE__->meta->add_relationship(
13   custom_variable_configs => {
14     type                  => 'many to many',
15     map_class             => 'SL::DB::CustomVariableConfigPartsgroup',
16   },
17   parts          => {
18     type         => 'one to many',
19     class        => 'SL::DB::Part',
20     column_map   => { id => 'partsgroup_id' },
21   },
22 );
23
24 __PACKAGE__->meta->initialize;
25
26 sub displayable_name {
27   my $self = shift;
28
29   return join ' ', grep $_, $self->id, $self->partsgroup;
30 }
31
32 sub validate {
33   my ($self) = @_;
34   require SL::DB::Customer;
35
36   my @errors;
37
38   push @errors, $::locale->text('The description is missing.') if $self->id and !$self->partsgroup;
39
40   return @errors;
41 }
42
43 sub orphaned {
44   my ($self) = @_;
45   die 'not an accessor' if @_ > 1;
46
47   return 1 unless $self->id;
48
49   my @relations = qw(
50     SL::DB::Part
51     SL::DB::CustomVariableConfigPartsgroup
52   );
53
54   for my $class (@relations) {
55     eval "require $class";
56     return 0 if $class->_get_manager_class->get_all_count(query => [ partsgroup_id => $self->id ]);
57   }
58
59   return 1;
60 }
61
62 1;