summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LedgerSMB/AM.pm12
-rw-r--r--LedgerSMB/DBObject/Company.pm6
-rw-r--r--LedgerSMB/Setting.pm4
-rw-r--r--UI/Contact/contact.html1
-rw-r--r--UI/am-defaults.html6
-rw-r--r--bin/am.pl6
-rw-r--r--t/04-template-handling.t16
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 -->
} #' ?>
</div>
<div> <!-- TODO: Move to elements.html -CT -->
+ <?lsmb IF !country; country = default_country; END -?>
<?lsmb INCLUDE select element_data = {
text_attr = "name"
value_attr = "id"
diff --git a/UI/am-defaults.html b/UI/am-defaults.html
index c34de1f5..da4cbef0 100644
--- a/UI/am-defaults.html
+++ b/UI/am-defaults.html
@@ -69,6 +69,12 @@
<?lsmb PROCESS select element_data=selects.FX_loss ?>
</td>
</tr>
+ <tr>
+ <th align="right" nowrap="nowrap"><?lsmb text('Default Country') ?></th>
+ <td>
+<?lsmb PROCESS select element_data=selects.default_country ?>
+ </td>
+ </tr>
</table>
</td>
</tr>
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 (/<td class="description">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');