my $params = shift;
my $report_id = $params->{report_id};
my $from = $params->{from};
- my $email = $params->{email};
+ my $email_col = $params->{email} || 'email';
my $module = $params->{module};
my $code = $params->{code};
my $branch = $params->{branch} || "";
my $email;
my $err_count = scalar @errors;
push ( @errors, { NO_BOR_COL => $counter } ) unless defined $row->{borrowernumber};
- push ( @errors, { NO_EMAIL_COL => $counter } ) unless ( (defined $email && defined $row->{$email}) || defined $row->{email} );
+ push ( @errors, { NO_EMAIL_COL => $counter } ) unless ( defined $row->{$email_col} );
push ( @errors, { NO_FROM_COL => $counter } ) unless defined ( $from || $row->{from} );
push ( @errors, { NO_BOR => $row->{borrowernumber} } ) unless Koha::Patrons->find({borrowernumber=>$row->{borrowernumber}});
my $from_address = $from || $row->{from};
- my $to_address = $email ? $row->{$email} : $row->{email};
+ my $to_address = $row->{$email_col};
push ( @errors, { NOT_PARSE => $counter } ) unless my $content = _process_row_TT( $row, $template );
$counter++;
next if scalar @errors > $err_count; #If any problems, try next
subtest 'Email report test' => sub {
- plan tests => 9;
+ plan tests => 12;
- my $id1 = $builder->build({ source => 'Borrower',value => { surname => 'mailer', email => 'a@b.com' } })->{ borrowernumber };
- my $id2 = $builder->build({ source => 'Borrower',value => { surname => 'nomailer', email => undef } })->{ borrowernumber };
- my $id3 = $builder->build({ source => 'Borrower',value => { surname => 'norman', email => 'a@b.com' } })->{ borrowernumber };
- my $report1 = $builder->build({ source => 'SavedSql', value => { savedsql => "SELECT surname,borrowernumber,email FROM borrowers WHERE borrowernumber IN ($id1,$id2,$id3)" } })->{ id };
+ my $id1 = $builder->build({ source => 'Borrower',value => { surname => 'mailer', email => 'a@b.com', emailpro => 'b@c.com' } })->{ borrowernumber };
+ my $id2 = $builder->build({ source => 'Borrower',value => { surname => 'nomailer', email => undef, emailpro => 'd@e.com' } })->{ borrowernumber };
+ my $id3 = $builder->build({ source => 'Borrower',value => { surname => 'norman', email => 'a@b.com', emailpro => undef } })->{ borrowernumber };
+ my $report1 = $builder->build({ source => 'SavedSql', value => { savedsql => "SELECT surname,borrowernumber,email,emailpro FROM borrowers WHERE borrowernumber IN ($id1,$id2,$id3)" } })->{ id };
my $report2 = $builder->build({ source => 'SavedSql', value => { savedsql => "SELECT potato FROM mashed" } })->{ id };
my $letter1 = $builder->build({
is( $emails->[0]{letter}->{content}, "mailer", "Message has expected content");
is( $emails->[1]{letter}->{content}, "norman", "Message has expected content");
+ ($emails, $errors ) = C4::Reports::Guided::EmailReport({report_id => $report1, module => $letter1->{module} , code => $letter1->{code}, from => 'the@future.ooh', email => 'emailpro' });
+ is_deeply( $errors, [{'NO_EMAIL_COL'=>3}],"We report missing email in emailpro column");
+ is( $emails->[0]->{to_address}, 'b@c.com', "Message uses correct email");
+ is( $emails->[1]->{to_address}, 'd@e.com', "Message uses correct email");
+
};
$schema->storage->txn_rollback;