2
0
forked from Wavyzz/dolibarr

ADD: packaging to round the quantities to some given multiples for the sales orders

This commit is contained in:
Mélina JOUM
2025-01-20 12:50:09 +01:00
parent a14a474a70
commit b7b0a29e42
2 changed files with 41 additions and 0 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) && ($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;