|
@@ -301,7 +301,9 @@ class MouvementStock extends CommonObject
|
|
|
// If not found, we add record
|
|
|
$sql = "SELECT pb.rowid, pb.batch, pb.eatby, pb.sellby FROM ".$this->db->prefix()."product_lot as pb";
|
|
|
$sql .= " WHERE pb.fk_product = ".((int) $fk_product)." AND pb.batch = '".$this->db->escape($batch)."'";
|
|
|
+
|
|
|
dol_syslog(get_class($this)."::_create scan serial for this product to check if eatby and sellby match", LOG_DEBUG);
|
|
|
+
|
|
|
$resql = $this->db->query($sql);
|
|
|
if ($resql) {
|
|
|
$num = $this->db->num_rows($resql);
|
|
@@ -560,6 +562,10 @@ class MouvementStock extends CommonObject
|
|
|
if (!$error && isModEnabled('productbatch') && $product->hasbatch() && !$skip_batch) {
|
|
|
if ($id_product_batch > 0) {
|
|
|
$result = $this->createBatch($id_product_batch, $qty);
|
|
|
+ if ($result == -2 && $fk_product_stock > 0) { // The entry for this product batch does not exists anymore, bu we already have a llx_product_stock, so we recreate the batch entry in product_batch
|
|
|
+ $param_batch = array('fk_product_stock' =>$fk_product_stock, 'batchnumber'=>$batch);
|
|
|
+ $result = $this->createBatch($param_batch, $qty);
|
|
|
+ }
|
|
|
} else {
|
|
|
$param_batch = array('fk_product_stock' =>$fk_product_stock, 'batchnumber'=>$batch);
|
|
|
$result = $this->createBatch($param_batch, $qty);
|
|
@@ -863,10 +869,10 @@ class MouvementStock extends CommonObject
|
|
|
* Create or update batch record (update table llx_product_batch). No check is done here, done by parent.
|
|
|
*
|
|
|
* @param array|int $dluo Could be either
|
|
|
- * - int if row id of product_batch table
|
|
|
+ * - int if row id of product_batch table (for update)
|
|
|
* - or complete array('fk_product_stock'=>, 'batchnumber'=>)
|
|
|
* @param int $qty Quantity of product with batch number. May be a negative amount.
|
|
|
- * @return int <0 if KO, else return productbatch id
|
|
|
+ * @return int <0 if KO, -2 if we try to update a product_batchid that does not exist, else return productbatch id
|
|
|
*/
|
|
|
private function createBatch($dluo, $qty)
|
|
|
{
|