View | Details | Raw Unified | Return to bug 42001
Collapse All | Expand All

(-)a/C4/UsageStats.pm (-2 / +2 lines)
Lines 316-323 sub _shared_preferences { Link Here
316
        EdiBlockDuplicateInvoice
316
        EdiBlockDuplicateInvoice
317
        EdiBlockDuplicateInvoiceEmailAddresses
317
        EdiBlockDuplicateInvoiceEmailAddresses
318
        EdiBlockDuplicateInvoiceEmailNotice
318
        EdiBlockDuplicateInvoiceEmailNotice
319
        EdiDuplicateOrderEmailAddresses
319
        EdifactOrderSendBlockDuplicatesEmailAddresses
320
        EdiDuplicateOrderEmailNotice
320
        EdifactOrderSendBlockDuplicatesEmailNotice
321
        EmailFieldPrimary
321
        EmailFieldPrimary
322
        autoMemberNum
322
        autoMemberNum
323
        BorrowerRenewalPeriodBase
323
        BorrowerRenewalPeriodBase
(-)a/Koha/EDI.pm (-38 / +57 lines)
Lines 1556-1562 sub _send_duplicate_order_email_notice { Link Here
1556
    my $logger = Koha::Logger->get( { interface => 'edi' } );
1556
    my $logger = Koha::Logger->get( { interface => 'edi' } );
1557
1557
1558
    # Check if email notifications enabled
1558
    # Check if email notifications enabled
1559
    return unless C4::Context->preference('EdiDuplicateOrderEmailNotice');
1559
    my $email_pref = C4::Context->preference('EdifactOrderSendBlockDuplicatesEmailNotice');
1560
    return unless $email_pref;
1560
1561
1561
    my $vendor_id = $vendor->vendor_id;
1562
    my $vendor_id = $vendor->vendor_id;
1562
    my $po_number = $basket->basketname;
1563
    my $po_number = $basket->basketname;
Lines 1571-1615 sub _send_duplicate_order_email_notice { Link Here
1571
        vendor_san        => $vendor->san || '',
1572
        vendor_san        => $vendor->san || '',
1572
    };
1573
    };
1573
1574
1575
    # Use acquisitions from/reply addresses, consistent with other acquisitions notices
1576
    my $from_address = C4::Context->preference('AcquisitionsDefaultEmailAddress')
1577
        || C4::Context->preference('KohaAdminEmailAddress');
1578
    my $reply_address = C4::Context->preference('AcquisitionsDefaultReplyTo') || undef;
1579
1574
    # 1. Send notification to library staff
1580
    # 1. Send notification to library staff
1575
    my $library_email_addresses = C4::Context->preference('EdiDuplicateOrderEmailAddresses');
1581
    my @library_addresses;
1576
    if ($library_email_addresses) {
1582
    if ( $email_pref eq 'AcquisitionsDefaultEmailAddress' ) {
1577
        my @library_addresses = split /\s*,\s*/, $library_email_addresses;
1583
        my $addr = C4::Context->preference('AcquisitionsDefaultEmailAddress')
1578
1584
            || C4::Context->preference('KohaAdminEmailAddress');
1579
        foreach my $to_address (@library_addresses) {
1585
        push @library_addresses, $addr if $addr;
1580
            $to_address =~ s/^\s+|\s+$//g;    # trim whitespace
1586
    } elsif ( $email_pref eq 'KohaAdminEmailAddress' ) {
1581
            next unless $to_address;
1587
        my $addr = C4::Context->preference('ReplytoDefault')
1582
            next unless Koha::Email->is_valid($to_address);
1588
            || C4::Context->preference('KohaAdminEmailAddress');
1583
1589
        push @library_addresses, $addr if $addr;
1584
            my $letter = C4::Letters::GetPreparedLetter(
1590
    } elsif ( $email_pref eq 'EdifactOrderSendBlockDuplicatesEmailAddresses' ) {
1585
                module                 => 'acquisition',
1591
        my $addresses = C4::Context->preference('EdifactOrderSendBlockDuplicatesEmailAddresses');
1586
                letter_code            => 'EDI_DUP_ORD_LIBRARY',
1592
        push @library_addresses, split /\s*,\s*/, $addresses if $addresses;
1587
                message_transport_type => 'email',
1593
    }
1588
                tables                 => {
1589
                    aqbooksellers => $vendor_id,
1590
                },
1591
                substitute => $substitute,
1592
            );
1593
1594
1594
            if ($letter) {
1595
    foreach my $to_address (@library_addresses) {
1595
                my $message_id = C4::Letters::EnqueueLetter(
1596
        $to_address =~ s/^\s+|\s+$//g;    # trim whitespace
1596
                    {
1597
        next unless $to_address;
1597
                        letter                 => $letter,
1598
        next unless Koha::Email->is_valid($to_address);
1598
                        to_address             => $to_address,
1599
                        message_transport_type => 'email',
1600
                    }
1601
                );
1602
1599
1603
                if ($message_id) {
1600
        my $letter = C4::Letters::GetPreparedLetter(
1604
                    $logger->info(
1601
            module                 => 'acquisition',
1605
                        "Library duplicate order notification queued (message_id: $message_id) for $to_address, PO number $po_number. Message will be sent by message_queue cronjob."
1602
            letter_code            => 'EDI_DUP_ORD_LIBRARY',
1606
                    );
1603
            message_transport_type => 'email',
1607
                } else {
1604
            tables                 => {
1608
                    $logger->warn("Failed to enqueue library notification to $to_address for PO number $po_number");
1605
                aqbooksellers => $vendor_id,
1606
            },
1607
            substitute => $substitute,
1608
        );
1609
1610
        if ($letter) {
1611
            my $message_id = C4::Letters::EnqueueLetter(
1612
                {
1613
                    letter       => $letter,
1614
                    to_address   => $to_address,
1615
                    from_address => $from_address,
1616
                    ( $reply_address ? ( reply_address => $reply_address ) : () ),
1617
                    message_transport_type => 'email',
1609
                }
1618
                }
1619
            );
1620
1621
            if ($message_id) {
1622
                $logger->info(
1623
                    "Library duplicate order notification queued (message_id: $message_id) for $to_address, PO number $po_number. Message will be sent by message_queue cronjob."
1624
                );
1610
            } else {
1625
            } else {
1611
                $logger->warn("Could not generate library notification letter for PO number $po_number");
1626
                $logger->warn("Failed to enqueue library notification to $to_address for PO number $po_number");
1612
            }
1627
            }
1628
        } else {
1629
            $logger->warn("Could not generate library notification letter for PO number $po_number");
1613
        }
1630
        }
1614
    }
1631
    }
1615
1632
Lines 1641-1648 sub _send_duplicate_order_email_notice { Link Here
1641
                if ($letter) {
1658
                if ($letter) {
1642
                    my $message_id = C4::Letters::EnqueueLetter(
1659
                    my $message_id = C4::Letters::EnqueueLetter(
1643
                        {
1660
                        {
1644
                            letter                 => $letter,
1661
                            letter       => $letter,
1645
                            to_address             => $vendor_email,
1662
                            to_address   => $vendor_email,
1663
                            from_address => $from_address,
1664
                            ( $reply_address ? ( reply_address => $reply_address ) : () ),
1646
                            message_transport_type => 'email',
1665
                            message_transport_type => 'email',
1647
                        }
1666
                        }
1648
                    );
1667
                    );
Lines 1929-1938 Koha::EDI Link Here
1929
    are detected (i.e. a basket with the same PO number already exists for the vendor).
1948
    are detected (i.e. a basket with the same PO number already exists for the vendor).
1930
1949
1931
    Queues two types of notifications using letter templates:
1950
    Queues two types of notifications using letter templates:
1932
    1. EDI_DUP_ORD_LIBRARY - to library staff (addresses from EdiDuplicateOrderEmailAddresses)
1951
    1. EDI_DUP_ORD_LIBRARY - to library staff (addresses from EdifactOrderSendBlockDuplicatesEmailAddresses)
1933
    2. EDI_DUP_ORD_VENDOR - to vendor contacts with edi_error_notification set
1952
    2. EDI_DUP_ORD_VENDOR - to vendor contacts with edi_error_notification set
1934
1953
1935
    Only runs if EdiDuplicateOrderEmailNotice preference is enabled.
1954
    Only runs if EdifactOrderSendBlockDuplicatesEmailNotice preference is enabled.
1936
1955
1937
    Parameters:
1956
    Parameters:
1938
    - $basket: The Aqbasket DBIC row for the basket being blocked
1957
    - $basket: The Aqbasket DBIC row for the basket being blocked
(-)a/installer/data/mysql/atomicupdate/bug_42001.pl (-9 / +20 lines)
Lines 7-41 return { Link Here
7
        my ($args) = @_;
7
        my ($args) = @_;
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
9
10
        # Email notification toggle
10
        # Email notification destination
11
        $dbh->do(
11
        $dbh->do(
12
            q{
12
            q{
13
            INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type)
13
            INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type)
14
            VALUES (
14
            VALUES (
15
                'EdiDuplicateOrderEmailNotice',
15
                'EdifactOrderSendBlockDuplicatesEmailNotice',
16
                '0',
16
                '0',
17
                NULL,
17
                '0|AcquisitionsDefaultEmailAddress|EdifactOrderSendBlockDuplicatesEmailAddresses|KohaAdminEmailAddress',
18
                'Send email notification when a duplicate EDIFACT purchase order number is detected for the same supplier.',
18
                'Send duplicate EDIFACT order block notifications using the EDI_DUP_ORD_LIBRARY notice template to the selected address. Vendor EDI contacts are always notified separately via EDI_DUP_ORD_VENDOR.',
19
                'YesNo'
19
                'Choice'
20
            )
20
            )
21
        }
21
        }
22
        );
22
        );
23
        say $out "Added system preference 'EdiDuplicateOrderEmailNotice'";
23
        $dbh->do(
24
            q{
25
            UPDATE systempreferences
26
            SET type    = 'Choice',
27
                options = '0|AcquisitionsDefaultEmailAddress|EdifactOrderSendBlockDuplicatesEmailAddresses|KohaAdminEmailAddress',
28
                value   = CASE WHEN value = '1' THEN 'AcquisitionsDefaultEmailAddress' ELSE '0' END,
29
                explanation = 'Send duplicate EDIFACT order block notifications using the EDI_DUP_ORD_LIBRARY notice template to the selected address. Vendor EDI contacts are always notified separately via EDI_DUP_ORD_VENDOR.'
30
            WHERE variable = 'EdifactOrderSendBlockDuplicatesEmailNotice'
31
              AND type = 'YesNo'
32
        }
33
        );
34
        say $out "Added system preference 'EdifactOrderSendBlockDuplicatesEmailNotice'";
24
35
25
        # Email recipient list
36
        # Email recipient list
26
        $dbh->do(
37
        $dbh->do(
27
            q{
38
            q{
28
            INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type)
39
            INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type)
29
            VALUES (
40
            VALUES (
30
                'EdiDuplicateOrderEmailAddresses',
41
                'EdifactOrderSendBlockDuplicatesEmailAddresses',
31
                '',
42
                '',
32
                NULL,
43
                NULL,
33
                'Comma-separated list of email addresses to notify when duplicate EDIFACT purchase order numbers are detected (e.g., "purchasing@library.org,edi_support@library.org"). Requires EdiDuplicateOrderEmailNotice to be enabled.',
44
                'Comma-separated list of acquisitions staff email addresses to use when EdifactOrderSendBlockDuplicatesEmailNotice is set to specific email addresses.',
34
                'Textarea'
45
                'Textarea'
35
            )
46
            )
36
        }
47
        }
37
        );
48
        );
38
        say $out "Added system preference 'EdiDuplicateOrderEmailAddresses'";
49
        say $out "Added system preference 'EdifactOrderSendBlockDuplicatesEmailAddresses'";
39
50
40
        # Add notice template - library staff notification
51
        # Add notice template - library staff notification
41
        $dbh->do(
52
        $dbh->do(
(-)a/installer/data/mysql/mandatory/sysprefs.sql (-2 / +2 lines)
Lines 245-252 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
245
('EdifactInvoiceImportBlockDuplicates', '0', NULL, 'Block automatic processing of EDIFACT invoices when a duplicate invoice number is detected for the same supplier. Similar to AcqWarnOnDuplicateInvoice for manually created invoices, but applies to invoices received via EDI.', 'YesNo'),
245
('EdifactInvoiceImportBlockDuplicates', '0', NULL, 'Block automatic processing of EDIFACT invoices when a duplicate invoice number is detected for the same supplier. Similar to AcqWarnOnDuplicateInvoice for manually created invoices, but applies to invoices received via EDI.', 'YesNo'),
246
('EdifactInvoiceImportBlockDuplicatesEmailAddresses', '', NULL, 'Comma-separated list of acquisitions staff email addresses to use when EdifactInvoiceImportBlockDuplicatesEmailNotice is set to specific email addresses.', 'Textarea'),
246
('EdifactInvoiceImportBlockDuplicatesEmailAddresses', '', NULL, 'Comma-separated list of acquisitions staff email addresses to use when EdifactInvoiceImportBlockDuplicatesEmailNotice is set to specific email addresses.', 'Textarea'),
247
('EdifactInvoiceImportBlockDuplicatesEmailNotice', '0', '0|AcquisitionsDefaultEmailAddress|EdifactInvoiceImportBlockDuplicatesEmailAddresses|KohaAdminEmailAddress', 'Send duplicate EDIFACT invoice block notifications using the EDI_DUP_INV_LIBRARY notice template to the selected address. Vendor EDI contacts are always notified separately via EDI_DUP_INV_VENDOR. Requires EdifactInvoiceImportBlockDuplicates to be enabled.', 'Choice'),
247
('EdifactInvoiceImportBlockDuplicatesEmailNotice', '0', '0|AcquisitionsDefaultEmailAddress|EdifactInvoiceImportBlockDuplicatesEmailAddresses|KohaAdminEmailAddress', 'Send duplicate EDIFACT invoice block notifications using the EDI_DUP_INV_LIBRARY notice template to the selected address. Vendor EDI contacts are always notified separately via EDI_DUP_INV_VENDOR. Requires EdifactInvoiceImportBlockDuplicates to be enabled.', 'Choice'),
248
('EdiDuplicateOrderEmailAddresses', '', NULL, 'Comma-separated list of email addresses to notify when duplicate EDIFACT purchase order numbers are detected (e.g., "purchasing@library.org,edi_support@library.org"). Requires EdiDuplicateOrderEmailNotice to be enabled.', 'Textarea'),
248
('EdifactOrderSendBlockDuplicatesEmailAddresses', '', NULL, 'Comma-separated list of acquisitions staff email addresses to use when EdifactOrderSendBlockDuplicatesEmailNotice is set to specific email addresses.', 'Textarea'),
249
('EdiDuplicateOrderEmailNotice', '0', NULL, 'Send email notification when a duplicate EDIFACT purchase order number is detected for the same supplier.', 'YesNo'),
249
('EdifactOrderSendBlockDuplicatesEmailNotice', '0', '0|AcquisitionsDefaultEmailAddress|EdifactOrderSendBlockDuplicatesEmailAddresses|KohaAdminEmailAddress', 'Send duplicate EDIFACT order block notifications using the EDI_DUP_ORD_LIBRARY notice template to the selected address. Vendor EDI contacts are always notified separately via EDI_DUP_ORD_VENDOR.', 'Choice'),
250
('ElasticsearchBoostFieldMatch', '0', NULL, 'Add a "match" query to es when searching, will follow indexes chosen in advanced search, or use title-cover for generic keyword or title index search', 'YesNo'),
250
('ElasticsearchBoostFieldMatch', '0', NULL, 'Add a "match" query to es when searching, will follow indexes chosen in advanced search, or use title-cover for generic keyword or title index search', 'YesNo'),
251
('ElasticsearchCrossFields', '1', NULL, 'Enable "cross_fields" option for searches using Elastic search.', 'YesNo'),
251
('ElasticsearchCrossFields', '1', NULL, 'Enable "cross_fields" option for searches using Elastic search.', 'YesNo'),
252
('ElasticsearchIndexStatus_authorities', '0', 'Authorities index status', NULL, NULL),
252
('ElasticsearchIndexStatus_authorities', '0', 'Authorities index status', NULL, NULL),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref (-7 / +8 lines)
Lines 215-227 Acquisitions: Link Here
215
              type: textarea
215
              type: textarea
216
              class: code
216
              class: code
217
        -
217
        -
218
            - pref: EdiDuplicateOrderEmailNotice
218
            - "Send duplicate EDIFACT order block notifications using the EDI_DUP_ORD_LIBRARY notice template to:"
219
            - pref: EdifactOrderSendBlockDuplicatesEmailNotice
219
              choices:
220
              choices:
220
                  1: Send
221
                  0: "Do not send"
221
                  0: "Don't send"
222
                  AcquisitionsDefaultEmailAddress: AcquisitionsDefaultEmailAddress
222
            - email notifications when a duplicate EDIFACT purchase order number is detected.
223
                  EdifactOrderSendBlockDuplicatesEmailAddresses: "specific email addresses"
223
        -
224
                  KohaAdminEmailAddress: KohaAdminEmailAddress
224
            - "Send duplicate order notifications to these email addresses (comma-separated):"
225
            - '<br>Vendor EDI contacts are always notified separately via the EDI_DUP_ORD_VENDOR notice using contacts flagged in the vendor''s EDI account.<br>If choosing specific email addresses, enter them here (comma-separated):'
225
            - pref: EdiDuplicateOrderEmailAddresses
226
            - pref: EdifactOrderSendBlockDuplicatesEmailAddresses
226
              type: textarea
227
              type: textarea
227
              class: code
228
              class: code
(-)a/t/db_dependent/Koha/EDI.t (-9 / +14 lines)
Lines 2999-3012 subtest 'duplicate_order_email_notifications' => sub { Link Here
2999
        return ( $bookseller, $new_basket, $ean );
2999
        return ( $bookseller, $new_basket, $ean );
3000
    };
3000
    };
3001
3001
3002
    # Test 1: No email when EdiDuplicateOrderEmailNotice is disabled
3002
    # Test 1: No email when EdifactOrderSendBlockDuplicatesEmailNotice is disabled
3003
    subtest 'email_notification_disabled' => sub {
3003
    subtest 'email_notification_disabled' => sub {
3004
        plan tests => 3;
3004
        plan tests => 3;
3005
3005
3006
        $schema->storage->txn_begin;
3006
        $schema->storage->txn_begin;
3007
3007
3008
        t::lib::Mocks::mock_preference( 'EdiDuplicateOrderEmailNotice',    0 );
3008
        t::lib::Mocks::mock_preference( 'EdifactOrderSendBlockDuplicatesEmailNotice',    0 );
3009
        t::lib::Mocks::mock_preference( 'EdiDuplicateOrderEmailAddresses', 'library@example.com' );
3009
        t::lib::Mocks::mock_preference( 'EdifactOrderSendBlockDuplicatesEmailAddresses', 'library@example.com' );
3010
3010
3011
        my ( $bookseller, $new_basket, $ean ) = $_setup_duplicate_order->();
3011
        my ( $bookseller, $new_basket, $ean ) = $_setup_duplicate_order->();
3012
3012
Lines 3018-3024 subtest 'duplicate_order_email_notifications' => sub { Link Here
3018
        is( $result->{error}, 'duplicate_po_number', 'Error code is duplicate_po_number' );
3018
        is( $result->{error}, 'duplicate_po_number', 'Error code is duplicate_po_number' );
3019
3019
3020
        my $messages = $schema->resultset('MessageQueue')->search( { to_address => 'library@example.com' } );
3020
        my $messages = $schema->resultset('MessageQueue')->search( { to_address => 'library@example.com' } );
3021
        is( $messages->count, 0, 'No email queued when EdiDuplicateOrderEmailNotice is disabled' );
3021
        is( $messages->count, 0, 'No email queued when EdifactOrderSendBlockDuplicatesEmailNotice is disabled' );
3022
3022
3023
        $logger->clear();
3023
        $logger->clear();
3024
        $schema->storage->txn_rollback;
3024
        $schema->storage->txn_rollback;
Lines 3030-3037 subtest 'duplicate_order_email_notifications' => sub { Link Here
3030
3030
3031
        $schema->storage->txn_begin;
3031
        $schema->storage->txn_begin;
3032
3032
3033
        t::lib::Mocks::mock_preference( 'EdiDuplicateOrderEmailNotice',    1 );
3033
        t::lib::Mocks::mock_preference(
3034
        t::lib::Mocks::mock_preference( 'EdiDuplicateOrderEmailAddresses', 'acq@library.org' );
3034
            'EdifactOrderSendBlockDuplicatesEmailNotice',
3035
            'EdifactOrderSendBlockDuplicatesEmailAddresses'
3036
        );
3037
        t::lib::Mocks::mock_preference( 'EdifactOrderSendBlockDuplicatesEmailAddresses', 'acq@library.org' );
3035
3038
3036
        $schema->resultset('Letter')
3039
        $schema->resultset('Letter')
3037
            ->search( { module => 'acquisition', code => [ 'EDI_DUP_ORD_LIBRARY', 'EDI_DUP_ORD_VENDOR' ] } )
3040
            ->search( { module => 'acquisition', code => [ 'EDI_DUP_ORD_LIBRARY', 'EDI_DUP_ORD_VENDOR' ] } )
Lines 3082-3089 subtest 'duplicate_order_email_notifications' => sub { Link Here
3082
3085
3083
        $schema->storage->txn_begin;
3086
        $schema->storage->txn_begin;
3084
3087
3085
        t::lib::Mocks::mock_preference( 'EdiDuplicateOrderEmailNotice',    1 );
3088
        t::lib::Mocks::mock_preference(
3086
        t::lib::Mocks::mock_preference( 'EdiDuplicateOrderEmailAddresses', '' );
3089
            'EdifactOrderSendBlockDuplicatesEmailNotice',
3090
            'EdifactOrderSendBlockDuplicatesEmailAddresses'
3091
        );
3092
        t::lib::Mocks::mock_preference( 'EdifactOrderSendBlockDuplicatesEmailAddresses', '' );
3087
3093
3088
        $schema->resultset('Letter')
3094
        $schema->resultset('Letter')
3089
            ->search( { module => 'acquisition', code => [ 'EDI_DUP_ORD_LIBRARY', 'EDI_DUP_ORD_VENDOR' ] } )
3095
            ->search( { module => 'acquisition', code => [ 'EDI_DUP_ORD_LIBRARY', 'EDI_DUP_ORD_VENDOR' ] } )
3090
- 

Return to bug 42001