magento / magento/community-features

No control over invoice generation

Open
#81 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

moved from magento2 Priority: P3 Requires PO triage
Dominant language
No language data
Stars
46
Forks
14
PR merge metrics
No merged PRs in 30d

Description

Summary

Magento currently automatically creates Invoices associated with Sales Orders when a payment for a sales order is received. This is incorrect and this is currently the case for Braintree, PayPal and other payment methods developed by the magento core team.

The fundamental problem with this is that there is no control over it and not all merchants should have an Invoice automatically generated.

Although this may be fine for some small merchants, it is not appropriate for larger merchants that have an integration with an ERP system and follow GAAP.

In particular GAAP stipulate that revenue should NOT be recognised too early and an Invoice is fundamentally an accounting transaction that affects the P&L statement. By creating and issuing an Invoice at the time of payment receipt for the Sales Order the merchant is effectively not following GAAP as they are recognising the revenue too early. It is generally accepted under GAAP to recognise revenue (i.e. Issuing of Invoice) at the time of order fulfillment / shipment rather than receipt of payment. Furthermore it results in time-separation of Revenue recognition (Invoice) and related COGS expense that is directly related to that revenue, which is also against GAAP.

Receipt of Payment for a Sales Order is actually a Balance Sheet transaction with Debit (Increase) to a Bank Account (Asset) account and a Credit (Increase) to a Customer Prepayments (Liability) account.

Invoicing and Item Fulfillment in turn result in Credit (Increase) to Sales Revenue, Debit (Decrease) in Customer Prepayments Liability, Credit (Decrease) in Inventory Asset and Debit (Increase) in COGS Expense.

Furthermore, it is possible for a Sales Order to change between the time it is received and fulfilled when stock isn't available or sold through another channel, the customer changes their mind, etc.

Where Magento is integrated with an ERP it is also generally desirable to have the ERP create the invoice and sync the invoice to Magento, rather than having the eCommerce platform try to handle accounting concepts and do so incorrectly.

If a merchant wants to generate an Invoice at the time of Payment receipt they should be allowed to do so, but at the same time they should not be forced to do so.

Similarly a refund (which is a balance sheet transaction) should not be tied to a Credit Memo (which is a P&L transaction).

This has been a constant problem and frustration for a number of larger clients with ERP integrations with Magento.

This is particularly important in the B2B space.

Examples

Create an order and pay for it through Braintree or PayPal and see how an Invoice is automatically generated.

Proposed solution

Implement a configuration option on the base payment method class that controls whether an Invoice is automatically generated when a payment accepted by that payment method. Also implement and expose a Payment entity that actually keeps track of payments.

Magento already separates payments from invoices at the lower level with data stored in sales_order_payment and sales_payment_transaction so it should not be particularly difficult to show it that way.

It is also worth noting that Payments are usually applied / allocated to Invoices when an Invoice is created and it should be possible to configure the system to either automatically allocate Payments associated with Sales Orders to Invoices or to do so manually (and sync back from the backend ERP).

Original Report: https://github.com/magento/magento2/issues/17952 by @sheldmandu

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce automatic invoice creation with Braintree or PayPal, then inspect the base payment method class and the sales_order_payment and sales_payment_transaction data mentioned in the proposal. Define how the configuration should control invoice generation and how the exposed Payment entity should relate to invoices, refunds, and credit memos; done requires a reviewed design and coverage for the payment flows.

Written by the indexing model from the issue text.

Assessment

Domain
payments
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.