Skip to content

Commit

Permalink
Debug BOM module
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed May 25, 2019
1 parent a5865d3 commit 9f9f3bd
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 46 deletions.
34 changes: 33 additions & 1 deletion htdocs/bom/bom_card.php
Expand Up @@ -110,8 +110,40 @@
$autocopy='MAIN_MAIL_AUTOCOPY_BOM_TO';
$trackid='bom'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
}

// Add line
if ($action == 'addline' && $user->rights->bom->write)
{
$langs->load('errors');
$error = 0;

// Set if we used free entry or predefined product
$idprod=GETPOST('idprod', 'int');
$qty=GETPOST('qty', 'int');
$efficiency=GETPOST('efficiency', 'int');

if ($qty == '') {
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
$error++;
}
if (! ($idprod > 0)) {
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Product')), null, 'errors');
$error++;
}

$bomline = new BOMLine($db);
$bomline->fk_bom = $id;
$bomline->fk_product = $prodid;
$bomline->qty = $qty;
$bomline->efficiency = $efficiency;

$result = $bomline->create($user);
if ($result <= 0)
{
setEventMessages($bomline->error, $bomline->errors, 'errors');
}
}
}


/*
Expand Down
18 changes: 10 additions & 8 deletions htdocs/bom/class/bom.class.php
Expand Up @@ -946,7 +946,7 @@ class BOMLine extends CommonObject
/**
* @var string String with name of icon for bomline. Must be the part after the 'object_' into object_bomline.png
*/
public $picto = 'bomline@bom';
public $picto = 'bomline';


/**
Expand Down Expand Up @@ -974,20 +974,22 @@ class BOMLine extends CommonObject
*/
public $fields=array(
'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>"Id",),
'fk_bom' => array('type'=>'integer:BillOfMaterials:societe/class/bom.class.php', 'label'=>'BillOfMaterials', 'enabled'=>1, 'visible'=>1, 'position'=>10, 'notnull'=>-1, 'index'=>1,),
'fk_product' => array('type'=>'integer:Product:product/class/product.class.php', 'label'=>'Product', 'enabled'=>1, 'visible'=>1, 'position'=>20, 'notnull'=>-1, 'index'=>1,),
'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>1, 'visible'=>-1, 'position'=>60, 'notnull'=>-1,),
'qty' => array('type'=>'double(24,8)', 'label'=>'Quantity', 'enabled'=>1, 'visible'=>1, 'position'=>100, 'notnull'=>-1, 'isameasure'=>'1',),
'efficiency' => array('type'=>'double(8,4)', 'label'=>'ManufacturingEfficiency', 'enabled'=>1, 'visible'=>1, 'default'=>1, 'position'=>110, 'notnull'=>0, 'css'=>'maxwidth50imp', 'help'=>'ValueOfMeansLoss'),
'rank' => array('type'=>'integer', 'label'=>'Rank', 'enabled'=>1, 'visible'=>0, 'position'=>200, 'notnull'=>1,),
'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>1000, 'notnull'=>-1,),
'qty' => array('type'=>'double(24,8)', 'label'=>'Quantity', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'notnull'=>-1, 'isameasure'=>'1',),
'fk_product' => array('type'=>'integer:Product:product/class/product.class.php', 'label'=>'Product', 'enabled'=>1, 'visible'=>1, 'position'=>20, 'notnull'=>-1, 'index'=>1,),
'fk_bom' => array('type'=>'integer:BillOfMaterials:societe/class/bom.class.php', 'label'=>'BillOfMaterials', 'enabled'=>1, 'visible'=>1, 'position'=>10, 'notnull'=>-1, 'index'=>1,),
'rank' => array('type'=>'integer', 'label'=>'Rank', 'enabled'=>1, 'visible'=>0, 'position'=>40, 'notnull'=>1,),
);
public $rowid;
public $fk_bom;
public $fk_product;
public $description;
public $import_key;
public $qty;
public $fk_product;
public $fk_bom;
public $efficiency;
public $rank;
public $import_key;
// END MODULEBUILDER PROPERTIES


Expand Down
37 changes: 5 additions & 32 deletions htdocs/bom/tpl/objectline_create.tpl.php
Expand Up @@ -81,7 +81,7 @@
print '</span></td>';
}
?>
<td class="linecollost right"><?php echo $langs->trans('Lost'); ?></td>
<td class="linecollost right"><?php echo $langs->trans('ManufacturingEfficiency'); ?></td>
<td class="linecoledit" colspan="<?php echo $colspan; ?>">&nbsp;</td>
</tr>
<?php
Expand Down Expand Up @@ -144,7 +144,7 @@

$coldisplay++;
?>
<td class="nobottom nowrap linecollost right"><input type="text" size="1" name="lost" id="lost" class="flat right" value="<?php echo (isset($_POST["lsot"])?GETPOST("lost", 'alpha', 2):$remise_percent); ?>"><span class="hideonsmartphone">%</span></td>
<td class="nobottom nowrap linecollost right"><input type="text" size="1" name="efficiency" id="efficiency" class="flat right" value="<?php echo (GETPOSTISSET("efficiency")?GETPOST("efficiency", 'alpha'):1); ?>"></td>
<?php

$coldisplay+=$colspan;
Expand All @@ -165,39 +165,12 @@
/* JQuery for product free or predefined select */
jQuery(document).ready(function() {
/* When changing predefined product, we reload list of supplier prices required for margin combo */
$("#idprod, #idprodfournprice").change(function()
$("#idprod").change(function()
{
console.log("#idprod, #idprodfournprice change triggered");

setforpredef(); // TODO Keep vat combo visible and set it to first entry into list that match result of get_default_tva

jQuery('#trlinefordates').show();

/* To process customer price per quantity */
var pbq = parseInt($('option:selected', this).attr('data-pbq'));
var pbqqty = parseFloat($('option:selected', this).attr('data-pbqqty'));
var pbqpercent = parseFloat($('option:selected', this).attr('data-pbqpercent'));

if ((jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val()) && typeof pbq !== "undefined")
{
console.log("We choose a price by quanty price_by_qty id = "+pbq+" price_by_qty qty = "+pbqqty+" price_by_qty percent = "+pbqpercent);
jQuery("#pbq").val(pbq);
if (jQuery("#qty").val() < pbqqty)
{
jQuery("#qty").val(pbqqty);
}
if (jQuery("#remise_percent").val() < pbqpercent)
{
jQuery("#remise_percent").val(pbqpercent);
}
}
else
{
jQuery("#pbq").val('');
}
console.log("#idprod change triggered");

/* To set focus */
if (jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val() > 0)
if (jQuery('#idprod').val() > 0)
{
/* focus work on a standard textarea but not if field was replaced with CKEDITOR */
jQuery('#dp_desc').focus();
Expand Down
10 changes: 7 additions & 3 deletions htdocs/install/mysql/migration/9.0.0-10.0.0.sql
Expand Up @@ -226,7 +226,7 @@ CREATE TABLE llx_bom_bom(
-- END MODULEBUILDER FIELDS
) ENGINE=innodb;

ALTER TABLE llx_bom_bom ADD COLUMN efficiency double(24,8) DEFAULT 1;
ALTER TABLE llx_bom_bom ADD COLUMN efficiency double(8,4) DEFAULT 1;

create table llx_bom_bom_extrafields
(
Expand All @@ -239,15 +239,19 @@ create table llx_bom_bom_extrafields
CREATE TABLE llx_bom_bomline(
-- BEGIN MODULEBUILDER FIELDS
rowid integer AUTO_INCREMENT PRIMARY KEY NOT NULL,
fk_bom integer,
fk_product integer,
description text,
import_key varchar(14),
qty double(24,8),
fk_product integer,
fk_bom integer,
efficiency double(8,4) DEFAULT 1,
rank integer NOT NULL
-- END MODULEBUILDER FIELDS
) ENGINE=innodb;

ALTER TABLE llx_bom_bomline ADD COLUMN efficiency double(8,4) DEFAULT 1;


create table llx_bom_bomline_extrafields
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
Expand Down
5 changes: 3 additions & 2 deletions htdocs/install/mysql/tables/llx_bom_bomline.sql
Expand Up @@ -17,11 +17,12 @@
CREATE TABLE llx_bom_bomline(
-- BEGIN MODULEBUILDER FIELDS
rowid integer AUTO_INCREMENT PRIMARY KEY NOT NULL,
fk_bom integer,
fk_product integer,
description text,
import_key varchar(14),
qty double(24,8),
fk_product integer,
fk_bom integer,
efficiency double(8,4) DEFAULT 1,
rank integer NOT NULL
-- END MODULEBUILDER FIELDS
) ENGINE=innodb;

1 comment on commit 9f9f3bd

@homer8173
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @eldy
in previous version, there were having a rank field in the bomline table.
The migration script doesn't seem to delete it.
I haven't double check, but only my new installed Dol10 works, all migrated aren't able to insert new line in BOM.

Please sign in to comment.