Dolibarr / dolibarr

Dolibarr ERP CRM is a modern software package to manage your company or foundation's activity (contacts, suppliers, invoices, orders, stocks, agenda, accounting, ...). it's an open source Web application (written in PHP) designed for businesses of any sizes, foundations and freelancers.
https://www.dolibarr.org
GNU General Public License v3.0
5.52k stars 2.81k forks source link

Error: When creating an invoice for a supplier order with a negative value #30516

Closed developmentOYR closed 3 months ago

developmentOYR commented 4 months ago

Bug

Guide to reproduce the error:

When you try to create an invoice for an order with a negative value, an error occurs:

image

I proceed to create the invoice:

image

I create the invoice:

image

the error:

image

Cause of the error

The error occurs when using instantiate the DiscountAbsolute object on line 471 of the htdocs/fourn/commande/list.php file.

The solution:

To fix the error, you must import the class file of the instance that initially produces the error.

(require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';)

Dolibarr Version

19.2

Environment PHP

8.1.29

Environment Database

10.2.44-MariaDB

Steps to reproduce the behavior and expected behavior

image

I proceed to create the invoice:

image

I create the invoice:

image

Error:

image

Attached files

No response

ems-co commented 4 months ago

Did you make a pull request to fix the issue?

developmentOYR commented 4 months ago

No, the truth is I'm not very clear on how to do it. If you tell me how I can do it.

Thank you so much

ems-co commented 4 months ago

I have tried to implement the fix you provided, but now it gives a popup error (foreign key contraint fails....) dolibarr version 20.0

The issue is that by common sense one should not be able to make a purchase order of a negative value, if you also try to make a (vendor proposal of a line item with negative unit price) you cannot validate it!

So in my opinion dolibarr should not let any purchasing order or proposal to be in negative value.

What is your idea about this?

developmentOYR commented 4 months ago

There are two issues I want to comment on, one on a business level, the other in terms of code development practices.

On a business level, it is a very common practice in Spain, but in many other countries as well to issue a negative vendor purchase order when products are returned before they are actually invoiced.

The scenarios is as follows:

1) Client orders a set of items from vendor on the 5th day of the month.

2) Vendor ships the items to Client, but client decides not to accept shipment for whatever reason or simply no longer needs the items.

3) Vendor only invoices client at the end of the month. This is also a very common practice. A vendor invoices you the totality of your purchases at the end of the month.

Therefore, the vendor purchase order never issues an invoice and instead of issuing an invoice and later a credit note for the returned items, it simply issues a vendor purchase order with negative values for the items included in the original vendor purchase order.

As odd as this may seem, Dolibarr actually takes this into account and has a global variable for allowing negative lines in invoices. (FACTURE_ENABLE_NEGATIVE_LINES)

In terms of code development practices, I find it odd that an object is instantiated without calling the file that includes the necessary class , without which it cannot function.

This is the issue that I was trying to address. The proposed solution is to simply call upon the required file for said class.

ems-co commented 4 months ago

thanks for the clarification, please go ahead and create a pull request, checking your profile you have made many pull requests before.

ksar-ksar commented 3 months ago

FIX by https://github.com/Dolibarr/dolibarr/commit/23384296ea037bdea4b62997f25b591c2946b3c9