forked from Wavyzz/dolibarr
* societe: add missing model_pdf field The field is used by the class but wasn't declared. * societe: expose Societe::mergeCompany The code is directly copied from societe/card.php with as less changes as possible. The original code came fromdeb91ad7c1. * societe: remove fields from property copy $phone_pro and $fk_project are not existing for societe. This was added fromdeb91ad7c1. * SocieteTest: test the merge functionality This test is a simple smoke test to check that the mergeCompany() will work correctly on simple case and actually merge the details of the company. More complex deduplication pattern with objects referencing the deleted Societe object, will be written for each of the different object class in their respective test file. * societe: card: use the new mergeCompany function Since the code is almost the same, there should be no differences in behaviour right now. * societe: api_thirdparties: use Societe::mergeCompany() * societe: fix issue when merging companies When a Societe object is merged against another, its related objects are supposed to reference the new Societe object so that the databse doesn't raise foreign key errors. The list references the objects that need to be transformed, and Reception objects weren't part of this list. Fix #26272 * ReceptionTest: check company merge hook Before a Societe object is destroyed from the database, every object referencing the FK should be destroyed or should reference another object. In the case of two companies being merged, the case arises and Reception objects need to be moved to the new company. This commit brings a non-regression test for this case. Refs #26272 * Update societe.class.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
committed by
GitHub
parent
9fc5accd81
commit
c3b3840f08
@@ -356,6 +356,36 @@ class ReceptionTest extends PHPUnit\Framework\TestCase
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* testReceptionMergeCompanies
|
||||
*
|
||||
* Check that a Reception referencing a Societe object being merged into
|
||||
* another is correctly migrated to use the new Societe object.
|
||||
*
|
||||
* @param $localobject An existing validated Reception object to mark as Draft.
|
||||
*
|
||||
* @depends testReceptionSetDraft
|
||||
* @return Reception a Reception object with data fetched
|
||||
*/
|
||||
public function testReceptionMergeCompanies($localobject)
|
||||
{
|
||||
global $db, $user;
|
||||
$soc2 = new Societe($db);
|
||||
$soc2->name = "Test reception";
|
||||
$soc2_id = $soc2->create($user);
|
||||
$this->assertLessThanOrEqual($soc2_id, 0, "Cannot create second Societe object:\n".
|
||||
$soc2->errorsToString());
|
||||
|
||||
$result = $soc2->mergeCompany($localobject->id);
|
||||
$this->assertLessThanOrEqual($result, 0, "Cannot merge Societe object:\n".
|
||||
$soc2->errorsToString());
|
||||
|
||||
print __METHOD__." result=".$result."\n";
|
||||
$this->assertLessThanOrEqual($result, 0);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* testReceptionDelete
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user