Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #139 from OPEN-DSI/2024_rc
Browse files Browse the repository at this point in the history
2024 rc -> 2024
  • Loading branch information
kkhelifa-opendsi authored Jun 25, 2024
2 parents 25749fd + 22a6300 commit 75b0976
Show file tree
Hide file tree
Showing 18 changed files with 1,285 additions and 112 deletions.
9 changes: 8 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# ChangeLog

## [14.0.4] - 21-06-2024
- Ajout de la synchronisation des Mode(s) d’expédition par zone
- Ajout du choix de l'entrepot synchronisée en fonction du choix du mode d'expedition
- Correction de la synchro des meta-données vers woocommerce en convertissant en string
- Modification de l'ecran de parametrage de de l'onglet "stocks"

## [14.0.3] - 17-06-2024
- Ajout version de PHP.

Expand Down Expand Up @@ -901,6 +907,7 @@
- Initial version.


[Non Distribué]: https://github.com/OPEN-DSI/ecommerceng_woosync/compare/14.0.3...HEAD
[Non Distribué]: https://github.com/OPEN-DSI/ecommerceng_woosync/compare/14.0.4...HEAD
[14.0.4]: https://github.com/OPEN-DSI/ecommerceng_woosync/commits/14.0.4
[14.0.3]: https://github.com/OPEN-DSI/ecommerceng_woosync/commits/14.0.3
[14.0.2]: https://github.com/OPEN-DSI/ecommerceng_woosync/commits/14.0.2
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14.0.3
14.0.4
273 changes: 210 additions & 63 deletions admin/stock.php

Large diffs are not rendered by default.

174 changes: 145 additions & 29 deletions class/business/eCommerceSynchro.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2548,6 +2548,37 @@ public function getAllRemoteWarehouses()
return $result;
}

/**
* Get all remote shipping zones
*
* @return array|false List of shipping zones or false if error
*/
public function getAllRemoteShippingZones()
{
$result = $this->eCommerceRemoteAccess->getAllRemoteShippingZones();
if (!$result) {
$this->error = $this->eCommerceRemoteAccess->error;
$this->errors = $this->eCommerceRemoteAccess->errors;
}
return $result;
}

/**
* Get all remote shipping zone methods
*
* @param integer $remote_zone_id Remote zone ID
* @return array|false List of shipping zone methods or false if error
*/
public function getAllRemoteShippingZoneMethods($remote_zone_id)
{
$result = $this->eCommerceRemoteAccess->getAllRemoteShippingZoneMethods($remote_zone_id);
if (!$result) {
$this->error = $this->eCommerceRemoteAccess->error;
$this->errors = $this->eCommerceRemoteAccess->errors;
}
return $result;
}

/**
* Get all webhooks
*
Expand Down Expand Up @@ -4436,10 +4467,28 @@ public function synchronizeOrder($order_data, $dont_synchronize_products = false

// Update the order status
if (!$error && ($new_order || ($order->statut != $order_data['status']))) { // Always when creating
$warehouse_id = $this->eCommerceSite->parameters['order_actions']['valid_order_fk_warehouse'] > 0 && empty($warehouseByLine) ? $this->eCommerceSite->parameters['order_actions']['valid_order_fk_warehouse'] : 0;
if (empty($warehouse_id) && empty($warehouseByLine) && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1) {
$this->errors[] = $this->langs->trans('ECommerceErrorValidOrderWarehouseNotConfigured', $this->eCommerceSite->name);
$error++;
// Get default warehouse ID
$default_warehouse_id = 0;
if (!empty($this->eCommerceSite->parameters['enable_warehouse_depending_on_shipping_zone_method'])) {
$default_warehouse_id = $this->getWarehouseFromShippingMethod($order_data['shipping_lines']);
if ($default_warehouse_id < 0) {
$error++;
}
}
if (!$error && empty($default_warehouse_id)) {
$default_warehouse_id = max(0, (int) $this->eCommerceSite->parameters['order_actions']['valid_order_fk_warehouse']);
}

// Set validate warehouse ID if no warehouse plugin support activated and movement stock on validate order set
$warehouse_id = 0;
if (!$error && empty($this->eCommerceSite->parameters['enable_warehouse_plugin_support']) &&
!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1
) {
$warehouse_id = $default_warehouse_id;
if (empty($warehouse_id)) {
$this->errors[] = $this->langs->trans('ECommerceErrorValidOrderWarehouseNotConfigured');
$error++;
}
}

// Valid the order if the distant order is not at the draft status but the order is draft. For set the order ref.
Expand All @@ -4451,7 +4500,7 @@ public function synchronizeOrder($order_data, $dont_synchronize_products = false
$this->errors = array_merge($this->errors, $order->errors);
$error++;
} else {
$result = $this->setLinesMovementStockOnDifferentWarehouse($order, $warehouseByLine);
$result = $this->setLinesMovementStockOnDifferentWarehouse($order, $warehouseByLine, $default_warehouse_id);
if ($result < 0) {
$this->errors[] = $this->langs->trans("ECommerceErrorWhenMovementStockOnDifferentWarehouse");
$error++;
Expand Down Expand Up @@ -4485,7 +4534,7 @@ public function synchronizeOrder($order_data, $dont_synchronize_products = false
$this->errors = array_merge($this->errors, $order->errors);
$error++;
} else {
$result = $this->setLinesMovementStockOnDifferentWarehouse($order, $warehouseByLine, true);
$result = $this->setLinesMovementStockOnDifferentWarehouse($order, $warehouseByLine, $default_warehouse_id, true);
if ($result < 0) {
$this->errors[] = $this->langs->trans("ECommerceErrorWhenMovementStockOnDifferentWarehouse");
$error++;
Expand Down Expand Up @@ -4631,16 +4680,17 @@ public function synchronizeOrder($order_data, $dont_synchronize_products = false
/**
* Set movement stock for each product line on different warehouse
*
* @param CommonObject $object Object handler
* @param array $warehouseByLine List of warehouse ID for each line
* @param boolean $undoMovement True to undo movements
* @return int <0 if KO, >0 if OK
* @param CommonObject $object Object handler
* @param array $warehouseByLine List of warehouse ID for each line
* @param int $default_warehouse_id Default warehouse ID
* @param boolean $undoMovement True to undo movements
* @return int <0 if KO, >0 if OK
*/
public function setLinesMovementStockOnDifferentWarehouse($object, $warehouseByLine, $undoMovement = false)
public function setLinesMovementStockOnDifferentWarehouse($object, $warehouseByLine, $default_warehouse_id, $undoMovement = false)
{
global $conf;

$canMakeMovement = !empty($warehouseByLine) && !empty($conf->stock->enabled);
$canMakeMovement = !empty($this->eCommerceSite->parameters['enable_warehouse_plugin_support']) && !empty($conf->stock->enabled);
if ($object->element == 'commande') {
$canMakeMovement &= !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1;
$movementLabel = $this->langs->trans($undoMovement ? "OrderCanceledInDolibarr" : "OrderValidatedInDolibarr", $object->ref);
Expand Down Expand Up @@ -4671,16 +4721,16 @@ public function setLinesMovementStockOnDifferentWarehouse($object, $warehouseByL
$error = 0;
$this->db->begin();
foreach ($object->lines as $line) {
if ($line->fk_product > 0) {
if ($line->fk_product > 0 && ($line->product_type != Product::TYPE_SERVICE || getDolGlobalString('STOCK_SUPPORTS_SERVICES'))) {
$remoteWarehouseId = isset($warehouseByLine[$line->id]) && $warehouseByLine[$line->id] > 0 ? $warehouseByLine[$line->id] : 0;
if (empty($remoteWarehouseId) && $line->product_type == Product::TYPE_PRODUCT) {
if (empty($remoteWarehouseId) && empty($default_warehouse_id)) {
$this->errors[] = $this->langs->trans("ECommerceErrorWarehouseIdNotSpecifiedForTheLine", $line->fk_product);
$error++;
break;
}

$warehouseId = isset($remoteWarehousesList[$remoteWarehouseId]['warehouse_id']) && $remoteWarehousesList[$remoteWarehouseId]['warehouse_id'] > 0 ? $remoteWarehousesList[$remoteWarehouseId]['warehouse_id'] : 0;
if ($remoteWarehouseId > 0 && empty($warehouseId)) {
$warehouseId = !empty($remoteWarehouseId) && isset($remoteWarehousesList[$remoteWarehouseId]['warehouse_id']) && $remoteWarehousesList[$remoteWarehouseId]['warehouse_id'] > 0 ? $remoteWarehousesList[$remoteWarehouseId]['warehouse_id'] : $default_warehouse_id;
if (!empty($remoteWarehouseId) && empty($warehouseId)) {
dol_syslog(__METHOD__ . ' Warehouse not configured for remote warehouse ID ' . $remoteWarehouseId . ' so we don\'t process this remote warehouse', LOG_WARNING);
continue;
// $this->errors[] = $this->langs->trans("ECommerceErrorWarehouseIdNotConfiguredForRemoteWarehouse", $remoteWarehouseId, $this->eCommerceSite->name);
Expand Down Expand Up @@ -4716,6 +4766,38 @@ public function setLinesMovementStockOnDifferentWarehouse($object, $warehouseByL
return 1;
}

/**
* Get warehouse from shipping method
*
* @param array $shipping_lines List of shipping lines ID
* @return int <0 if KO, =0 if not found, >0 if warehouse ID found
*/
public function getWarehouseFromShippingMethod($shipping_lines)
{
// Get all shipping methods
dol_include_once('/ecommerceng/class/data/eCommerceRemoteShippingZoneMethods.class.php');
$remote_shipping_methods = new eCommerceRemoteShippingZoneMethods($this->db);
$remoteShippingMethodsList = $remote_shipping_methods->get_all($this->eCommerceSite->id);
if (!is_array($remoteShippingMethodsList) && $remoteShippingMethodsList < 0) {
$this->errors[] = $remote_shipping_methods->errorsToString();
return -1;
}

foreach ($remoteShippingMethodsList as $key1 => $remote_shipping_zone_infos) {
foreach ($remote_shipping_zone_infos['methods'] as $key2 => $infos) {
foreach ($shipping_lines as $shipping_line) {
if ($infos['remote_instance_id'] == $shipping_line['instance_id'] &&
$infos['remote_method_id'] == $shipping_line['method_id']
) {
return (int) $infos['warehouse_id'];
}
}
}
}

return 0;
}

/**
* Synchronize a order data in the invoice in Dolibarr database
*
Expand Down Expand Up @@ -5027,11 +5109,28 @@ public function synchronizeInvoiceFromOrder($order_data, $dont_synchronize_produ
}
}

// Get warehouse ID
$warehouse_id = $this->eCommerceSite->parameters['order_actions']['valid_invoice_fk_warehouse'] > 0 && empty($warehouseByLine) ? $this->eCommerceSite->parameters['order_actions']['valid_invoice_fk_warehouse'] : 0;
if (empty($warehouse_id) && empty($warehouseByLine) && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
$this->errors[] = $this->langs->trans('ECommerceErrorInvoiceValidateWarehouseNotConfigured');
$error++;
// Get default warehouse ID
$default_warehouse_id = 0;
if (!empty($this->eCommerceSite->parameters['enable_warehouse_depending_on_shipping_zone_method'])) {
$default_warehouse_id = $this->getWarehouseFromShippingMethod($order_data['shipping_lines']);
if ($default_warehouse_id < 0) {
$error++;
}
}
if (!$error && empty($default_warehouse_id)) {
$default_warehouse_id = max(0, (int) $this->eCommerceSite->parameters['order_actions']['valid_invoice_fk_warehouse']);
}

// Set validate warehouse ID if no warehouse plugin support activated and movement stock on validate order set
$warehouse_id = 0;
if (!$error && empty($this->eCommerceSite->parameters['enable_warehouse_plugin_support']) &&
!empty($conf->global->STOCK_CALCULATE_ON_BILL)
) {
$warehouse_id = $default_warehouse_id;
if (empty($warehouse_id)) {
$this->errors[] = $this->langs->trans('ECommerceErrorInvoiceValidateWarehouseNotConfigured');
$error++;
}
}

if ($isDepositType) {
Expand All @@ -5052,7 +5151,7 @@ public function synchronizeInvoiceFromOrder($order_data, $dont_synchronize_produ
$this->errors = array_merge($this->errors, $invoice->errors);
$error++;
} else {
$result = $this->setLinesMovementStockOnDifferentWarehouse($invoice, $warehouseByLine);
$result = $this->setLinesMovementStockOnDifferentWarehouse($invoice, $warehouseByLine, $default_warehouse_id);
if ($result < 0) {
$this->errors[] = $this->langs->trans("ECommerceErrorWhenMovementStockOnDifferentWarehouse");
$error++;
Expand Down Expand Up @@ -5208,7 +5307,7 @@ public function synchronizeInvoiceFromOrder($order_data, $dont_synchronize_produ
// Validate supplier invoice
if (!$error) {
// Get warehouse ID
$warehouse_id = $this->eCommerceSite->parameters['order_actions']['valid_supplier_invoice_fk_warehouse'] > 0 ? $this->eCommerceSite->parameters['order_actions']['valid_supplier_invoice_fk_warehouse'] : 0;
$warehouse_id = /*$this->eCommerceSite->parameters['order_actions']['valid_supplier_invoice_fk_warehouse'] > 0 ? $this->eCommerceSite->parameters['order_actions']['valid_supplier_invoice_fk_warehouse'] :*/ 0;

$result = $supplier_invoice->validate($this->user, '', $warehouse_id);
if ($result < 0) {
Expand Down Expand Up @@ -5840,11 +5939,28 @@ public function synchronizeInvoiceRefundsFromOrder($order_data, $dont_synchroniz
}
}

// Get warehouse ID
$warehouse_id = $this->eCommerceSite->parameters['order_actions']['valid_invoice_fk_warehouse'] > 0 ? $this->eCommerceSite->parameters['order_actions']['valid_invoice_fk_warehouse'] : 0;
if (empty($warehouse_id) && empty($warehouseByLine) && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
$this->errors[] = $this->langs->trans('ECommerceErrorInvoiceValidateWarehouseNotConfigured');
$error++;
// Get default warehouse ID
$default_warehouse_id = 0;
if (!empty($this->eCommerceSite->parameters['enable_warehouse_depending_on_shipping_zone_method'])) {
$default_warehouse_id = $this->getWarehouseFromShippingMethod($order_data['shipping_lines']);
if ($default_warehouse_id < 0) {
$error++;
}
}
if (!$error && empty($default_warehouse_id)) {
$default_warehouse_id = max(0, (int) $this->eCommerceSite->parameters['order_actions']['valid_invoice_fk_warehouse']);
}

// Set validate warehouse ID if no warehouse plugin support activated and movement stock on validate order set
$warehouse_id = 0;
if (!$error && empty($this->eCommerceSite->parameters['enable_warehouse_plugin_support']) &&
!empty($conf->global->STOCK_CALCULATE_ON_BILL)
) {
$warehouse_id = $default_warehouse_id;
if (empty($warehouse_id)) {
$this->errors[] = $this->langs->trans('ECommerceErrorInvoiceValidateWarehouseNotConfigured');
$error++;
}
}

// Validate invoice
Expand All @@ -5856,7 +5972,7 @@ public function synchronizeInvoiceRefundsFromOrder($order_data, $dont_synchroniz
$this->errors = array_merge($this->errors, $invoice_refund->errors);
$error++;
} else {
$result = $this->setLinesMovementStockOnDifferentWarehouse($invoice_refund, $warehouseByLine);
$result = $this->setLinesMovementStockOnDifferentWarehouse($invoice_refund, $warehouseByLine, $default_warehouse_id);
if ($result < 0) {
$this->errors[] = $this->langs->trans("ECommerceErrorWhenMovementStockOnDifferentWarehouse");
$error++;
Expand Down
27 changes: 27 additions & 0 deletions class/data/eCommerceRemoteAccess.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,33 @@ public function getAllRemoteWarehouses()
return $result;
}

/**
* Get all remote shipping zones
*
* @return array|false List of remote shipping zones or false if error
*/
public function getAllRemoteShippingZones()
{
$result=$this->class->getAllRemoteShippingZones();
$this->error=$this->class->error;
$this->errors=$this->class->errors;
return $result;
}

/**
* Get all remote shipping zone methods
*
* @param integer $remote_zone_id Remote zone ID
* @return array|false List of remote shipping zone methods or false if error
*/
public function getAllRemoteShippingZoneMethods($remote_zone_id)
{
$result=$this->class->getAllRemoteShippingZoneMethods($remote_zone_id);
$this->error=$this->class->error;
$this->errors=$this->class->errors;
return $result;
}

/**
* Get all webhooks
*
Expand Down
Loading

0 comments on commit 75b0976

Please sign in to comment.