Merge pull request #15548 from defrance/patch-163

NEW Can set the default BOM on a product
This commit is contained in:
Laurent Destailleur 2021-08-11 21:52:21 +02:00 committed by GitHub
commit 2683a360c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 5 deletions

View File

@ -103,5 +103,6 @@ create table llx_product
desiredstock float DEFAULT 0,
fk_unit integer DEFAULT NULL,
price_autogen tinyint DEFAULT 0,
fk_default_bom integer DEFAULT NULL,
fk_project integer DEFAULT NULL -- Used when the product was generated by a project or is specific to a project
)ENGINE=innodb;

View File

@ -64,13 +64,12 @@ if (!empty($conf->commande->enabled)) {
}
if (!empty($conf->accounting->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
}
if (!empty($conf->accounting->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
}
if (!empty($conf->accounting->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
}
if (!empty($conf->bom->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
}
// Load translation files required by the page
$langs->loadLangs(array('products', 'other'));
@ -522,6 +521,13 @@ if (empty($reshook)) {
$object->finished = null;
}
$fk_default_bom = GETPOST('fk_default_bom', 'int');
if ($fk_default_bom >= 0) {
$object->fk_default_bom = $fk_default_bom;
} else {
$object->fk_default_bom = null;
}
$units = GETPOST('units', 'int');
if ($units > 0) {
$object->fk_unit = $units;
@ -1905,6 +1911,13 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
print '<table class="border centpercent">';
if (!$object->isService() && !empty($conf->bom->enabled)) {
print '<tr><td>'.$form->textwithpicto($langs->trans("DefaultBOM"), $langs->trans("DefaultBOMDesc")).'</td><td>';
$bomkey = "Bom:bom/class/bom.class.php:0:t.status=1 AND t.fk_product=".$object->id;
print $form->selectForForms($bomkey, 'fk_default_bom', $object->fk_default_bom, 1);
print '</td></tr>';
}
if (empty($conf->global->PRODUCT_DISABLE_ACCOUNTING)) {
if (!empty($conf->accounting->enabled)) {
// Accountancy_code_sell
@ -2357,6 +2370,17 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
print '<tr><td>'.$langs->trans("QCFrequency").'</td><td>'.$object->qc_frequency.'</td></tr>';
}
if (!$object->isService() && !empty($conf->bom->enabled)) {
print '<tr><td class="titlefield">'.$form->textwithpicto($langs->trans("DefaultBOM"), $langs->trans("DefaultBOMDesc")).'</td><td>';
if ($object->fk_default_bom) {
$bom_static = new BOM($db);
$bom_static->fetch($object->fk_default_bom);
print $bom_static->getNomUrl(1);
}
print '</td></tr>';
}
// Other attributes
$parameters = array();
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';

View File

@ -261,6 +261,13 @@ class Product extends CommonObject
*/
public $finished;
/**
* fk_default_bom indicates the default bom
*
* @var int
*/
public $fk_default_bom;
/**
* We must manage lot/batch number, sell-by date and so on : '1':yes '0':no
*
@ -1102,6 +1109,7 @@ class Product extends CommonObject
$sql .= ", batch_mask = '".$this->db->escape($this->batch_mask)."'";
$sql .= ", finished = ".((!isset($this->finished) || $this->finished < 0 || $this->finished == '') ? "null" : (int) $this->finished);
$sql .= ", fk_default_bom = ".((!isset($this->fk_default_bom) || $this->fk_default_bom < 0 || $this->fk_default_bom == '') ? "null" : (int) $this->fk_default_bom);
$sql .= ", net_measure = ".($this->net_measure != '' ? "'".$this->db->escape($this->net_measure)."'" : 'null');
$sql .= ", net_measure_units = ".($this->net_measure_units != '' ? "'".$this->db->escape($this->net_measure_units)."'" : 'null');
$sql .= ", weight = ".($this->weight != '' ? "'".$this->db->escape($this->weight)."'" : 'null');
@ -2244,7 +2252,7 @@ class Product extends CommonObject
$sql .= " p.price_min, p.price_min_ttc, p.price_base_type, p.cost_price, p.default_vat_code, p.tva_tx, p.recuperableonly as tva_npr, p.localtax1_tx, p.localtax2_tx, p.localtax1_type, p.localtax2_type, p.tosell,";
$sql .= " p.tobuy, p.fk_product_type, p.duration, p.fk_default_warehouse, p.seuil_stock_alerte, p.canvas, p.net_measure, p.net_measure_units, p.weight, p.weight_units,";
$sql .= " p.length, p.length_units, p.width, p.width_units, p.height, p.height_units,";
$sql .= " p.surface, p.surface_units, p.volume, p.volume_units, p.barcode, p.fk_barcode_type, p.finished,";
$sql .= " p.surface, p.surface_units, p.volume, p.volume_units, p.barcode, p.fk_barcode_type, p.finished, p.fk_default_bom,";
if (empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
$sql .= " p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export, p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,";
} else {
@ -2288,6 +2296,7 @@ class Product extends CommonObject
if ($separatedStock) {
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_stock as sp ON sp.fk_product = p.rowid AND sp.fk_entrepot IN (SELECT rowid FROM ".MAIN_DB_PREFIX."entrepot WHERE entity IN (".$this->db->sanitize($visibleWarehousesEntities)."))";
}
if ($id) {
$sql .= " WHERE p.rowid = ".((int) $id);
} else {
@ -2370,6 +2379,8 @@ class Product extends CommonObject
$this->localtax2_type = $obj->localtax2_type;
$this->finished = $obj->finished;
$this->fk_default_bom = $obj->fk_default_bom;
$this->duration = $obj->duration;
$this->duration_value = substr($obj->duration, 0, dol_strlen($obj->duration) - 1);
$this->duration_unit = substr($obj->duration, -1);