YetiForceCompany / YetiForce

One of the most innovative CRM systems that supports mainly business processes and allows for customization according to your needs. Be ahead of your competition and implement YetiForce!
https://yetiforce.com
4 stars 3 forks source link

[bug] Import of quotes from csv not working - import matches items that has been deleted, fix included to make query check crmentity deleted column #9

Open WMCyn opened 7 months ago

WMCyn commented 7 months ago

trying to import quotes using csv.

export a test quote from yeti to get formatting.

removed test quote and attempted to import from exported csv

system just gives error image

Nothing showing logs

Am I missing something?

WMCyn commented 7 months ago

Think I have found the issue, the "product name" in the quote matched both a deleted product and a newer product. after turning on more logging. it was attempting to match the "product name" with the one marked as deleted.

Any idea where in the code to make the import respect the "deleted" flag?

WMCyn commented 7 months ago

problem is in \app\record.php

public static function getCrmIdByLabel($moduleName, $label, $userId = false)
{
    $key = $moduleName . $label . '_' . $userId;
    if (\App\Cache::staticHas(__METHOD__, $key)) {
        return \App\Cache::staticGet(__METHOD__, $key);
    }
    $query = (new \App\Db\Query())
        ->select(['cl.crmid'])
        ->from('u_#__crmentity_label cl')
        ->innerJoin('vtiger_crmentity', 'cl.crmid = vtiger_crmentity.crmid')
        ->where(['vtiger_crmentity.setype' => $moduleName])
        ->andWhere(['cl.label' => $label]);
    if ($userId) {
        $query->andWhere(['like', 'vtiger_crmentity.users', ",$userId,"]);
    }
    $crmId = $query->scalar();
    \App\Cache::staticSave(__METHOD__, $key, $crmId);

    return $crmId;
}
WMCyn commented 7 months ago

notice no check for "deleted"

WMCyn commented 7 months ago

fixed version of the function

public static function getCrmIdByLabel($moduleName, $label, $userId = false)
{
    $key = $moduleName . $label . '_' . $userId;
    if (\App\Cache::staticHas(__METHOD__, $key)) {
        return \App\Cache::staticGet(__METHOD__, $key);
    }
    $query = (new \App\Db\Query())
        ->select(['cl.crmid'])
        ->from('u_#__crmentity_label cl')
        ->innerJoin('vtiger_crmentity', 'cl.crmid = vtiger_crmentity.crmid')
        ->where(['vtiger_crmentity.setype' => $moduleName])
        ->andWhere(['vtiger_crmentity.deleted' => 0])
        ->andWhere(['cl.label' => $label]);
    if ($userId) {
        $query->andWhere(['like', 'vtiger_crmentity.users', ",$userId,"]);
    }
    $crmId = $query->scalar();
    \App\Cache::staticSave(__METHOD__, $key, $crmId);

    return $crmId;
}