Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mass invoice validation with stock management : the user is not informed anymore to validate invoices manually #12665

Closed
glelarge opened this issue Dec 9, 2019 · 0 comments
Labels
Bug This is a bug (something does not work as expected)

Comments

@glelarge
Copy link
Contributor

glelarge commented Dec 9, 2019

Bug

Normally the mass invoice validation is not authorized due to the need to choose the warehouse where to increase/decrease the stock.
A message ErrorMassValidationNotAllowedWhenStockIncreaseOnAction is displayed to inform the user to do this validation manually one by one.
The invoices should not be validated.
Currently:

  • no message is displayed
  • the invoices are validated

Environment

  • Version: 10.0.2 (second instance in parenthesis : 8.0.3)
  • OS: Debian 7 (8)
  • Web server: nginx (Apache)
  • PHP: PHP 5.6 (7.3)
  • Database: MariaDB (PostgreSQL)

Expected and actual behavior

The message ErrorMassValidationNotAllowedWhenStockIncreaseOnAction to inform the user should be displayed.
The invoices must not be validated.

Steps to reproduce the behavior

Activate the modules Invoices, Products and Stock.
In the Stock module options, set the STOCK_CALCULATE_ON_BILL option ("Decrease real stocks on validation of customer invoice/credit note") to true.
Create a product PR01.
Create a warehouse WH01 and set the quantity of PR01 in WH01.
Create a customer invoice with one line of 25 PR01. No need to create multiple invoices to reproduce the case.
Display the list of invoices and select the draft invoice(s) to be validated.
On the mass action drop list (top of the page), select the 'Validate' action.
Click on the 'Confirm' button.
No message is displayed.
The invoice is validated but the stock is not impacted.

Reason of the issue

Code references are based on the branch 10.0.

In the file core/actions_massactions.inc.php l.1087:

// Validate records
if (! $error && $massaction == 'validate' && $permtocreate)
{
	$objecttmp=new $objectclass($db);

	if ($objecttmp->element == 'invoice' && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_BILL))
	{
		$langs->load("errors");
		setEventMessages($langs->trans('ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'), null, 'errors');
		$error++;
	}

the test is always wrong as $objecttmp->element contains 'facture' and not 'invoice'.

The compta/facture/class/facture.class.php l.59 provides the correct value:

/**
 *	Class to manage invoices
 */
class Facture extends CommonInvoice
{
	/**
	 * @var string ID to identify managed object
	 */
	public $element='facture';

Proposed fix (based on branch 10.0)

Option 1

The basic fix would replace the tested value by 'invoice'.
Tested locally, it is working.

Option 2

Both 'invoice' and 'facture' values can be tested, like in core/class/discount.class.php l.557, 603, 648 :
if ($invoice->element == 'facture' || $invoice->element == 'invoice')

Option 3

Last option, probably stranger, would to do something like comm/action/class/actioncomm.class.php l.298 :

        // For backward compatibility
        if ($this->elementtype=='facture')  $this->elementtype='invoice';
        if ($this->elementtype=='commande') $this->elementtype='order';
        if ($this->elementtype=='contrat')  $this->elementtype='contract';

I will submit a PR following the option 2.

@glelarge glelarge added the Bug This is a bug (something does not work as expected) label Dec 9, 2019
eldy added a commit that referenced this issue Dec 9, 2019
…_with_stock_management

FIX #12665 Mass invoice validation with stock management
glelarge added a commit to glelarge/dolibarr that referenced this issue Dec 10, 2019
Normally the mass invoice validation is not authorized due to the need to choose the warehouse where to increase
or decrease the stock.
A message ErrorMassValidationNotAllowedWhenStockIncreaseOnAction is displayed to inform the user to do this
validation manually one by one.
The invoices should not be validated.
glelarge added a commit to glelarge/dolibarr that referenced this issue Dec 10, 2019
Normally the mass invoice validation is not authorized due to the need to choose the warehouse where to increase
or decrease the stock.
A message ErrorMassValidationNotAllowedWhenStockIncreaseOnAction is displayed to inform the user to do this
validation manually one by one.
The invoices should not be validated.
glelarge added a commit to glelarge/dolibarr that referenced this issue Dec 10, 2019
Normally the mass invoice validation is not authorized due to the need to choose the warehouse where to increase
or decrease the stock.
A message ErrorMassValidationNotAllowedWhenStockIncreaseOnAction is displayed to inform the user to do this
validation manually one by one.
The invoices should not be validated.
eldy added a commit that referenced this issue Dec 10, 2019
…ion_with_stock_management

FIX #12665 Mass invoice validation with stock management (branch 8.0)
eldy added a commit that referenced this issue Dec 10, 2019
…ion_with_stock_management

FIX #12665 Mass invoice validation with stock management (branch 9.0)
@eldy eldy closed this as completed in 903c377 Dec 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This is a bug (something does not work as expected)
Projects
None yet
Development

No branches or pull requests

1 participant