Commit c6b72911a4406834518461dccac7c172b0420db5

Authored by Yarik
1 parent 7c514320

Odoo completed

backend/config/main.php
... ... @@ -51,6 +51,7 @@
51 51 'viewPath' => '@artbox/webcomment/views/manage',
52 52 ],
53 53 'export' => 'artbox\catalog\controllers\ExportController',
  54 + 'odoo' => 'artbox\odoo\controllers\OdooController',
54 55 ],
55 56 'components' => [
56 57 'assetManager' => [
... ...
common/config/bootstrap.php
... ... @@ -18,4 +18,7 @@
18 18 }
19 19 if (!Yii::getAlias('@artbox/webcomment', false)) {
20 20 Yii::setAlias('@artbox/webcomment', dirname(dirname(__DIR__)) . '/artweb/artbox-webcomment');
  21 + }
  22 + if (!Yii::getAlias('@artbox/odoo', false)) {
  23 + Yii::setAlias('@artbox/odoo', dirname(dirname(__DIR__)) . '/artweb/artbox-odoo');
21 24 }
22 25 \ No newline at end of file
... ...
common/config/main.php
... ... @@ -2,6 +2,7 @@
2 2 use artbox\catalog\helpers\FilterHelper;
3 3 use artbox\core\components\AliasCache;
4 4 use artbox\core\components\SeoComponent;
  5 + use artbox\odoo\components\OdooMapper;
5 6  
6 7 return [
7 8 'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
... ... @@ -56,6 +57,10 @@
56 57 'class' => 'yii\i18n\PhpMessageSource',
57 58 'basePath' => '@eauth/messages',
58 59 ],
  60 + 'odoo' => [
  61 + 'class' => 'yii\i18n\PhpMessageSource',
  62 + 'basePath' => '@artbox/odoo/messages',
  63 + ],
59 64 ],
60 65 ],
61 66 'filedb' => [
... ... @@ -83,5 +88,90 @@
83 88 'aliasCache' => [
84 89 'class' => AliasCache::className(),
85 90 ],
  91 + 'odooMapper' => [
  92 + 'class' => OdooMapper::className(),
  93 + 'map' => [
  94 + 'id' => 'remote_id',
  95 + 'active' => 'status',
  96 + 'create_date' => [
  97 + 'attribute' => 'created_at',
  98 + 'artbox' => function ($field) {
  99 + return strtotime($field);
  100 + },
  101 + 'odoo' => function ($field) {
  102 + return date('Y-m-d H:i:s', $field);
  103 + },
  104 + ],
  105 + '__last_update' => [
  106 + 'attribute' => 'updated_at',
  107 + 'artbox' => function ($field) {
  108 + return strtotime($field);
  109 + },
  110 + 'odoo' => function ($field) {
  111 + return date('Y-m-d H:i:s', $field);
  112 + },
  113 + ],
  114 + 'name' => 'title',
  115 + 'default_code' => 'sku',
  116 + 'list_price' => 'price',
  117 + 'product_id' => [
  118 + 'attribute' => 'variant_id',
  119 + 'artbox' => function ($field) {
  120 + return $field[ 0 ];
  121 + },
  122 + 'odoo' => function ($field) {
  123 + return [ $field ];
  124 + },
  125 + ],
  126 + 'price_unit' => 'price',
  127 + 'product_uom_qty' => 'count',
  128 + 'categ_id' => 'category',
  129 + 'contact_address' => [
  130 + 'attribute' => 'address',
  131 + 'artbox' => function ($field) {
  132 + return strval($field);
  133 + },
  134 + 'odoo' => function ($field) {
  135 + return boolval($field);
  136 + },
  137 + ],
  138 + 'phone' => [
  139 + 'attribute' => 'phone',
  140 + 'artbox' => function ($field) {
  141 + return strval($field);
  142 + },
  143 + 'odoo' => function ($field) {
  144 + return boolval($field);
  145 + },
  146 + ],
  147 + 'email' => [
  148 + 'attribute' => 'email',
  149 + 'artbox' => function ($field) {
  150 + return strval($field);
  151 + },
  152 + 'odoo' => function ($field) {
  153 + return boolval($field);
  154 + },
  155 + ],
  156 + 'city' => [
  157 + 'attribute' => 'city',
  158 + 'artbox' => function ($field) {
  159 + return strval($field);
  160 + },
  161 + 'odoo' => function ($field) {
  162 + return boolval($field);
  163 + },
  164 + ],
  165 + 'comment' => [
  166 + 'attribute' => 'comment',
  167 + 'artbox' => function ($field) {
  168 + return strval($field);
  169 + },
  170 + 'odoo' => function ($field) {
  171 + return boolval($field);
  172 + },
  173 + ],
  174 + ],
  175 + ],
86 176 ],
87 177 ];
... ...
composer.json
... ... @@ -38,7 +38,8 @@
38 38 "kartik-v/yii2-widget-datepicker": "@dev",
39 39 "nodge/yii2-eauth": "~2.0",
40 40 "skeeks/yii2-assets-auto-compress": "*",
41   - "zyx/zyx-phpmailer": "@stable"
  41 + "zyx/zyx-phpmailer": "@stable",
  42 + "darkaonline/ripcord": "*"
42 43 },
43 44 "require-dev": {
44 45 "yiisoft/yii2-debug": "~2.0.0",
... ... @@ -79,7 +80,8 @@
79 80 "artbox\\core\\": "artweb/artbox-core/",
80 81 "artbox\\catalog\\": "artweb/artbox-catalog/",
81 82 "artbox\\order\\": "artweb/artbox-order/",
82   - "artbox\\weblog\\": "artweb/artbox-weblog/"
  83 + "artbox\\weblog\\": "artweb/artbox-weblog/",
  84 + "artbox\\odoo\\": "artweb/artbox-odoo/"
83 85 }
84 86 }
85 87 }
... ...
composer.lock
... ... @@ -4,7 +4,7 @@
4 4 "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
5 5 "This file is @generated automatically"
6 6 ],
7   - "content-hash": "f5d818fe2726a09810a6587656444937",
  7 + "content-hash": "a27711284fb6ee8108327ae9dff29060",
8 8 "packages": [
9 9 {
10 10 "name": "2amigos/yii2-tinymce-widget",
... ... @@ -605,6 +605,47 @@
605 605 "time": "2017-02-14T19:40:03+00:00"
606 606 },
607 607 {
  608 + "name": "darkaonline/ripcord",
  609 + "version": "v0.1.4",
  610 + "source": {
  611 + "type": "git",
  612 + "url": "https://github.com/DarkaOnLine/Ripcord.git",
  613 + "reference": "b485483a931d68f0935933ad563e3a164e873df3"
  614 + },
  615 + "dist": {
  616 + "type": "zip",
  617 + "url": "https://api.github.com/repos/DarkaOnLine/Ripcord/zipball/b485483a931d68f0935933ad563e3a164e873df3",
  618 + "reference": "b485483a931d68f0935933ad563e3a164e873df3",
  619 + "shasum": ""
  620 + },
  621 + "require": {
  622 + "php": ">=5.4"
  623 + },
  624 + "type": "library",
  625 + "autoload": {
  626 + "psr-4": {
  627 + "Ripcord\\": "src/Ripcord"
  628 + }
  629 + },
  630 + "notification-url": "https://packagist.org/downloads/",
  631 + "license": [
  632 + "MIT"
  633 + ],
  634 + "authors": [
  635 + {
  636 + "name": "Darius Matulionis",
  637 + "email": "darius@matulionis.lt"
  638 + }
  639 + ],
  640 + "description": "RPC client and server around PHP's xmlrpc library",
  641 + "keywords": [
  642 + "rpc",
  643 + "xml",
  644 + "xmlrpc"
  645 + ],
  646 + "time": "2017-05-24T05:49:36+00:00"
  647 + },
  648 + {
608 649 "name": "ezyang/htmlpurifier",
609 650 "version": "v4.9.3",
610 651 "source": {
... ...
console/controllers/TestController.php 0 โ†’ 100644
  1 +<?php
  2 + /**
  3 + * Created by PhpStorm.
  4 + * User: yarik
  5 + * Date: 12.06.17
  6 + * Time: 14:07
  7 + */
  8 +
  9 + namespace console\controllers;
  10 +
  11 + use artbox\catalog\models\Product;
  12 + use artbox\odoo\components\Builder;
  13 + use artbox\odoo\components\OdooHelper;
  14 + use artbox\odoo\components\Query;
  15 + use artbox\odoo\models\OdooToOrder;
  16 + use artbox\odoo\models\OdooToProduct;
  17 + use artbox\order\models\Order;
  18 + use Ripcord\Ripcord;
  19 + use yii\console\Controller;
  20 +
  21 + class TestController extends Controller
  22 + {
  23 + public function actionIndex()
  24 + {
  25 + $url = 'https://demo.cloudbank.biz';
  26 + $db = 'odoo';
  27 + $username = 'admin';
  28 + $password = 'htcge,kbrf';
  29 + $info = Ripcord::client("$url/xmlrpc/2/common");
  30 + $uid = call_user_func_array(
  31 + [
  32 + $info,
  33 + 'authenticate',
  34 + ],
  35 + [
  36 + $db,
  37 + $username,
  38 + $password,
  39 + [],
  40 + ]
  41 + );
  42 + $modelsQuery = Ripcord::client("$url/xmlrpc/2/object");
  43 + $models = call_user_func_array(
  44 + [
  45 + $modelsQuery,
  46 + 'execute_kw',
  47 + ],
  48 + [
  49 + $db,
  50 + $uid,
  51 + $password,
  52 + 'product.template',
  53 + 'search_read',
  54 + [ [] ],
  55 + [ 'fields' => [ 'name' ] ],
  56 + ]
  57 + );
  58 + var_dump($models);
  59 + }
  60 +
  61 + public function actionT()
  62 + {
  63 + /**
  64 + * @var \artbox\odoo\components\Connection $odoo
  65 + */
  66 + $odoo = \Yii::$app->get('odoo');
  67 +
  68 + /**
  69 + * @var \artbox\odoo\components\Connection $connection
  70 + */
  71 + $result = $odoo->createCommand(
  72 + 'product.template',
  73 + 'search_read',
  74 + [
  75 + [
  76 + [
  77 + 'list_price',
  78 + '=',
  79 + 10,
  80 + ],
  81 + ],
  82 + ],
  83 + [
  84 + 'fields' => [
  85 + 'name',
  86 + 'list_price',
  87 + ],
  88 + ]
  89 + )
  90 + ->execute();
  91 + var_dump($result);
  92 + }
  93 +
  94 + public function actionK()
  95 + {
  96 + /**
  97 + * @var \artbox\odoo\components\Connection $odoo
  98 + */
  99 + $odoo = \Yii::$app->get('odoo');
  100 +
  101 + $result = $odoo->createCommand(
  102 + 'product.template',
  103 + 'create',
  104 + [
  105 + [
  106 + 'name' => 'Test10',
  107 + ],
  108 + ]
  109 + )
  110 + ->execute();
  111 + var_dump($result);
  112 + }
  113 +
  114 + public function actionQ()
  115 + {
  116 + /**
  117 + * @var \artbox\odoo\components\Connection $odoo
  118 + * @var \artbox\odoo\components\OdooMapper $mapper
  119 + */
  120 + $odoo = \Yii::$app->get('odoo');
  121 + $mapper = \Yii::$app->get('odooMapper');
  122 + $result = ( new Query() )->from('product.template')
  123 + ->where(
  124 + [
  125 + 'id',
  126 + '=',
  127 + 3,
  128 + ]
  129 + )
  130 + ->one();
  131 + $mapped = $mapper->toArtbox($result);
  132 + var_dump($mapped);
  133 + die();
  134 + var_dump($mapper->toOdoo($mapped));
  135 + }
  136 +
  137 + public function actionW()
  138 + {
  139 + /**
  140 + * @var \artbox\odoo\components\Connection $odoo
  141 + * @var \artbox\odoo\components\OdooMapper $mapper
  142 + */
  143 + $odoo = \Yii::$app->get('odoo');
  144 + $mapper = \Yii::$app->get('odooMapper');
  145 + $result = ( new Query() )->from('sale.order')
  146 + ->where(
  147 + [
  148 + 'id',
  149 + '=',
  150 + 1,
  151 + ]
  152 + )
  153 + ->one();
  154 + $products = ( new Query() )->from('sale.order.line')
  155 + ->where(
  156 + [
  157 + 'order_id',
  158 + '=',
  159 + $result[ 'id' ],
  160 + ]
  161 + )
  162 + ->all();
  163 + foreach ($products as $product) {
  164 + var_dump($mapper->toArtbox($product));
  165 + }
  166 + }
  167 +
  168 + public function actionE()
  169 + {
  170 + /**
  171 + * @var \artbox\odoo\components\Connection $odoo
  172 + */
  173 + $odoo = \Yii::$app->get('odoo');
  174 + $builder = new Builder($odoo);
  175 + $userId = $builder->setParam('name', 'Test1')
  176 + ->create('res.partner')
  177 + ->execute();
  178 + $command = $builder->setParam('name', 'Test123')
  179 + ->setParam('partner_id', $userId)
  180 + ->create('sale.order');
  181 + var_dump($command->execute());
  182 + }
  183 +
  184 + public function actionR()
  185 + {
  186 + /**
  187 + * @var Order $order
  188 + */
  189 + $order = Order::find()
  190 + ->with('orderProducts.variant.product')
  191 + ->one();
  192 + $odooHelper = new OdooHelper();
  193 + $odooHelper->ensureSaleOrderLine($order);
  194 + }
  195 + }
0 196 \ No newline at end of file
... ...