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

BUG: Mo::deleteLine removes the "main" MoLine if consumed line is delete + GETPOST in class #28533

Open
Humml87 opened this issue Feb 29, 2024 · 4 comments
Labels
Bug This is a bug (something does not work as expected)

Comments

@Humml87
Copy link
Contributor

Humml87 commented Feb 29, 2024

Bug

At MoLine with Product type "Services":
Delete consumed line...
image
The result... the parent MoLine is deleted:
image

In the database is the main MoLine deleted, but the linked MoLine is existing!
image

Environment Version

19

Environment OS

No response

Environment Web server

No response

Environment PHP

No response

Environment Database

No response

Environment URL(s)

No response

Expected and actual behavior

No response

Steps to reproduce the behavior

No response

Attached files

No response

@Humml87 Humml87 added the Bug This is a bug (something does not work as expected) label Feb 29, 2024
Humml87 pushed a commit to HUSCH-GmbH/dolibarr that referenced this issue Feb 29, 2024
eldy pushed a commit that referenced this issue Mar 1, 2024
…is delete (#28535)

* fix #28533

* qual for github actions

* fix use $this->db in classes

---------

Co-authored-by: christian.humpel <christian.humpel@gmail.com>
@Humml87 Humml87 closed this as completed Mar 1, 2024
eldy added a commit that referenced this issue Mar 1, 2024
eldy added a commit that referenced this issue Mar 1, 2024
@Humml87 Humml87 reopened this Mar 2, 2024
Humml87 added a commit to HUSCH-GmbH/dolibarr that referenced this issue Mar 2, 2024
Humml87 added a commit to HUSCH-GmbH/dolibarr that referenced this issue Mar 3, 2024
Humml87 added a commit to HUSCH-GmbH/dolibarr that referenced this issue Mar 4, 2024
@eldy
Copy link
Member

eldy commented Mar 4, 2024

Seems fixed with: b870a84
If not can you describe a process to reproduce the bug. I am not able to reproduce after the fix b870a84

@Humml87
Copy link
Contributor Author

Humml87 commented Mar 4, 2024

Seems fixed with: b870a84 If not can you describe a process to reproduce the bug. I am not able to reproduce after the fix b870a84

I saw this fix (the main bug was fixed), but i think it's not a real clean fix, i found something wich is not good in my opinion:

Mo.class.php
Line 902 => $fk_movement = GETPOST('fk_movement', 'int');
-> I think a GETPOST is not good in this class, this make problems if the function will be called from elsewhere (e.g. WebService).

Line 936 / 959 / 967 => setEventMessages(....);
-> It's a part of view, i think also its not ok in the class.

Others

  • It's able to delete a line if the Mo is in a invalid status. I think the test must near on the delete function. To make it safe to use the delete of a MoLine from elsewhere.
  • Some logic works only if the call comes from the mo_production.php. If we call as example MoLine::delete from elsewhere, it make some trouble. I think this make some new Bug´s in the future.

After your fix, is it now possible to rename this PR to a QUAL PR?

I work currently on the WebService API and there i become all these problems.

Best regards Christian

@eldy
Copy link
Member

eldy commented Mar 5, 2024

You're right when you say that GETPOST should not appear into CRUD files. This is an old bad practice. We are removing them step by step.
For example, the case mentionned about Line 902 => $fk_movement = GETPOST('fk_movement', 'int');
It has been already replaced into develop branch.

Except the setEventMessage, not yet removed, I still not see why you may have trouble when calling the MoLine->delete() from a non GUI context.

@Humml87
Copy link
Contributor Author

Humml87 commented Mar 5, 2024

I still not see why you may have trouble when calling the MoLine->delete() from a non GUI context.

Hi @eldy ,
as example:
image
image

Now, if i call from non GUI MoLine->delete() for id 430:
image
What is not good currently:

  • It's possible to make a invalid db state.
  • Now if we have a invalid db state, the call GET MoLines give some confuse Lines.
  • It's possible to delete a MoLine, without verify the Mo state

... now its possible to make a new (copy) of the logic to the WebService function, but this is not the target i think.

... i think i make a good code with reduce some problems, but i see you don't like this. What is your target, what can i make better?

Best regards
Christian

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

2 participants