disable synchro button in adm order

This commit is contained in:
Rodney Figaro 2017-03-16 12:08:00 +01:00
parent fac0185cd9
commit f6d0d7a1c2
2 changed files with 47 additions and 34 deletions

View File

@ -170,15 +170,21 @@
{l s='Partial refund'} {l s='Partial refund'}
</a> </a>
{/if} {/if}
{if !$order->isSynchIntoErp()} {if $erp_enabled}
<a class="btn btn-default" href="{$link->getAdminLink('AdminOrders')|escape:'html':'UTF-8'}&amp;vieworder&amp;id_order={$order->id|intval}&amp;syncherp=1"> {if !$order->isSynchIntoErp()}
<i class="icon-upload"></i> <a class="btn btn-default" href="{$link->getAdminLink('AdminOrders')|escape:'html':'UTF-8'}&amp;vieworder&amp;id_order={$order->id|intval}&amp;syncherp=1">
{l s='Synchroniser dans Odoo'} <i class="icon-upload"></i>
</a> {l s='Synchroniser dans Odoo'}
</a>
{else}
<span class="span label label-inactive">
<i class="icon-remove"></i>
{l s='Synchronisée'}
</span>
{/if}
{else} {else}
<span class="span label label-inactive"> <span class="span label label-inactive">
<i class="icon-remove"></i> {l s='Synchronisation désactivée'}
{l s='Synchronisée'}
</span> </span>
{/if} {/if}
</div> </div>

View File

@ -1522,37 +1522,43 @@ class AdminOrdersControllerCore extends AdminController
} }
} elseif (Tools::getValue('syncherp') == 1) { } elseif (Tools::getValue('syncherp') == 1) {
$id_order = Tools::getValue('id_order', false); if (!defined('ERP_ENABLED') || !ERP_ENABLED) {
if ($id_order) { $this->errors[] = Tools::displayError('La synchro avec Odoo est actuellement désactivée.');
$order = new Order((int)$id_order); }
if (!$order->isSynchIntoErp()) { else {
if ($order->getIdErp() === 1) { $id_order = Tools::getValue('id_order', false);
$order->deletIdErpIfNotSynch(); if ($id_order) {
} $order = new Order((int)$id_order);
if (!$order->isSynchIntoErp()) {
$params['id_order'] = $order->id; if ($order->getIdErp() === 1) {
$params['newOrderStatus'] = new StdClass(); $order->deletIdErpIfNotSynch();
if ($order->hasStatusInHistory(2)) {
$params['newOrderStatus']->id = 2;
} elseif ($order->hasStatusInHistory(10)) {
$params['newOrderStatus']->id = 10;
} elseif ($order->hasStatusInHistory(1)) {
$params['newOrderStatus']->id = 1;
}
if (!empty($params['newOrderStatus']->id)) {
$erporder = Module::getInstanceByName('erporder');
if ($erporder) {
return $erporder->hookActionOrderStatusPostUpdate($params);
} }
} else {
$sql = 'SELECT `name` FROM `'._DB_PREFIX_.'order_state_lang` WHERE `id_order_state` IN (1,2,10) AND id_lang = 1';
$rows = Db::getInstance()->executeS($sql);
$txt .= implode('", "', array_column($rows, 'name')); $params['id_order'] = $order->id;
$this->errors[] = Tools::displayError('Pas de synchro possible, la commande doit avoir eu l\'un des status suivants : "'.$txt.'"'); $params['newOrderStatus'] = new StdClass();
if ($order->hasStatusInHistory(2)) {
$params['newOrderStatus']->id = 2;
} elseif ($order->hasStatusInHistory(10)) {
$params['newOrderStatus']->id = 10;
} elseif ($order->hasStatusInHistory(1)) {
$params['newOrderStatus']->id = 1;
}
if (!empty($params['newOrderStatus']->id)) {
$erporder = Module::getInstanceByName('erporder');
if ($erporder) {
return $erporder->hookActionOrderStatusPostUpdate($params);
}
} else {
$sql = 'SELECT `name` FROM `'._DB_PREFIX_.'order_state_lang` WHERE `id_order_state` IN (1,2,10) AND id_lang = 1';
$rows = Db::getInstance()->executeS($sql);
$txt .= implode('", "', array_column($rows, 'name'));
$this->errors[] = Tools::displayError('Pas de synchro possible, la commande doit avoir eu l\'un des status suivants : "'.$txt.'"');
}
} }
} }
} }
@ -1759,6 +1765,7 @@ class AdminOrdersControllerCore extends AdminController
// Smarty assign // Smarty assign
$this->tpl_view_vars = array( $this->tpl_view_vars = array(
'erp_enabled' => (defined('ERP_ENABLED') && ERP_ENABLED)?true:false,
'order' => $order, 'order' => $order,
'cart' => new Cart($order->id_cart), 'cart' => new Cart($order->id_cart),
'customer' => $customer, 'customer' => $customer,