From ef3b11491182b85ec459c42fe4e51f6a7ca5262b Mon Sep 17 00:00:00 2001 From: einhverfr Date: Mon, 1 Dec 2008 02:15:53 +0000 Subject: Default country can now be set. git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@2422 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB/AM.pm | 12 ++++++++++-- LedgerSMB/DBObject/Company.pm | 6 +++++- LedgerSMB/Setting.pm | 4 ++-- UI/Contact/contact.html | 1 + UI/am-defaults.html | 6 ++++++ bin/am.pl | 6 ++++++ t/04-template-handling.t | 16 ++++++++++++---- 7 files changed, 42 insertions(+), 9 deletions(-) diff --git a/LedgerSMB/AM.pm b/LedgerSMB/AM.pm index 3885829e..d2fdeca2 100644 --- a/LedgerSMB/AM.pm +++ b/LedgerSMB/AM.pm @@ -1815,7 +1815,7 @@ sub save_defaults { fxgain_accno_id fxloss_accno_id glnumber sinumber vinumber sonumber ponumber sqnumber rfqnumber partnumber employeenumber customernumber vendornumber projectnumber yearend curr - weightunit businessnumber) + weightunit businessnumber default_country) ) { my $val = $form->{$_}; @@ -2416,7 +2416,15 @@ sub get_all_defaults { while ( ( $skey, $value ) = $sth->fetchrow_array() ) { $form->{$skey} = $value; } - + $sth->finish; + $query = "select id, name from country order by name"; + $sth = $dbh->prepare($query); + $sth->execute; + $form->{countries} = []; + while ($ref = $sth->fetchrow_hashref('NAME_lc')) { + push @{$form->{countries}}, $ref; + } + $sth->finish; $self->defaultaccounts( undef, $form ); $dbh->commit; } diff --git a/LedgerSMB/DBObject/Company.pm b/LedgerSMB/DBObject/Company.pm index 4d11d858..d8ea8039 100644 --- a/LedgerSMB/DBObject/Company.pm +++ b/LedgerSMB/DBObject/Company.pm @@ -11,6 +11,7 @@ retrieving customers and vendors. package LedgerSMB::DBObject::Company; +use LedgerSMB::Setting; use base qw(LedgerSMB::DBObject); use strict; @@ -165,7 +166,10 @@ sub get_metadata { @{$self->{contact_class_list}} = $self->exec_method(funcname => 'entity_list_contact_class'); - + my $country_setting = LedgerSMB::Setting->new({base => $self, copy => 'base'}); + $country_setting->{key} = 'default_country'; + $country_setting->get; + $self->{default_country} = $country_setting->{value}; } sub save_contact { diff --git a/LedgerSMB/Setting.pm b/LedgerSMB/Setting.pm index f9fc122c..637a8f84 100644 --- a/LedgerSMB/Setting.pm +++ b/LedgerSMB/Setting.pm @@ -52,8 +52,8 @@ our $VERSION = '1.0.0'; sub get { my $self = shift; - my $hashref = shift @{ $self->exec_method( funcname => 'setting_get' ) }; - $self->merge( $hashref, 'value' ); + my ($hashref) = $self->exec_method( funcname => 'setting_get' ) ; + $self->{value} = $hashref->{setting_get}; } sub increment { diff --git a/UI/Contact/contact.html b/UI/Contact/contact.html index 070b6713..0c0bb43c 100644 --- a/UI/Contact/contact.html +++ b/UI/Contact/contact.html @@ -592,6 +592,7 @@ problems with multi-word single-quoted constructs in PI tags. -CT --> } #' ?>
+ + + + + + + diff --git a/bin/am.pl b/bin/am.pl index f92e380e..9a08092d 100644 --- a/bin/am.pl +++ b/bin/am.pl @@ -1471,6 +1471,12 @@ sub defaults { 'IC_income' => {name => 'IC_income', options => []}, 'IC_inventory' => {name => 'IC_inventory', options => []}, 'IC' => {name => 'IC', options => []}, + 'default_country' => {name => 'default_country', + options => $form->{countries}, + default_values => [$form->{'default_country'}], + text_attr => 'name', + value_attr => 'id', + }, ); foreach $key ( keys %{ $form->{accno} } ) { foreach $accno ( sort keys %{ $form->{accno}{$key} } ) { diff --git a/t/04-template-handling.t b/t/04-template-handling.t index 38dcac37..6f3c0669 100644 --- a/t/04-template-handling.t +++ b/t/04-template-handling.t @@ -395,6 +395,7 @@ my $contact_request = { meta_number => 'test1', credit_id => '1', entity_class => 1, + default_country => 4, credit_list => [{ entity_class => 1, meta_number => 'test1', }], @@ -404,6 +405,13 @@ my $contact_request = { business_id => 1000, business_types => [{ id => 1, description => 'test1' }, { id => 1000, description => 'test2' }], + country_list => [{id => 1, name => 'country1'}, + {id => 2, name => 'country2'}, + {id => 3, name => 'country3'}, + {id => 4, name => 'country4'}, + {id => 5, name => 'country5'}, + {id => 6, name => 'country6'}, + ] }; # Company with Credit Accounts and business types. my $contact_template = LedgerSMB::Template->new( @@ -417,10 +425,10 @@ my $contact_template = LedgerSMB::Template->new( $contact_template->render($contact_request); my @output = get_output_line_array($contact_template); -is(grep (/value="1" selected/, @output), 0, 'Select box Value 1 unselected'); -is(grep (/value="1000" selected/, @output), 1, 'Select box Value 1000 selected'); +is(grep (/value="1" selected="selected">test1/, @output), 0, 'Select box Value 1 unselected'); +is(grep (/value="1000" selected="selected">test2/, @output), 1, 'Select box Value 1000 selected'); is(grep (/dtest1/, @output), 1, 'Contact description shows'); - +is(grep (/value="4" selected="selected">country4/, @output), 1, 'Default Country Set'); # bulk payment template tests my $payment = LedgerSMB->new(); $payment->merge({ @@ -438,7 +446,7 @@ my $payment_template = LedgerSMB::Template->new( ); $payment_template->render($payment); -my @output = get_output_line_array($payment_template); +@output = get_output_line_array($payment_template); cmp_ok(grep(/101<\/td>/, @output), '>', 0, 'Invoice row exists'); is(grep(/name="payment_101"/, @output), 0, 'Invoice locked'); is(grep(/Locked by/, @output), 1, 'Invoice locked label shown'); -- cgit v1.2.3