Verknüpfungen Parts/Customers/Vendors -> Custom Variables
[kivitendo-erp.git] / SL / DB / Vendor.pm
1 package SL::DB::Vendor;
2
3 use strict;
4
5 use SL::DB::MetaSetup::Vendor;
6 use SL::DB::Helper::TransNumberGenerator;
7
8 use SL::DB::VC;
9
10 __PACKAGE__->meta->add_relationship(
11   shipto => {
12     type         => 'one to many',
13     class        => 'SL::DB::Shipto',
14     column_map   => { id      => 'trans_id' },
15     manager_args => { sort_by => 'lower(shipto.shiptoname)' },
16     query_args   => [ module  => 'CT' ],
17   },
18   contacts => {
19     type         => 'one to many',
20     class        => 'SL::DB::Contact',
21     column_map   => { id      => 'cp_cv_id' },
22     manager_args => { sort_by => 'lower(contacts.cp_name)' },
23   },
24   business => {
25     type         => 'one to one',
26     class        => 'SL::DB::Business',
27     column_map   => { business_id => 'id' },
28   },
29   custom_variables => {
30     type           => 'one to many',
31     class          => 'SL::DB::CustomVariable',
32     column_map     => { id => 'trans_id' },
33     query_args     => [ config_id => [ \"(SELECT custom_variable_configs.id FROM custom_variable_configs WHERE custom_variable_configs.module = 'CT')" ] ],
34   },
35 );
36
37 __PACKAGE__->meta->make_manager_class;
38 __PACKAGE__->meta->initialize;
39
40 __PACKAGE__->before_save('_before_save_set_vendornumber');
41
42 sub _before_save_set_vendornumber {
43   my ($self) = @_;
44
45   $self->create_trans_number if $self->vendornumber eq '';
46   return 1;
47 }
48
49 1;