CVars als Object Mixin.
[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 use SL::DB::Helper::CustomVariables (
8   module      => 'CT',
9   cvars_alias => 1,
10 );
11
12 use SL::DB::VC;
13
14 __PACKAGE__->meta->add_relationship(
15   shipto => {
16     type         => 'one to many',
17     class        => 'SL::DB::Shipto',
18     column_map   => { id      => 'trans_id' },
19     manager_args => { sort_by => 'lower(shipto.shiptoname)' },
20     query_args   => [ module  => 'CT' ],
21   },
22   contacts => {
23     type         => 'one to many',
24     class        => 'SL::DB::Contact',
25     column_map   => { id      => 'cp_cv_id' },
26     manager_args => { sort_by => 'lower(contacts.cp_name)' },
27   },
28   business => {
29     type         => 'one to one',
30     class        => 'SL::DB::Business',
31     column_map   => { business_id => 'id' },
32   },
33   custom_variables => {
34     type           => 'one to many',
35     class          => 'SL::DB::CustomVariable',
36     column_map     => { id => 'trans_id' },
37     query_args     => [ config_id => [ \"(SELECT custom_variable_configs.id FROM custom_variable_configs WHERE custom_variable_configs.module = 'CT')" ] ],
38   },
39 );
40
41 __PACKAGE__->meta->make_manager_class;
42 __PACKAGE__->meta->initialize;
43
44 __PACKAGE__->before_save('_before_save_set_vendornumber');
45
46 sub _before_save_set_vendornumber {
47   my ($self) = @_;
48
49   $self->create_trans_number if $self->vendornumber eq '';
50   return 1;
51 }
52
53 1;