https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43790

            Bug ID: 43790
           Summary: EDIFACT messages Import button always runs the invoice
                    importer, even for quotes
   Initiative type: ---
        Sponsorship ---
            status:
           Product: Koha
           Version: Main
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P5 - low
         Component: Acquisitions
          Assignee: [email protected]
          Reporter: [email protected]
        QA Contact: [email protected]
  Target Milestone: ---

The EDIFACT messages page (acqui/edifactmsgs.pl) shows an Import button for
any message whose status is 'new', whatever its type, and op=import always
calls process_invoice(). The button was added by Bug 23682 for invoices when
EdifactInvoiceImport is set to 'manual', but nothing restricts it to invoices.

If an inbound QUOTE (or ORDRSP) is left at status 'new' -- for example because
edi_cron.pl did not get as far as processing it -- the button appears and
clicking it runs the invoice importer on the quote. Quote lines carry
RFF+QLI rather than RFF+LI, so every line is skipped with
"Skipped invoice line N, missing ordernumber" in the EDI errors, an empty
aqinvoices row is created for the quote's BGM document number on every click,
and the message is marked 'received' without ever creating a basket.

Further problems in the same code path:
- op=import is a GET link rather than a cud- POST with a CSRF token, unlike
  the Delete button next to it.
- The script does not check the message is still 'new', so a repeated or stale
  request imports it again and creates duplicate invoice headers.

Proposed fix: offer Import for any unprocessed inbound message (QUOTE,
INVOICE, ORDRSP) and dispatch on message_type to process_quote,
process_invoice or process_ordrsp via a new Koha::EDI::process_message.
Outbound ORDERS messages are not importable. Make the action a cud-import POST
with CSRF token and only act on messages still in status 'new'.

Test plan:
1. Enable EDIFACT. Insert (or download) an EDI message of type QUOTE with a
   valid quote in raw_msg, status 'new', for a vendor with an EDI account.
2. Go to Acquisitions > EDIFACT messages.
3. Without the patch: click Import. The invoice importer runs: an aqinvoices
   row is created, "missing ordernumber" errors are recorded and no basket
   exists.
4. Restore the message to status 'new' and apply the patch.
5. Reload: Import is shown for QUOTE, INVOICE and ORDRSP messages with status
   'new' and not for ORDERS or already processed messages.
6. Click Import on the QUOTE: a basket is created from the quote and no
   invoice or error rows are created. Check an INVOICE (manual import mode)
   and an ORDRSP are processed by their own importer as well.
7. prove t/db_dependent/Koha/EDI.t

-- 
You are receiving this mail because:
You are the assignee for the bug.
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to