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

Wrong thrird-party linked by EmailCollector class on precssing customer emails #31237

Open
alsoft10 opened this issue Oct 3, 2024 · 5 comments
Assignees
Labels
Bug This is a bug (something does not work as expected)

Comments

@alsoft10
Copy link
Contributor

alsoft10 commented Oct 3, 2024

Bug

When EmailCollector class is enables and Collect_Ticket_Requests option is enabled, after processing the customer emails, if the Third-party with that email address is already present, then EmailCollector class selecting wrong thirdparty. You can see the EmailCollector class settings below.
EmailCollector class settings

You can also check the EmailCollector class output below.
EmailCollector class output

Dolibarr Version

20.0

Environment PHP

8.1.25

Environment Database

MySQL

Steps to reproduce the behavior and expected behavior

  1. Create a Third-party with and email address at Dolibarr
  2. Setup EmailCollector class with your IMAP email
  3. Send email from that Third-party email to your support IMAP email
  4. Run EmailCollector class

Attached files

No response

@alsoft10 alsoft10 added the Bug This is a bug (something does not work as expected) label Oct 3, 2024
@alsoft10 alsoft10 mentioned this issue Oct 3, 2024
@eldy
Copy link
Member

eldy commented Oct 3, 2024

I don't see error here.
You setup to extract the email and name of company into the email.
The system search for a thirdparty with email or name ALSOFT.
He found the thirdparty ALSOFT, so he load the thirdparty ALSOFT.

@alsoft10
Copy link
Contributor Author

alsoft10 commented Oct 3, 2024

Can you see the line, Thirdparty already exists with id = 1.

This ID returen after the search is wrong. My ALSOFT customer ID is actually 8. This is because of unnecessary search for thrirdparty at the end of the IF ELSE ladder. Which I deleted.

@alsoft10
Copy link
Contributor Author

alsoft10 commented Oct 5, 2024

@eldy the same configuration is working at Dolibarr 18.0.x

@alsoft10
Copy link
Contributor Author

alsoft10 commented Oct 5, 2024

@eldy problem is in the following code.
`else { // $result > 0 is ID of thirdparty
dol_syslog("One and only one existing third party has been found");

									$thirdpartystatic->fetch($result);

									$operationslog .= '<br>Thirdparty already exists with id = '.dol_escape_htmltag($thirdpartystatic->id)." and name ".dol_escape_htmltag($thirdpartystatic->name);
								}`

Here the value of $result is always one if Third-party found. As this is the return value from Class societe and method fetch. You don't need to fetch the third-party again here. If you really want to fetch third-party then the above code should be like this.
`else { // $result > 0 is ID of thirdparty
dol_syslog("One and only one existing third party has been found");

									$thirdpartystatic->fetch($thirdpartystatic->id); // ID already fetch in last call

									$operationslog .= '<br>Thirdparty already exists with id = '.dol_escape_htmltag($thirdpartystatic->id)." and name ".dol_escape_htmltag($thirdpartystatic->name);
								}`

Or if you want to make it more beautiful then, you can return the actual value from the function findNearest like this way
`public function findNearest($rowid = 0, $ref = '', $ref_ext = '', $barcode = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '', $is_client = 0, $is_supplier = 0)
{
// A rowid is known, it is a unique key so we found it
if ($rowid) {
return $rowid;
}

	// We try to find the thirdparty with exact matching on all fields
	// TODO Replace this with step by step search
	// Then search on barcode if we have it (+ restriction on is_client and is_supplier)
	// Then search on profids with a OR (+ restriction on is_client and is_supplier)
	// Then search on email (+ restriction on is_client and is_supplier)
	// Then search ref, ref_ext or alias with a OR (+ restriction on is_client and is_supplier)
	$tmpthirdparty = new Societe($this->db);
	$result = $tmpthirdparty->fetch($rowid, $ref, $ref_ext, $barcode, $idprof1, $idprof2, $idprof3, $idprof4, $idprof5, $idprof6, $email, $ref_alias, $is_client, $is_supplier);

	if ($result == 1) {
		return $tmpthirdparty->id;
	} else {
		return $result;
	}
}`

@alsoft10
Copy link
Contributor Author

@eldy This is issue is still present at Dolibarr 20.0.1

@eldy eldy self-assigned this Oct 22, 2024
@alsoft10 alsoft10 mentioned this issue Oct 23, 2024
eldy added a commit that referenced this issue Oct 23, 2024
@alsoft10 alsoft10 mentioned this issue Dec 17, 2024
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