modify('-100 day'); // Get All Customers with email and is customer to create if no exist or update info $models = ripcord::client("$url/xmlrpc/2/object"); $ids_company = $models->execute_kw($db, $uid, $password, 'res.partner', 'search', array( array( array('email', '!=', ''), array('is_company', '=', true), ) ) ); $final = array(); $companys = $models->execute_kw($db, $uid, $password, 'res.partner', 'read', array($ids_company)); foreach ($companys as $key => $company) { $final[] = array( 'company_id_erp' => $company['id'], 'addr' => $company ); $addrs = $models->execute_kw($db, $uid, $password, 'res.partner', 'read', array($company['child_ids'])); foreach ($addrs as $key => $addr) { $final[] = array( 'company_id_erp' => $company['id'], 'addr' => $addr ); } } foreach ($final as $key => $item) { $customer = Customer::getCustomerIdByIdErp($item['company_id_erp']); if (!$customer || empty($customer->id)) { continue; } $address = Address::getByErp($item['addr']['id']); $phone = $item['addr']['phone']; if (empty($phone)) { $phone = '0123456789'; } if (empty($item['addr']['country_id']) || empty($item['addr']['street']) || empty($item['addr']['city']) || empty($item['addr']['name']) || empty($item['addr']['zip'])) { ErpTools::logError($item['addr'], 'erp_update_address | odoo address is not valid'); continue; } $address->id_customer = $customer->id; $address->alias = utf8_encode($item['addr']['name']); $address->lastname = utf8_encode($customer->lastname); $address->firstname = utf8_encode($customer->firstname); $address->address1 = utf8_encode($item['addr']['street']); $address->address2 = utf8_encode($item['addr']['street2']); $address->city = utf8_encode($item['addr']['city']); $address->postcode = $item['addr']['zip']; $address->company = utf8_encode($item['addr']['display_name']); $address->phone = (int)str_replace(' ', '', $phone); $address->id_country = ErpTools::getCountryIdForPresta($item['addr']['country_id'][0]); $address->is_erp = 1; $address->id_erp = $item['addr']['id']; $address->save(); }