Merge branch 'master' of gitlab.antadis.net:dev-antadis/roykin into ticket/r12695-allinonereward

This commit is contained in:
Rodney Figaro 2017-04-19 15:45:56 +02:00
commit ecb330844f
2 changed files with 40 additions and 4 deletions

View File

@ -42,6 +42,8 @@ class ErpTools
161 => 158, // Nouvelle Calédonie
248 => 144, // Mayotte
189 => 176, // Réunion
95 => 22, // Hong-Kong
49 => 5 // China
);
if (!empty($assoc_country[$id_country_odoo])) {

View File

@ -29,19 +29,45 @@ $ids_customer = $models->execute_kw($db, $uid, $password,
)
);
// $ids_customer = array(7185);
// if (in_array($_SERVER['REMOTE_ADDR'], array('88.163.22.99'))) {
// $ids_customer = array(7463);
// }
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
$representant_email = '';
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')));
if (is_array($representant)) {
$representant_email = $representant['email'];
}
}
}
$group_to_add_to_customer = array();
foreach ($tags as $key => $tag) {
if (!Group::getByName($tag['name'], 1)) {
@ -58,7 +84,6 @@ foreach ($ids_customer as $id_customer) {
$group_to_add_to_customer[] = 3;
$group_to_add_to_customer = array_unique($group_to_add_to_customer);
// check mail validity
if(empty($record['email'])) {
continue;
@ -73,6 +98,8 @@ foreach ($ids_customer as $id_customer) {
continue;
}
}
// ppp($id_customer.' loop');
// var_dump(ErpTools::alreadyExists($record['id']));
// var_dump(Customer::getCustomersByEmail($email));
@ -107,6 +134,7 @@ foreach ($ids_customer as $id_customer) {
if (!ErpTools::validateRecordCustomer($record)) {
ErpTools::logError($record, 'add_customer_validate');
echo 'INVALIDE';
p($record);
continue;
}
@ -144,6 +172,11 @@ foreach ($ids_customer as $id_customer) {
$address->id_erp = $record['id'];
$address->add();
$target_emails = array($customer->email, 'christophe@roykin.fr');
if (!empty($representant_email) && Validate::isEmail($representant_email)) {
$target_emails[] = $representant_email;
}
$mail = Mail::Send(
1,
'account',
@ -154,10 +187,10 @@ foreach ($ids_customer as $id_customer) {
'{email}' => $customer->email,
'{passwd}' => $password_generate
),
array($customer->email, 'christophe@roykin.fr'),
$target_emails,
$customer->firstname.' '.$customer->lastname
);
var_dump("mail sent : ".$mail.' '.$customer->email);
foreach ($other_addresses as $key => $other_address) {
//$other_address['phone'] = ($other_address['phone']) ? $other_address['phone'] : $record['phone'];
if (isset($other_address['phone']) && !empty($other_address['phone'])) {
@ -187,6 +220,7 @@ foreach ($ids_customer as $id_customer) {
}
}
} catch (Exception $exception) {
$msg = $exception->getMessage();
ErpTools::logError($record, 'add_customer');