|
From d647479794f6f7e9b1f4ccc1947efd8d7258afed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com>
Date: Sat, 23 Nov 2019 17:17:25 +0100
Subject: [PATCH 07/15] Do not delete product automaticaly (unlink only)
---
htdocs/variants/combinations.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/htdocs/variants/combinations.php b/htdocs/variants/combinations.php
index c2067a28ee1..e3993d02d3b 100644
--- a/htdocs/variants/combinations.php
+++ b/htdocs/variants/combinations.php
@@ -244,7 +244,7 @@ if ($action === 'confirm_deletecombination') {
if ($prodcomb->fetch($valueid) > 0) {
$db->begin();
- if ($prodcomb->delete($user) > 0 && $prodstatic->fetch($prodcomb->fk_product_child) > 0 && $prodstatic->delete($user) > 0) {
+ if ($prodcomb->delete($user) > 0) {
$db->commit();
setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
header('Location: '.dol_buildpath('/variants/combinations.php?id='.$object->id, 2));
From 83de0fa7c19fee857fa9723da6fd6c449da674a4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com>
Date: Sat, 23 Nov 2019 18:03:46 +0100
Subject: [PATCH 08/15] Add the choice to delete the product linked
---
htdocs/variants/combinations.php | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/htdocs/variants/combinations.php b/htdocs/variants/combinations.php
index e3993d02d3b..adb2fa8b739 100644
--- a/htdocs/variants/combinations.php
+++ b/htdocs/variants/combinations.php
@@ -42,6 +42,7 @@ $show_files = GETPOST('show_files', 'int');
$confirm = GETPOST('confirm', 'alpha');
$toselect = GETPOST('toselect', 'array');
$cancel = GETPOST('cancel', 'alpha');
+$delete_product = GETPOST('delete_product', 'alpha');
// Security check
$fieldvalue = (!empty($id) ? $id : $ref);
@@ -244,7 +245,7 @@ if ($action === 'confirm_deletecombination') {
if ($prodcomb->fetch($valueid) > 0) {
$db->begin();
- if ($prodcomb->delete($user) > 0) {
+ if ($prodcomb->delete($user) > 0 && (empty($delete_product) || ($delete_product == 'on' && $prodstatic->fetch($prodcomb->fk_product_child) > 0 && $prodstatic->delete($user) > 0))) {
$db->commit();
setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
header('Location: '.dol_buildpath('/variants/combinations.php?id='.$object->id, 2));
@@ -635,7 +636,7 @@ if (! empty($id) || ! empty($ref))
$langs->trans('Delete'),
$langs->trans('ProductCombinationDeleteDialog', $prodstatic->ref),
"confirm_deletecombination",
- '',
+ array(array('label'=> $langs->trans('DeleteLinkedProduct'),'type'=> 'checkbox', 'name' => 'delete_product', 'value' => false)),
0,
1
);
From b959e595545d6b434122e52ac6fae05bf52804a3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com>
Date: Sat, 23 Nov 2019 18:09:17 +0100
Subject: [PATCH 09/15] Checkbox label delete child product EN
---
htdocs/langs/en_US/products.lang | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang
index 1ca335da637..103f13b7f75 100644
--- a/htdocs/langs/en_US/products.lang
+++ b/htdocs/langs/en_US/products.lang
@@ -347,4 +347,5 @@ ErrorDestinationProductNotFound=Destination product not found
ErrorProductCombinationNotFound=Product variant not found
ActionAvailableOnVariantProductOnly=Action only available on the variant of product
ProductsPricePerCustomer=Product prices per customers
-ProductSupplierExtraFields=Additional Attributes (Supplier Prices)
\ No newline at end of file
+ProductSupplierExtraFields=Additional Attributes (Supplier Prices)
+DeleteLinkedProduct = Delete the child product linked to the combination
From 950a32a433ae6f633eaabeb37cc5619bddc470fe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com>
Date: Sat, 23 Nov 2019 18:11:20 +0100
Subject: [PATCH 10/15] Checkbox label delete child product FR
---
htdocs/langs/fr_FR/products.lang | 1 +
1 file changed, 1 insertion(+)
diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang
index 0248f6470a9..d5465684736 100644
--- a/htdocs/langs/fr_FR/products.lang
+++ b/htdocs/langs/fr_FR/products.lang
@@ -347,3 +347,4 @@ ErrorDestinationProductNotFound=Produit destination non trouvé
ErrorProductCombinationNotFound=Variante du produit non trouvé
ActionAvailableOnVariantProductOnly=Action disponible uniquement sur la variante du produit
ProductsPricePerCustomer=Prix produit par clients
+DeleteLinkedProduct = Supprimer le produit enfant lié à la variante
From 76c5a08242ec496c7d9a2b1ceefc33e1864e284e Mon Sep 17 00:00:00 2001
From: stickler-ci
Date: Thu, 28 Nov 2019 12:13:36 +0000
Subject: [PATCH 11/15] Fixing style errors.
---
htdocs/product/class/api_products.class.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index 05e4fe3b1c6..8cb710ceab4 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -1373,13 +1373,13 @@ class Products extends DolibarrApi
}
$prodcomb = new ProductCombination($this->db);
-
+
$result = $prodcomb->createProductCombination(DolibarrApiAccess::$user, $this->product, $features, array(), $price_impact_is_percent, $price_impact, $weight_impact, $reference);
if ($result > 0)
{
- return $result;
+ return $result;
} else {
- throw new RestException(500, "Error creating new product variant");
+ throw new RestException(500, "Error creating new product variant");
}
}
From 565a17dc47c6a032f21a42584c4ebda48fcec785 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com>
Date: Sat, 30 Nov 2019 23:36:23 +0100
Subject: [PATCH 12/15] API New add purchase prices
---
htdocs/product/class/api_products.class.php | 67 +++++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index 8cb710ceab4..b9d21b481e2 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -631,6 +631,73 @@ class Products extends DolibarrApi
'prices_by_qty_list'=>$this->product->prices_by_qty_list[0]
);
}
+
+ /**
+ * Add purchase prices for a product.
+ *
+ * @param int $id ID of Product
+ * @param float $qty Min quantity for which price is valid
+ * @param float $buyprice Purchase price for the quantity min
+ * @param string $price_base_type HT or TTC
+ * @param int $fourn_id Supplier ID
+ * @param int $availability Product availability
+ * @param string $ref_fourn Supplier ref
+ * @param float $tva_tx New VAT Rate (For example 8.5. Should not be a string)
+ * @param string $charges costs affering to product
+ * @param float $remise_percent Discount regarding qty (percent)
+ * @param float $remise Discount regarding qty (amount)
+ * @param int $newnpr Set NPR or not
+ * @param int $delivery_time_days Delay in days for delivery (max). May be '' if not defined.
+ * @param string $supplier_reputation Reputation with this product to the defined supplier (empty, FAVORITE, DONOTORDER)
+ * @param array $localtaxes_array Array with localtaxes info array('0'=>type1,'1'=>rate1,'2'=>type2,'3'=>rate2) (loaded by getLocalTaxesFromRate(vatrate, 0, ...) function).
+ * @param string $newdefaultvatcode Default vat code
+ * @param float $multicurrency_buyprice Purchase price for the quantity min in currency
+ * @param string $multicurrency_price_base_type HT or TTC in currency
+ * @param float $multicurrency_tx Rate currency
+ * @param string $multicurrency_code Currency code
+ * @param string $desc_fourn Custom description for product_fourn_price
+ * @param string $barcode Barcode
+ * @param int $fk_barcode_type Barcode type
+ * @return int
+ *
+ * @throws RestException
+ * @throws 401
+ *
+ * @url POST {id}/purchase_prices
+ */
+ public function addPurchasePrice($id, $qty, $buyprice, $price_base_type, $fourn_id, $availability, $ref_fourn, $tva_tx, $charges = 0, $remise_percent = 0, $remise = 0, $newnpr = 0, $delivery_time_days = 0, $supplier_reputation = '', $localtaxes_array = array(), $newdefaultvatcode = '', $multicurrency_buyprice = 0, $multicurrency_price_base_type = 'HT', $multicurrency_tx = 1, $multicurrency_code = '', $desc_fourn = '', $barcode = '', $fk_barcode_type = null)
+ {
+ if(! DolibarrApiAccess::$user->rights->produit->creer) {
+ throw new RestException(401);
+ }
+
+ $result = $this->productsupplier->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'Product not found');
+ }
+
+ if (!DolibarrApi::_checkAccessToResource('product', $this->productsupplier->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
+
+ $result = $this->productsupplier->add_fournisseur(DolibarrApiAccess::$user, $fourn_id, $ref_fourn, $qty);
+ if ($result <= 0) {
+ throw new RestException(500, "Error adding supplier to product : ".$this->db->lasterror());
+ }
+
+ $fourn = new Fournisseur($this->db);
+ $result = $fourn->fetch($fourn_id);
+ if ($result <= 0) {
+ throw new RestException(404, 'Supplier not found');
+ }
+
+ $result = $this->productsupplier->update_buyprice($qty, $buyprice, DolibarrApiAccess::$user, $price_base_type, $fourn, $availability, $ref_fourn, $tva_tx, $charges, $remise_percent, $remise, $newnpr, $delivery_time_days, $supplier_reputation, $localtaxes_array, $newdefaultvatcode, $multicurrency_buyprice, $multicurrency_price_base_type, $multicurrency_tx, $multicurrency_code, $desc_fourn, $barcode, $fk_barcode_type);
+
+ if ($result <= 0) {
+ throw new RestException(500, "Error updating buy price : ".$this->db->lasterror());
+ }
+ return (int) $this->productsupplier->product_fourn_price_id;
+ }
/**
* Delete purchase price for a product
From 1bad6f5c9c783dc97a4f5bb69708a997aa6c509e Mon Sep 17 00:00:00 2001
From: stickler-ci
Date: Sat, 30 Nov 2019 22:38:05 +0000
Subject: [PATCH 13/15] Fixing style errors.
---
htdocs/product/class/api_products.class.php | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index b9d21b481e2..1bb5aed98f5 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -631,7 +631,7 @@ class Products extends DolibarrApi
'prices_by_qty_list'=>$this->product->prices_by_qty_list[0]
);
}
-
+
/**
* Add purchase prices for a product.
*
@@ -670,29 +670,29 @@ class Products extends DolibarrApi
if(! DolibarrApiAccess::$user->rights->produit->creer) {
throw new RestException(401);
}
-
+
$result = $this->productsupplier->fetch($id);
if (!$result) {
throw new RestException(404, 'Product not found');
}
-
+
if (!DolibarrApi::_checkAccessToResource('product', $this->productsupplier->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
-
+
$result = $this->productsupplier->add_fournisseur(DolibarrApiAccess::$user, $fourn_id, $ref_fourn, $qty);
if ($result <= 0) {
throw new RestException(500, "Error adding supplier to product : ".$this->db->lasterror());
}
-
+
$fourn = new Fournisseur($this->db);
$result = $fourn->fetch($fourn_id);
if ($result <= 0) {
throw new RestException(404, 'Supplier not found');
}
-
+
$result = $this->productsupplier->update_buyprice($qty, $buyprice, DolibarrApiAccess::$user, $price_base_type, $fourn, $availability, $ref_fourn, $tva_tx, $charges, $remise_percent, $remise, $newnpr, $delivery_time_days, $supplier_reputation, $localtaxes_array, $newdefaultvatcode, $multicurrency_buyprice, $multicurrency_price_base_type, $multicurrency_tx, $multicurrency_code, $desc_fourn, $barcode, $fk_barcode_type);
-
+
if ($result <= 0) {
throw new RestException(500, "Error updating buy price : ".$this->db->lasterror());
}
From 7b295bf738dc295cfd774871f7fdb54ea5708c17 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com>
Date: Sun, 1 Dec 2019 14:56:39 +0100
Subject: [PATCH 14/15] addPurchasePrice Update the price if already exist
---
htdocs/product/class/api_products.class.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index 1bb5aed98f5..4ce7750fddd 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -633,7 +633,7 @@ class Products extends DolibarrApi
}
/**
- * Add purchase prices for a product.
+ * Add/Update purchase prices for a product.
*
* @param int $id ID of Product
* @param float $qty Min quantity for which price is valid
@@ -681,7 +681,7 @@ class Products extends DolibarrApi
}
$result = $this->productsupplier->add_fournisseur(DolibarrApiAccess::$user, $fourn_id, $ref_fourn, $qty);
- if ($result <= 0) {
+ if ($result < 0) {
throw new RestException(500, "Error adding supplier to product : ".$this->db->lasterror());
}
From c2677c0231f3bd4fb80e424279243d56871ae0ac Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Fri, 21 Feb 2020 19:44:02 +0100
Subject: [PATCH 15/15] Update api_products.class.php
---
htdocs/product/class/api_products.class.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index 4ce7750fddd..ccfe30055f8 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -660,8 +660,8 @@ class Products extends DolibarrApi
* @param int $fk_barcode_type Barcode type
* @return int
*
- * @throws RestException
- * @throws 401
+ * @throws RestException 500
+ * @throws RestException 401
*
* @url POST {id}/purchase_prices
*/
|