Merge branch 'tickets/r13985-telephone' into dev

This commit is contained in:
Michael RICOIS 2017-09-15 16:51:56 +02:00
commit 1ae6cde983
4 changed files with 72 additions and 34 deletions

View File

@ -33,20 +33,19 @@ $ids_customer = $models->execute_kw($db, $uid, $password,
// $ids_customer = array(7463);
// }
foreach ($ids_customer as $id_customer) {
// get info company
foreach ($ids_customer as $id_customer)
{
// Get info company
$record = $models->execute_kw($db, $uid, $password,
'res.partner', 'read', array($id_customer));
$other_addresses = $models->execute_kw($db, $uid, $password,
'res.partner', 'read', array($record['child_ids']));
$tags = $models->execute_kw($db, $uid, $password,
'res.partner.category', 'read', array($record['category_id']));
// get representant info
// Get representant info
$representant_email = '';
if (is_array($record) && isset($record['user_id']) && isset($record['user_id'][1])) {
$ids_representant = $models->execute_kw($db, $uid, $password,
@ -59,7 +58,7 @@ foreach ($ids_customer as $id_customer) {
if (is_array($ids_representant) && isset($ids_representant[0])) {
$representant = $models->execute_kw($db, $uid, $password,
'res.users', 'read', array($ids_representant[0]), array('fields'=>array('email')));
'res.users', 'read', array($ids_representant[0]), array('fields'=>array('email', 'phone')));
if (is_array($representant)) {
$representant_email = $representant['email'];
@ -67,7 +66,6 @@ foreach ($ids_customer as $id_customer) {
}
}
$group_to_add_to_customer = array();
foreach ($tags as $key => $tag) {
if (!Group::getByName($tag['name'], 1)) {
@ -88,7 +86,7 @@ foreach ($ids_customer as $id_customer) {
if(empty($record['email'])) {
continue;
}
// multiple email / explode
// multiple email / explode
$email = $record['email'];
if(!Validate::isEmail($email)) {
$emails = explode(';', $record['email']);
@ -136,10 +134,10 @@ foreach ($ids_customer as $id_customer) {
// $lastname = utf8_decode(substr((isset($record['display_name']) ? $record['display_name'] : $record['name'] ) , 0, 32));
// $firstname = utf8_decode(substr((isset($record['display_name']) ? $record['display_name'] : $record['name'] ) , 0, 32));
// }
//
//
if (!ErpTools::validateRecordCustomer($record)) {
ErpTools::logError($record, 'add_customer_validate');
ErpTools::logError($record, 'add_customer_validate');
echo 'INVALIDE';
p($record);
continue;
@ -158,6 +156,7 @@ foreach ($ids_customer as $id_customer) {
$customer->company = utf8_encode( (isset($record['display_name']) ? $record['display_name'] : $record['name'] ) );
$customer->id_erp = $record['id'];
$customer->representant = (isset($record['user_id'][1]) ? $record['user_id'][1] : '' );
$customer->representant_tel = str_replace(" ", "", $representant['phone']);
// If customer add with success create Address
if ($customer->add()) {

View File

@ -8,6 +8,14 @@ require '../config/config.inc.php';
require 'ErpTools.php';
require 'config.php';
// Var to exec from cli
$executeCli = false;
if (php_sapi_name() === 'cli') {
$executeCli = true;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_GET['token'] = ERP_SCRIPT_TOKEN;
}
if (empty($_GET['token']) || $_GET['token'] !== ERP_SCRIPT_TOKEN) {
die;
}
@ -29,8 +37,18 @@ $ids_customer_update = $models->execute_kw($db, $uid, $password,
)
);
foreach ($ids_customer_update as $id_customer) {
// get info company
$customerCpt = 0;
$customerTotal = count($ids_customer_update);
if ($customerTotal == 0) {
if ($executeCli) { echo "Nothing to update\n"; }
}
foreach ($ids_customer_update as $id_customer)
{
$customerCpt++;
if ($executeCli) { echo "$customerCpt/$customerTotal\n"; }
// Get info company
$record = $models->execute_kw($db, $uid, $password,
'res.partner', 'read', array($id_customer));
@ -43,6 +61,22 @@ foreach ($ids_customer_update as $id_customer) {
// echo '<pre>'; var_dump($record); echo '</pre>';
// die;
// Get representant info
if (is_array($record) && isset($record['user_id']) && isset($record['user_id'][1])) {
$ids_representant = $models->execute_kw($db, $uid, $password,
'res.users', 'search', array(
array(
array('name', '=', $record['user_id'][1])
)
)
);
if (is_array($ids_representant) && isset($ids_representant[0])) {
$representant = $models->execute_kw($db, $uid, $password,
'res.users', 'read', array($ids_representant[0]), array('fields' => array('email', 'phone')));
}
}
$group_to_add_to_customer = array();
foreach ($tags as $key => $tag) {
$group = '';
@ -55,7 +89,7 @@ foreach ($ids_customer_update as $id_customer) {
} else {
$group = Group::getByName($tag['name'], 1);
}
$group_to_add_to_customer[] = $group->id;
$group_to_add_to_customer[] = $group->id;
}
$group_to_add_to_customer[] = 3;
$group_to_add_to_customer = array_unique($group_to_add_to_customer);
@ -90,7 +124,7 @@ foreach ($ids_customer_update as $id_customer) {
// check if user exist
if (ErpTools::alreadyExists($record['id'])) {
if (!ErpTools::validateRecordCustomer($record)) {
if (!ErpTools::validateRecordCustomer($record)) {
ErpTools::logError($record, 'update_customer_validate');
continue;
}
@ -111,10 +145,11 @@ foreach ($ids_customer_update as $id_customer) {
$customer->email = $email;
$customer->company = utf8_encode($record['name']);
$customer->representant = $record['user_id'][1];
$customer->representant_tel = str_replace(" ", "", $representant['phone']);
$customer->update();
$customer->update();
$customer->updateGroup($group_to_add_to_customer);
$address = $customer->getAdressErp();
$address = $customer->getAdressErp();
// si aucune adresse pour le moment je la créé
if (!$address) {
@ -134,7 +169,7 @@ foreach ($ids_customer_update as $id_customer) {
$address->id_erp = $record['id'];
$address->add();
continue;
} else {
} else {
$address->address1 = utf8_encode($record['street']);
$address->address2 = utf8_encode($record['street2']);
$address->city = utf8_encode($record['city']);
@ -167,12 +202,12 @@ foreach ($ids_customer_update as $id_customer) {
$address->is_erp = 1;
$address->id_erp = $other_address['id'];
if (!empty($address->address1)) {
$address->save();
}
else {
error_log('erp_customer_update : customer id #'.$customer->id.' / erp id #'.$record['id'].' empty address');
}
if (!empty($address->address1)) {
$address->save();
}
else {
error_log('erp_customer_update : customer id #'.$customer->id.' / erp id #'.$record['id'].' empty address');
}
}
}
}

View File

@ -5,6 +5,7 @@ class Customer extends CustomerCore
public $id_erp;
public $representant;
public $representant_tel;
public static $definition = array(
'table' => 'customer',
@ -43,6 +44,7 @@ class Customer extends CustomerCore
// ADD ERP INPUT
'id_erp' => array('type' => self::TYPE_INT, 'validate' => 'isInt', 'copy_post' => false),
'representant' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'copy_post' => false),
'representant_tel' => array(),
),
);

View File

@ -61,17 +61,19 @@
{hook h="displayTop"}
{if $customer->representant}
<div id="infos-conseiller" class="md6">
<span class="header-title">{l s='My advisor'}</span>
<ul>
<li>
{$customer->representant}
</li>
<li>
{l s='01 48 15 01 45'}
</li>
</ul>
</div>
<div id="infos-conseiller" class="md6">
<span class="header-title">{l s='My advisor'}</span>
<ul>
<li>{$customer->representant}</li>
<li>
{if empty($customer->representant_tel)}
{l s='01 48 15 01 45'}
{else}
{chunk_split($customer->representant_tel, 2, ' ')}
{/if}
</li>
</ul>
</div>
{/if}
</div>
{/if}