Skip to content

Wrong invoice prefix in multistore setup due to default store id #14063

Closed
@shinesoftware

Description

@shinesoftware

Preconditions

Ubuntu, Standard LAMP (Apache, MySQL, ....)
Magento ver. 2.1.9 - Clean setup by command line
PHP 7.0.8-0ubuntu0.16.04.3 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
mysql Ver 14.14 Distrib 5.7.17, for Linux (x86_64) using EditLine wrapper

Steps to reproduce

Magento Store Configuration

The magento store has been configured as multistore with multiviews.

  • Store A
    • Store View Italian (default) - id:1 - invoice prefix: S-
    • Store View English - id:3 - invoice prefix: SS-
  • Store B
    • Store View Italian (default) - id:2 - invoice prefix: Z-
    • Store View English - id:4 - invoice prefix: ZZ-

I have discovered that Magento 2 set the DefaultStoreId in the second getSequence() parameter but this is not good if you need to set a correct prefix for the invoices. Look at https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Sales/Model/ResourceModel/EntityAbstract.php#L129

If create an order from the administration panel for the Store B English Store View you'll get the Default Store Id equals to 2 but the correct value is 4.

Expected result

I would like to set the correct invoice prefix when I try to create a new invoice from a specific store view.

Actual result

Magento creates the invoice number using the default store view id

I suggest to change the storeid parameter:

protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
    /** @var \Magento\Sales\Model\AbstractModel $object */
    if ($object instanceof EntityInterface && $object->getIncrementId() == null) {
        $object->setIncrementId(
            $this->sequenceManager->getSequence(
                $object->getEntityType(),
                $object->getStore()->getId() // <<< This parameter will be get from the invoice object
            )->getNextValue()
        );
    }
    parent::_beforeSave($object);
    return $this;
}

thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Event: dmcdindiaFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentProgress: PR CreatedIndicates that Pull Request has been created to fix issueReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releasegood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions