fix calculate costs bom (#31755)

* fix calculate costs bom

* fix calculate costs bom

* Update bom.class.php

* fix

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
Frédéric FRANCE 2024-11-15 15:05:51 +01:00 committed by GitHub
parent 5b42996669
commit ead048e1fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 21 deletions

View file

@ -34,9 +34,6 @@ if (isModEnabled('workstation')) {
require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstation.class.php';
}
//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
/**
* Class for BOM
@ -1471,8 +1468,12 @@ class BOM extends CommonObject
}
} else {
// Convert qty of line into hours
$unitforline = measuringUnitString($line->fk_unit, '', '', 1);
$qtyhourforline = convertDurationtoHour((float) $line->qty, $unitforline);
require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
$measuringUnits = new CUnits($this->db);
$measuringUnits->fetch($line->fk_unit);
// The unit is a unit for time, so the $measuringUnits->scale is not a power of 10, but directly the factor to change unit into seconds
$qtyhourforline = $line->qty * (int) $measuringUnits->scale / 3600;
if (isModEnabled('workstation') && !empty($line->fk_default_workstation)) {
$workstation = new Workstation($this->db);

View file

@ -1,6 +1,7 @@
<?php
/* Copyright (C) 2007-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
/* Copyright (C) 2007-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -36,8 +37,8 @@ class CUnits extends CommonDict
*/
public $records = array();
//var $element='ctypent'; //!< Id that identify managed objects
//var $table_element='ctypent'; //!< Name of table without prefix where object is stored
// public $element = 'cunits'; //!< Id that identify managed objects
// public $table_element = 'c_units'; //!< Name of table without prefix where object is stored
/**
* @var string label
@ -50,16 +51,19 @@ class CUnits extends CommonDict
* @var string
*/
public $sortorder;
/**
* @var string
*/
public $short_label;
/**
* @var string
*/
public $unit_type;
/**
* @var string
* @var ?int
*/
public $scale;
@ -107,7 +111,7 @@ class CUnits extends CommonDict
$this->active = (int) $this->active;
}
if (isset($this->scale)) {
$this->scale = trim($this->scale);
$this->scale = (int) $this->scale;
}
// Check parameters
@ -127,7 +131,7 @@ class CUnits extends CommonDict
$sql .= " ".(!isset($this->label) ? 'NULL' : "'".$this->db->escape($this->label)."'").",";
$sql .= " ".(!isset($this->short_label) ? 'NULL' : "'".$this->db->escape($this->short_label)."'").",";
$sql .= " ".(!isset($this->unit_type) ? 'NULL' : "'".$this->db->escape($this->unit_type)."'").",";
$sql .= " ".(!isset($this->scale) ? 'NULL' : "'".$this->db->escape($this->scale)."'");
$sql .= " ".(!isset($this->scale) ? 'NULL' : (int) $this->scale);
$sql .= ")";
$this->db->begin();
@ -176,7 +180,6 @@ class CUnits extends CommonDict
$sql .= " t.short_label,";
$sql .= " t.scale,";
$sql .= " t.unit_type,";
$sql .= " t.scale,";
$sql .= " t.active";
$sql .= " FROM ".$this->db->prefix()."c_units as t";
$sql_where = array();
@ -201,14 +204,13 @@ class CUnits extends CommonDict
if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
$this->id = (int) $obj->rowid;
$this->code = $obj->code;
$this->label = $obj->label;
$this->short_label = $obj->short_label;
$this->scale = $obj->scale;
$this->scale = $obj->scale ? (int) $obj->scale : null;
$this->unit_type = $obj->unit_type;
$this->scale = $obj->scale;
$this->active = $obj->active;
$this->active = (int) $obj->active;
}
$this->db->free($resql);
@ -294,14 +296,14 @@ class CUnits extends CommonDict
while ($obj = $this->db->fetch_object($resql)) {
$record = new self($this->db);
$record->id = $obj->rowid;
$record->id = (int) $obj->rowid;
$record->code = $obj->code;
$record->sortorder = $obj->sortorder;
$record->label = $obj->label;
$record->short_label = $obj->short_label;
$record->unit_type = $obj->unit_type;
$record->scale = $obj->scale;
$record->active = $obj->active;
$record->scale = $obj->scale ? (int) $obj->scale : null;
$record->active = (int) $obj->active;
$this->records[$record->id] = $record;
}
@ -346,7 +348,7 @@ class CUnits extends CommonDict
$this->libelle = trim($this->unit_type);
}
if (isset($this->scale)) {
$this->scale = trim($this->scale);
$this->scale = (int) $this->scale;
}
if (isset($this->active)) {
$this->active = (int) $this->active;