I want to generate invoice automatically when I create the shipment for the order manually. How can I create a system like this. Does anyone know how to do this? Any assistance will be helpful.

1 Answer 1


I'd go the route of creating an event-observer for sales_order_shipment_save_after:

So in app/code/local/Namespace/Module/etc/config.xml:


and in app/code/local/Namespace/Module/Model/Observer.php:

class Namespace_Module_Model_Observer
   public function autoInvoice($observer) {
       $shipment = $observer->getEvent()->getShipment();
       $order = $shipment->getOrder();
           $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
           $transactionSave = Mage::getModel('core/resource_transaction')

Then you should be all set.

  • Very nice code, works perfectly for me as well. Can we also make it to capture the payment online automatically when invoice created? Jul 26, 2017 at 10:19
  • Thanks @xxx, the code should be capturing your online payment ->setRequestedCaptureCase(...) and the transactionSave->save();. Check your log files if this is not working for you.
    – Moose
    Jul 27, 2017 at 6:09
  • Anyone trie on magento 2? Jan 18, 2021 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.