Merge pull request #32747 from altairisfr/qty_multiple_sale

NEW: Add the "packaging" feature to round the quantities to some given multiples
This commit is contained in:
Laurent Destailleur
2025-01-29 00:50:35 +01:00
committed by GitHub
12 changed files with 188 additions and 2 deletions

View File

@@ -1634,6 +1634,20 @@ class Commande extends CommonOrder
$localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
if (getDolGlobalString('PRODUCT_USE_CUSTOMER_PACKAGING')) {
$product = new Product($this->db);
$result = $product->fetch($fk_product);
if ($qty < $product->packaging) {
$qty = $product->packaging;
} else {
if (!empty($product->packaging) && (fmod((float) $qty, $product->packaging) > 0.000001)) {
$coeff = intval((float) $qty / $product->packaging) + 1;
$qty = (float) $product->packaging * $coeff;
setEventMessages($langs->trans('QtyRecalculatedWithPackaging'), null, 'mesgs');
}
}
}
// Clean vat code
$reg = array();
$vat_src_code = '';
@@ -2192,6 +2206,10 @@ class Commande extends CommonOrder
$line->volume = $objp->volume;
$line->volume_units = $objp->volume_units;
if (getDolGlobalString('PRODUCT_USE_CUSTOMER_PACKAGING')) {
$line->packaging = $objp->packaging;
}
$line->date_start = $this->db->jdate($objp->date_start);
$line->date_end = $this->db->jdate($objp->date_end);
@@ -3163,6 +3181,18 @@ class Commande extends CommonOrder
$this->line->rang = $rangmax + 1;
}
if (getDolGlobalString('PRODUCT_USE_CUSTOMER_PACKAGING')) {
if ($qty < $this->line->packaging) {
$qty = $this->line->packaging;
} else {
if (!empty($this->line->packaging) && fmod($qty, $this->line->packaging) > 0) {
$coeff = intval($qty / $this->line->packaging) + 1;
$qty = $this->line->packaging * $coeff;
setEventMessage($langs->trans('QtyRecalculatedWithPackaging'), 'mesgs');
}
}
}
$this->line->id = $rowid;
$this->line->label = $label;
$this->line->desc = $desc;