← Back to team overview

clearcorp team mailing list archive

[Merge] lp:~dr.clearcorp/openerp-ccorp-addons/6.1-modules_magento_7 into lp:openerp-ccorp-addons

 

Diana Rodríguez Martínez has proposed merging lp:~dr.clearcorp/openerp-ccorp-addons/6.1-modules_magento_7 into lp:openerp-ccorp-addons.

Requested reviews:
  CLEARCORP drivers (clearcorp-drivers)

For more details, see:
https://code.launchpad.net/~dr.clearcorp/openerp-ccorp-addons/6.1-modules_magento_7/+merge/129032

[ADD] Add CheckCustomer module : Check if the customer exists in openerp
[ADD] Add ImportOrderToOpenerp: Import order to openerp
[ADD] Add ReviewProductOrder: Check if the product exists in openerp
All modules need a user, password and database from openerp and xmlrpc user and password, they must be exists in Magento store.
-- 
https://code.launchpad.net/~dr.clearcorp/openerp-ccorp-addons/6.1-modules_magento_7/+merge/129032
Your team CLEARCORP development team is subscribed to branch lp:openerp-ccorp-addons.
=== added directory 'modules_magento_7'
=== added directory 'modules_magento_7/CheckCustomer'
=== added directory 'modules_magento_7/CheckCustomer/CheckCustomerOpenerp'
=== added directory 'modules_magento_7/CheckCustomer/CheckCustomerOpenerp/controllers'
=== added file 'modules_magento_7/CheckCustomer/CheckCustomerOpenerp/controllers/AccountController.php'
--- modules_magento_7/CheckCustomer/CheckCustomerOpenerp/controllers/AccountController.php	1970-01-01 00:00:00 +0000
+++ modules_magento_7/CheckCustomer/CheckCustomerOpenerp/controllers/AccountController.php	2012-10-10 19:43:19 +0000
@@ -0,0 +1,261 @@
+<?php
+
+# Controllers are not autoloaded so you will have to do it manually:
+require_once 'Mage/Customer/controllers/AccountController.php';
+include_once('/etc/php5/apache2/xmlrpc.inc'); //http://phpxmlrpc.sourceforge.net
+include_once('/etc/php5/apache2/xmlrpcs.inc'); //http://phpxmlrpc.sourceforge.net
+
+class CheckCustomer_CheckCustomerOpenerp_AccountController extends Mage_Customer_AccountController
+{
+    public $user;
+    public $password;
+    public $database;
+    public $url;
+    
+    public $error_msg;
+    
+    
+    function setParameters($user, $password, $database, $url){
+        $this->user = $user;
+        $this->password = $password;
+        $this->database = $database;
+        $this->url = $url;
+    }
+    
+    function login(){
+        try{
+            $msg = new xmlrpcmsg('login');
+            $msg->addParam(new xmlrpcval($this->database, "string"));
+            $msg->addParam(new xmlrpcval($this->user, "string"));
+            $msg->addParam(new xmlrpcval($this->password, "string"));
+            $val = $this->_cache_request($this->url.'common',$msg);
+            
+            $this->userId = $val->scalarVal();
+
+            if($this->userId > 0) {
+                return $this->userId;
+            }
+            else{
+                Mage::log($this->error_msg,null,'info.log');
+                Mage::throwException('Conection failed with Openerp. Check error log');               
+                return -1;
+            }
+        }
+        catch(Exception $e){
+            Mage::log($this->error_msg,null,'info.log');
+            Mage::throwException('Conection failed with Openerp. Check error log');
+                   
+        }
+    }
+    
+    function search($relation,$domain){
+        $msg = new xmlrpcmsg('execute');
+        $msg->addParam(new xmlrpcval($this->database, "string"));
+        $msg->addParam(new xmlrpcval($this->userId   , "int"));
+        $msg->addParam(new xmlrpcval($this->password, "string"));
+        $msg->addParam(new xmlrpcval($relation      , "string"));
+        $msg->addParam(new xmlrpcval("search"      , "string"));
+        $msg->addParam(php_xmlrpc_encode($domain));
+        $val = $this->_cache_request($this->url.'object',$msg);
+        
+        return php_xmlrpc_decode($val);
+    }
+    
+    function read($relation,$ids,$fields=array(),$context=array()){
+        $msg = new xmlrpcmsg('execute');
+        $msg->addParam(new xmlrpcval($this->database, "string"));
+        $msg->addParam(new xmlrpcval($this->userId, "int"));
+        $msg->addParam(new xmlrpcval($this->password, "string"));
+        $msg->addParam(new xmlrpcval($relation, "string"));
+        $msg->addParam(new xmlrpcval("read", "string"));
+        $msg->addParam(php_xmlrpc_encode($ids));
+        $msg->addParam(php_xmlrpc_encode($fields));
+        $val = $this->_cache_request($this->url.'object',$msg);
+        
+        return php_xmlrpc_decode($val);
+    }   
+    
+    
+    function import_customer_to_openerp($relation,$customer_id,$context=array())
+    {
+        $msg = new xmlrpcmsg('execute');
+        $msg->addParam(new xmlrpcval($this->database, "string"));
+        $msg->addParam(new xmlrpcval($this->userId, "int"));
+        $msg->addParam(new xmlrpcval($this->password, "string"));
+        $msg->addParam(new xmlrpcval($relation, "string"));
+        $msg->addParam(new xmlrpcval("import_customers", "string"));
+        $msg->addParam(php_xmlrpc_encode($customer_id));
+        $val = $this->_cache_request($this->url.'object',$msg);        
+        
+    }
+    
+    //************************************************** Tools
+    function dump_array($arr){
+        foreach ($arr as $c) {
+            foreach($c as $property => $value)  { 
+                
+            }
+        }
+    } 
+    
+    function varDumpToString ($var){
+        ob_start();
+        var_dump($var);
+        $result = ob_get_clean();
+        return $result;
+    }
+        
+    function _cache_request($url,$msg){
+        $key =    md5($url.$msg->serialize());
+        $connection = new xmlrpc_client($url);
+        $resp = $connection->send($msg);
+        $this->error_msg = $resp->faultString();
+        $ret = $resp->value();
+        return $ret;         
+    }   
+    
+    public function createPostAction()
+    {
+        $session = $this->_getSession();
+        if ($session->isLoggedIn()) {
+            $this->_redirect('*/*/');
+            return;
+        }
+        $session->setEscapeMessages(true); // prevent XSS injection in user input
+        if ($this->getRequest()->isPost()) {
+            $errors = array();
+
+            if (!$customer = Mage::registry('current_customer')) {
+                $customer = Mage::getModel('customer/customer')->setId(null);
+            }
+
+            /* @var $customerForm Mage_Customer_Model_Form */
+            $customerForm = Mage::getModel('customer/form');
+            $customerForm->setFormCode('customer_account_create')
+                ->setEntity($customer);
+
+            $customerData = $customerForm->extractData($this->getRequest());
+
+            if ($this->getRequest()->getParam('is_subscribed', false)) {
+                $customer->setIsSubscribed(1);
+            }
+
+            /**
+             * Initialize customer group id
+             */
+            $customer->getGroupId();
+            $customer_id = $customer->getEntityId();
+            Mage::log('Customer id: '.$customer_id,null,'info.log');
+
+            if ($this->getRequest()->getPost('create_address')) {
+                /* @var $address Mage_Customer_Model_Address */
+                $address = Mage::getModel('customer/address');
+                /* @var $addressForm Mage_Customer_Model_Form */
+                $addressForm = Mage::getModel('customer/form');
+                $addressForm->setFormCode('customer_register_address')
+                    ->setEntity($address);
+
+                $addressData    = $addressForm->extractData($this->getRequest(), 'address', false);
+                $addressErrors  = $addressForm->validateData($addressData);
+                if ($addressErrors === true) {
+                    $address->setId(null)
+                        ->setIsDefaultBilling($this->getRequest()->getParam('default_billing', false))
+                        ->setIsDefaultShipping($this->getRequest()->getParam('default_shipping', false));
+                    $addressForm->compactData($addressData);
+                    $customer->addAddress($address);
+
+                    $addressErrors = $address->validate();
+                    if (is_array($addressErrors)) {
+                        $errors = array_merge($errors, $addressErrors);
+                    }
+                } else {
+                    $errors = array_merge($errors, $addressErrors);
+                }
+            }
+
+            try {
+                $customerErrors = $customerForm->validateData($customerData);
+                if ($customerErrors !== true) {
+                    $errors = array_merge($customerErrors, $errors);
+                } else {
+                    $customerForm->compactData($customerData);
+                    $customer->setPassword($this->getRequest()->getPost('password'));
+                    $customer->setConfirmation($this->getRequest()->getPost('confirmation'));
+                    $customerErrors = $customer->validate();
+                    if (is_array($customerErrors)) {
+                        $errors = array_merge($customerErrors, $errors);
+                    }
+                }
+
+                $validationResult = count($errors) == 0;
+
+                if (true === $validationResult) {
+                          
+                    $customer->save();                    
+                    
+                    /*******IMPORT CUSTOMER ******/
+                    $server = new CheckCustomer_CheckCustomerOpenerp_AccountController();
+                    $server->setParameters('admin', 'admin', 'test_electrotech', 'http://127.0.0.1:2001/xmlrpc/');
+                    $result = $server->login();
+         
+                    if ($result > -1){
+                       $customer_id = $customer->getEntityId();
+                       $server->import_customer_to_openerp('sneldev.magento',$customer_id);
+                    }
+                    else{
+                        Mage::log('ERROR',null,'info.log');
+                        Mage::throwException('Connection error with Openerp. Check the error log.');
+                    }
+                    /******************************/
+                    
+                    Mage::dispatchEvent('customer_register_success',
+                        array('account_controller' => $this, 'customer' => $customer)
+                    );
+
+                    if ($customer->isConfirmationRequired()) {
+                        $customer->sendNewAccountEmail(
+                            'confirmation',
+                            $session->getBeforeAuthUrl(),
+                            Mage::app()->getStore()->getId()
+                        );
+                        $session->addSuccess($this->__('Account confirmation is required. Please, check your email for the confirmation link. To resend the confirmation email please <a href="%s">click here</a>.', Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail())));
+                        $this->_redirectSuccess(Mage::getUrl('*/*/index', array('_secure'=>true)));
+                        return;
+                    } else {
+                        $session->setCustomerAsLoggedIn($customer);
+                        $url = $this->_welcomeCustomer($customer);
+                        $this->_redirectSuccess($url);
+                        return;
+                    }
+                } else {
+                    $session->setCustomerFormData($this->getRequest()->getPost());
+                    if (is_array($errors)) {
+                        foreach ($errors as $errorMessage) {
+                            $session->addError($errorMessage);
+                        }
+                    } else {
+                        $session->addError($this->__('Invalid customer data'));
+                    }
+                }
+            } catch (Mage_Core_Exception $e) {
+                $session->setCustomerFormData($this->getRequest()->getPost());
+                if ($e->getCode() === Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS) {
+                    $url = Mage::getUrl('customer/account/forgotpassword');
+                    $message = $this->__('There is already an account with this email address. If you are sure that it is your email address, <a href="%s">click here</a> to get your password and access your account.', $url);
+                    $session->setEscapeMessages(false);
+                } else {
+                    $message = $e->getMessage();
+                }
+                $session->addError($message);
+            } catch (Exception $e) {
+                $session->setCustomerFormData($this->getRequest()->getPost())
+                    ->addException($e, $this->__('Cannot save the customer.'));
+            }
+        }
+
+        $this->_redirectError(Mage::getUrl('*/*/create', array('_secure' => true))); 
+              
+    }
+}
+
+?>

=== added directory 'modules_magento_7/CheckCustomer/CheckCustomerOpenerp/etc'
=== added file 'modules_magento_7/CheckCustomer/CheckCustomerOpenerp/etc/config.xml'
--- modules_magento_7/CheckCustomer/CheckCustomerOpenerp/etc/config.xml	1970-01-01 00:00:00 +0000
+++ modules_magento_7/CheckCustomer/CheckCustomerOpenerp/etc/config.xml	2012-10-10 19:43:19 +0000
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<config>
+    <modules>
+        <CheckCustomer_CheckCustomerOpenerp>
+            <version>0.0.1</version>
+        </CheckCustomer_CheckCustomerOpenerp>
+    </modules>    
+    <frontend>
+        <routers>
+            <checkcustomer_checkcustomeropenerp>
+                <use>standard</use>
+                    <args>
+                        <module>CheckCustomer_CheckCustomerOpenerp</module>
+                        <frontName>customer</frontName>
+                    </args>
+            </checkcustomer_checkcustomeropenerp>
+        </routers>
+    </frontend>
+    <global>
+        <rewrite>
+            <checkcustomer_checkcustomeropenerp_account>
+                <from><![CDATA[#^/account/#]]></from>
+                <to>/customer/account/</to>
+            </checkcustomer_checkcustomeropenerp_account>
+        </rewrite>
+    </global>
+</config>

=== added directory 'modules_magento_7/ImportOrderToOpenerp'
=== added directory 'modules_magento_7/ImportOrderToOpenerp/ImportOrder'
=== added directory 'modules_magento_7/ImportOrderToOpenerp/ImportOrder/Block'
=== added directory 'modules_magento_7/ImportOrderToOpenerp/ImportOrder/Helper'
=== added directory 'modules_magento_7/ImportOrderToOpenerp/ImportOrder/Model'
=== added file 'modules_magento_7/ImportOrderToOpenerp/ImportOrder/Model/Observer.php'
--- modules_magento_7/ImportOrderToOpenerp/ImportOrder/Model/Observer.php	1970-01-01 00:00:00 +0000
+++ modules_magento_7/ImportOrderToOpenerp/ImportOrder/Model/Observer.php	2012-10-10 19:43:19 +0000
@@ -0,0 +1,149 @@
+<?php
+
+include_once('/etc/php5/apache2/xmlrpc.inc'); //http://phpxmlrpc.sourceforge.net
+include_once('/etc/php5/apache2/xmlrpcs.inc'); //http://phpxmlrpc.sourceforge.net
+
+class ImportOrderToOpenerp_ImportOrder_Model_Observer
+{
+    /**Magento passes a Varien_Event_Observer object as
+     * the first parameter of dispatched events.
+     */
+
+    public $user;
+    public $password;
+    public $database;
+    public $url;
+    
+    public $error_msg;
+    
+    function __construct($user, $password, $database, $url){
+        $this->user = $user;
+        $this->password = $password;
+        $this->database = $database;
+        $this->url = $url;
+    }
+   
+    function login(){
+        try{
+            $msg = new xmlrpcmsg('login');
+            $msg->addParam(new xmlrpcval($this->database, "string"));
+            $msg->addParam(new xmlrpcval($this->user, "string"));
+            $msg->addParam(new xmlrpcval($this->password, "string"));
+            $val = $this->_cache_request($this->url.'common',$msg);
+            
+            $this->userId = $val->scalarVal();
+
+            if($this->userId > 0) {
+                //Mage::getSingleton('checkout/session')->addSuccess("Conection succesuful");
+                return $this->userId;
+            }
+            else{
+                //Mage::getSingleton('checkout/session')->addError("Conection failed with Openerp. Check error log"); 
+                Mage::log($this->error_msg,null,'sales_order_save_after.log');
+                Mage::throwException('Conection failed with Openerp. Check error log');               
+                //die();
+                return -1;
+            }
+        }
+        catch(Exception $e){
+            Mage::log($this->error_msg,null,'sales_order_save_after.log');
+            Mage::throwException('Conection failed with Openerp. Check error log');
+                   
+        }
+    }
+    
+    function search($relation,$domain){
+        $msg = new xmlrpcmsg('execute');
+        $msg->addParam(new xmlrpcval($this->database, "string"));
+        $msg->addParam(new xmlrpcval($this->userId   , "int"));
+        $msg->addParam(new xmlrpcval($this->password, "string"));
+        $msg->addParam(new xmlrpcval($relation      , "string"));
+        $msg->addParam(new xmlrpcval("search"      , "string"));
+        $msg->addParam(php_xmlrpc_encode($domain));
+        $val = $this->_cache_request($this->url.'object',$msg);
+        
+        return php_xmlrpc_decode($val);
+    }
+    
+    function read($relation,$ids,$fields=array(),$context=array()){
+        $msg = new xmlrpcmsg('execute');
+        $msg->addParam(new xmlrpcval($this->database, "string"));
+        $msg->addParam(new xmlrpcval($this->userId, "int"));
+        $msg->addParam(new xmlrpcval($this->password, "string"));
+        $msg->addParam(new xmlrpcval($relation, "string"));
+        $msg->addParam(new xmlrpcval("read", "string"));
+        $msg->addParam(php_xmlrpc_encode($ids));
+        $msg->addParam(php_xmlrpc_encode($fields));
+        $val = $this->_cache_request($this->url.'object',$msg);
+        
+        return php_xmlrpc_decode($val);
+    }   
+    
+    
+    function import_order_to_magento_openerp($relation,$entity_id,$increment_id,$context=array())
+    {
+        $msg = new xmlrpcmsg('execute');
+        $msg->addParam(new xmlrpcval($this->database, "string"));
+        $msg->addParam(new xmlrpcval($this->userId, "int"));
+        $msg->addParam(new xmlrpcval($this->password, "string"));
+        $msg->addParam(new xmlrpcval($relation, "string"));
+        $msg->addParam(new xmlrpcval("import_orders", "string"));
+        $msg->addParam(php_xmlrpc_encode($entity_id));
+        $msg->addParam(php_xmlrpc_encode($increment_id));
+        $val = $this->_cache_request($this->url.'object',$msg);        
+        //return php_xmlrpc_decode($val);
+        
+    }
+    
+    //************************************************** Tools
+    function dump_array($arr){
+        foreach ($arr as $c) {
+            foreach($c as $property => $value)  { 
+                
+            }
+        }
+    } 
+    
+    function varDumpToString ($var){
+        ob_start();
+        var_dump($var);
+        $result = ob_get_clean();
+        return $result;
+    }
+        
+    function _cache_request($url,$msg){
+        $key =    md5($url.$msg->serialize());
+        $connection = new xmlrpc_client($url);
+        $resp = $connection->send($msg);
+        $this->error_msg = $resp->faultString();
+        $ret = $resp->value();
+        return $ret;         
+    }
+
+    public function main_import_openerp(Varien_Event_Observer $observer){
+
+        /**** LOGIN *****/
+        $server = new ImportOrderToOpenerp_ImportOrder_Model_Observer('admin', 'admin', 'test_electrotech', 'http://127.0.0.1:2001/xmlrpc/');
+        $result = $server->login();
+         
+        if ($result > -1){
+            $event = $observer->getEvent();
+            $order = $event->getOrder();
+            
+            $entity_id = $order->getData('entity_id');
+            $increment_id = $order->getData('increment_id');
+            
+            $server->import_order_to_magento_openerp('sneldev.magento',$entity_id,$increment_id); 
+                       
+        }
+        else{
+            Mage::log('ERROR',null,'sales_order_save_after.log');
+            Mage::throwException('Error !!! Check the error log.');
+        }
+        
+    }
+
+}
+
+
+?>

=== added directory 'modules_magento_7/ImportOrderToOpenerp/ImportOrder/controllers'
=== added file 'modules_magento_7/ImportOrderToOpenerp/ImportOrder/controllers/IndexController.php'
--- modules_magento_7/ImportOrderToOpenerp/ImportOrder/controllers/IndexController.php	1970-01-01 00:00:00 +0000
+++ modules_magento_7/ImportOrderToOpenerp/ImportOrder/controllers/IndexController.php	2012-10-10 19:43:19 +0000
@@ -0,0 +1,10 @@
+<?php
+
+class ReviewProductOrder_CheckoutProduct_IndexController extends Mage_Core_Controller_Front_Action { 
+
+    public function indexAction () { 
+        echo 'Hello Index!' ; 
+    } 
+}
+
+?>

=== added directory 'modules_magento_7/ImportOrderToOpenerp/ImportOrder/etc'
=== added file 'modules_magento_7/ImportOrderToOpenerp/ImportOrder/etc/config.xml'
--- modules_magento_7/ImportOrderToOpenerp/ImportOrder/etc/config.xml	1970-01-01 00:00:00 +0000
+++ modules_magento_7/ImportOrderToOpenerp/ImportOrder/etc/config.xml	2012-10-10 19:43:19 +0000
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<config>
+    <!-- The module's node contains basic information about each Magento module -->
+    <modules>
+        <!-- This must exactly match the namespace and module's folder names, with directory separators replaced by underscores -->
+        <ImportOrderToOpenerp_ImportOrder>
+            <!-- The version of our module, starting at 0.0.1 -->
+            <version>0.0.1</version>
+        </ImportOrderToOpenerp_ImportOrder>
+    </modules>
+    <!-- Configure our module's behavior in the global scope -->
+    <global>
+        <!-- Defining models -->
+        <models>
+            <!-- Unique identifier in the model's node. By convention, we put the module's name in lowercase. -->
+            <importordertoopenerp_importorder>
+                <!-- The path to our models directory, with directory separators replaced by underscores -->
+                <class>ImportOrderToOpenerp_ImportOrder_Model</class>
+            </importordertoopenerp_importorder>
+        </models>
+
+        <!-- Defining an event observer -->
+        <events>
+            <!-- The code of the event we want to observe -->
+            <checkout_type_onepage_save_order_after>
+                <!-- Defining an observer for this event -->
+                <observers>
+                    <!-- Unique identifier within the sales_order_save_after node. By convention, we write the module's name in lowercase. -->
+                    <importordertoopenerp_importorder>
+                        <!-- The model to be instantiated -->
+                        <class>importordertoopenerp_importorder/observer</class>
+                        <!-- The method of the class to be called -->
+                        <method>main_import_openerp</method>
+                        <!-- The type of class to instantiate -->
+                        <type>singleton</type>
+                    </importordertoopenerp_importorder>
+                </observers>
+            </checkout_type_onepage_save_order_after>
+        </events>        
+    </global>
+</config>

=== added directory 'modules_magento_7/ReviewProductOrder'
=== added directory 'modules_magento_7/ReviewProductOrder/CheckoutProduct'
=== added directory 'modules_magento_7/ReviewProductOrder/CheckoutProduct/Model'
=== added file 'modules_magento_7/ReviewProductOrder/CheckoutProduct/Model/Observer.php'
--- modules_magento_7/ReviewProductOrder/CheckoutProduct/Model/Observer.php	1970-01-01 00:00:00 +0000
+++ modules_magento_7/ReviewProductOrder/CheckoutProduct/Model/Observer.php	2012-10-10 19:43:19 +0000
@@ -0,0 +1,161 @@
+<?php
+
+include_once('/etc/php5/apache2/xmlrpc.inc'); //http://phpxmlrpc.sourceforge.net
+include_once('/etc/php5/apache2/xmlrpcs.inc'); //http://phpxmlrpc.sourceforge.net
+
+class ReviewProductOrder_CheckoutProduct_Model_Observer
+{
+    /**Magento passes a Varien_Event_Observer object as
+     * the first parameter of dispatched events.
+     */
+
+    public $user;
+    public $password;
+    public $database;
+    public $url;
+    
+    public $error_msg;
+    
+    function __construct($user, $password, $database, $url){
+        $this->user = $user;
+        $this->password = $password;
+        $this->database = $database;
+        $this->url = $url;
+    }
+   
+    function login(){
+        try{
+            $msg = new xmlrpcmsg('login');
+            $msg->addParam(new xmlrpcval($this->database, "string"));
+            $msg->addParam(new xmlrpcval($this->user, "string"));
+            $msg->addParam(new xmlrpcval($this->password, "string"));
+            $val = $this->_cache_request($this->url.'common',$msg);
+            
+            $this->userId = $val->scalarVal();
+
+            if($this->userId > 0) {
+                //Mage::getSingleton('checkout/session')->addSuccess("Conection succesuful");
+                return $this->userId;
+            }
+            else{
+                //Mage::getSingleton('checkout/session')->addError("Conection failed with Openerp. Check error log"); 
+                Mage::log($this->error_msg,null,'sales_order_save_after.log');
+                Mage::throwException('Conection failed with Openerp. Check error log');               
+                //die();
+                return -1;
+            }
+        }
+        catch(Exception $e){
+            Mage::log($this->error_msg,null,'sales_order_save_after.log');
+            Mage::throwException('Conection failed with Openerp. Check error log');
+                   
+        }
+    }
+    
+    function search($relation,$domain){
+        $msg = new xmlrpcmsg('execute');
+        $msg->addParam(new xmlrpcval($this->database, "string"));
+        $msg->addParam(new xmlrpcval($this->userId   , "int"));
+        $msg->addParam(new xmlrpcval($this->password, "string"));
+        $msg->addParam(new xmlrpcval($relation      , "string"));
+        $msg->addParam(new xmlrpcval("search"      , "string"));
+        $msg->addParam(php_xmlrpc_encode($domain));
+        $val = $this->_cache_request($this->url.'object',$msg);
+        
+        return php_xmlrpc_decode($val);
+    }
+    
+    function read($relation,$ids,$fields=array(),$context=array()){
+        $msg = new xmlrpcmsg('execute');
+        $msg->addParam(new xmlrpcval($this->database, "string"));
+        $msg->addParam(new xmlrpcval($this->userId, "int"));
+        $msg->addParam(new xmlrpcval($this->password, "string"));
+        $msg->addParam(new xmlrpcval($relation, "string"));
+        $msg->addParam(new xmlrpcval("read", "string"));
+        $msg->addParam(php_xmlrpc_encode($ids));
+        $msg->addParam(php_xmlrpc_encode($fields));
+        $val = $this->_cache_request($this->url.'object',$msg);
+        
+        return php_xmlrpc_decode($val);
+    }   
+    
+    //************************************************** Tools
+    function dump_array($arr){
+        foreach ($arr as $c) {
+            foreach($c as $property => $value)  { 
+                
+            }
+        }
+    } 
+        
+    function _cache_request($url,$msg){
+        $key =    md5($url.$msg->serialize());
+        $connection = new xmlrpc_client($url);
+        $resp = $connection->send($msg);
+        $this->error_msg = $resp->faultString();
+        $ret = $resp->value();
+        return $ret;         
+    }
+    
+    public function main(Varien_Event_Observer $observer){
+        $flat = false;
+        $message = '';
+        
+        /**** LOGIN *****/
+        $server = new ReviewProductOrder_CheckoutProduct_Model_Observer('admin', 'admin', 'test_electrotech', 'http://127.0.0.1:2001/xmlrpc/');
+        $result = $server->login();
+        
+        if ($result > -1){
+            /****GET ORDER AND ORDER ITEMS **/
+            $order = $observer->getEvent()->getOrder();
+            $total_items = $order->getTotalItemCount();
+        
+            //returns an array of order items
+            $items = $order->getAllItems();
+
+            if ($items) {
+                foreach ($items as $item) {
+                    $item_info = 'Item Name:'.$item['name'].' - Sku: '.$item['sku'].' - Quantity ordered: '.$item['qty_ordered'];
+                    
+                    /*****search in openerp ****/
+                    $ids_products = $server->search('product.product',array(array('default_code','=',$item['sku'])));
+                    $products = $server->read('product.product',$ids_products,array('qty_available'));             
+                    
+                    foreach ($products as $p) {
+                        foreach($p as $property => $value){ 
+                            if ($property == 'qty_available') {
+                                if ($value == 0){
+                                    $flat = true;
+                                    $message = $item_info.' There is insufficient stock in OpenERP to proceed with this order';
+                                    break;
+                                } 
+                            }
+                            
+                        }
+                    }
+                    
+                    /*** SI LOS PRODUCTOS ESTAN CORRECTOS, SE VERIFICA EL CRÉDITO DEL CLIENTE PARA REALIZAR SU COMPRA ****/
+                    if ($flat){
+                        Mage::throwException($message);
+                    }  
+                    
+                    else{
+                        Mage::log('No existe error en los productos',null,'sales_order_save_after.log');
+                    }
+                    
+                }
+            }
+            else{
+                Mage::log('NO CONECTO',null,'sales_order_save_after.log');
+                Mage::throwException('No se pueden revisar los productos, error !!!');
+            }
+            
+        }
+        else{
+            Mage::throwException('Conection failed with Openerp. Check error log');
+        }
+    }
+}
+
+
+?>

=== added directory 'modules_magento_7/ReviewProductOrder/CheckoutProduct/etc'
=== added file 'modules_magento_7/ReviewProductOrder/CheckoutProduct/etc/config.xml'
--- modules_magento_7/ReviewProductOrder/CheckoutProduct/etc/config.xml	1970-01-01 00:00:00 +0000
+++ modules_magento_7/ReviewProductOrder/CheckoutProduct/etc/config.xml	2012-10-10 19:43:19 +0000
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<config>
+    <!-- The module's node contains basic information about each Magento module -->
+    <modules>
+        <!-- This must exactly match the namespace and module's folder names, with directory separators replaced by underscores -->
+        <ReviewProductOrder_CheckoutProduct>
+            <!-- The version of our module, starting at 0.0.1 -->
+            <version>0.0.1</version>
+        </ReviewProductOrder_CheckoutProduct>
+    </modules>
+    <!-- Configure our module's behavior in the global scope -->
+    <global>
+        <!-- Defining models -->
+        <models>
+            <!-- Unique identifier in the model's node. By convention, we put the module's name in lowercase. -->
+            <reviewproductorder_checkoutproduct>
+                <!-- The path to our models directory, with directory separators replaced by underscores -->
+                <class>ReviewProductOrder_CheckoutProduct_Model</class>
+            </reviewproductorder_checkoutproduct>
+        </models>
+        <!-- Defining an event observer -->
+        <events>
+            <!-- The code of the event we want to observe -->
+            <sales_order_place_before>
+                <!-- Defining an observer for this event -->
+                <observers>
+                    <!-- Unique identifier within the sales_order_save_after node. By convention, we write the module's name in lowercase. -->
+                    <reviewproductorder_checkoutproduct>
+                        <!-- The model to be instantiated -->
+                        <class>reviewproductorder_checkoutproduct/observer</class>
+                        <!-- The method of the class to be called -->
+                        <method>main</method>
+                        <!-- The type of class to instantiate -->
+                        <type>singleton</type>
+                    </reviewproductorder_checkoutproduct>
+                </observers>
+            </sales_order_place_before>
+        </events>        
+    </global>
+</config>


Follow ups