Debug MRP

This commit is contained in:
Laurent Destailleur 2020-01-07 22:17:40 +01:00
parent 622dc7e8d7
commit 20c9035837
4 changed files with 101 additions and 92 deletions

View File

@ -537,7 +537,7 @@ CREATE TABLE llx_mrp_production(
position integer NOT NULL DEFAULT 0,
fk_product integer NOT NULL,
fk_warehouse integer,
qty integer NOT NULL DEFAULT 1,
qty real NOT NULL DEFAULT 1,
qty_frozen smallint DEFAULT 0,
disable_stock_change smallint DEFAULT 0,
batch varchar(30),
@ -550,6 +550,7 @@ CREATE TABLE llx_mrp_production(
fk_user_modif integer,
import_key varchar(14)
) ENGINE=innodb;
ALTER TABLE llx_mrp_production MODIFY COLUMN qty real NOT NULL DEFAULT 1;
ALTER TABLE llx_mrp_production ADD COLUMN qty_frozen smallint DEFAULT 0;
ALTER TABLE llx_mrp_production ADD COLUMN disable_stock_change smallint DEFAULT 0;

View File

@ -20,7 +20,7 @@ CREATE TABLE llx_mrp_production(
position integer NOT NULL DEFAULT 0,
fk_product integer NOT NULL,
fk_warehouse integer,
qty integer NOT NULL DEFAULT 1,
qty real NOT NULL DEFAULT 1,
qty_frozen smallint DEFAULT 0,
disable_stock_change smallint DEFAULT 0,
batch varchar(30),

View File

@ -1331,7 +1331,7 @@ class MoLine extends CommonObjectLine
'position' =>array('type'=>'integer', 'label'=>'Position', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>20),
'fk_product' =>array('type'=>'integer', 'label'=>'Fk product', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>25),
'fk_warehouse' =>array('type'=>'integer', 'label'=>'Fk warehouse', 'enabled'=>1, 'visible'=>-1, 'position'=>30),
'qty' =>array('type'=>'integer', 'label'=>'Qty', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>35),
'qty' =>array('type'=>'real', 'label'=>'Qty', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>35),
'qty_frozen' => array('type'=>'smallint', 'label'=>'QuantityFrozen', 'enabled'=>1, 'visible'=>1, 'default'=>0, 'position'=>105, 'css'=>'maxwidth50imp', 'help'=>'QuantityConsumedInvariable'),
'disable_stock_change' => array('type'=>'smallint', 'label'=>'DisableStockChange', 'enabled'=>1, 'visible'=>1, 'default'=>0, 'position'=>108, 'css'=>'maxwidth50imp', 'help'=>'DisableStockChangeHelp'),
'batch' =>array('type'=>'varchar(30)', 'label'=>'Batch', 'enabled'=>1, 'visible'=>-1, 'position'=>140),

View File

@ -173,55 +173,59 @@ if (empty($reshook))
$i=1;
while (GETPOSTISSET('qty-'.$line->id.'-'.$i)) {
// Check warehouse is set if we should have to
if (GETPOSTISSET('idwarehouse-'.$line->id.'-'.$i)) { // If there is a warehouse to set
if (price2num(GETPOST('qty-'.$line->id.'-'.$i)) > 0 && ! (GETPOST('idwarehouse-'.$line->id.'-'.$i) > 0)) { // If there is a quantity to dispatch and warehouse not set.
$langs->load("errors");
setEventMessages($langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Warehouse"), $tmpproduct->ref), null, 'errors');
$error++;
}
if ($tmpproduct->status_batch && (! GETPOST('batch-'.$line->id.'-'.$i))) {
$langs->load("errors");
setEventMessages($langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Batch"), $tmpproduct->ref), null, 'errors');
$error++;
}
}
$qtytoprocess = price2num(GETPOST('qty-'.$line->id.'-'.$i));
$idstockmove = 0;
if (! $error && GETPOST('idwarehouse-'.$line->id.'-'.$i) > 0) {
// Record stock movement
$id_product_batch = 0;
$stockmove->origin = $object;
$idstockmove = $stockmove->livraison($user, $line->fk_product, GETPOST('idwarehouse-'.$line->id.'-'.$i), price2num(GETPOST('qty-'.$line->id.'-'.$i)), 0, $labelmovement, dol_now(), '', '', GETPOST('batch-'.$line->id.'-'.$i), $id_product_batch, $codemovement);
if ($idstockmove < 0) {
$error++;
setEventMessages($stockmove->error, $stockmove->errors, 'errors');
}
}
if ($qtytoprocess != 0) {
// Check warehouse is set if we should have to
if (GETPOSTISSET('idwarehouse-'.$line->id.'-'.$i)) { // If there is a warehouse to set
if (! (GETPOST('idwarehouse-'.$line->id.'-'.$i) > 0)) { // If there is no warehouse set.
$langs->load("errors");
setEventMessages($langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Warehouse"), $tmpproduct->ref), null, 'errors');
$error++;
}
if ($tmpproduct->status_batch && (! GETPOST('batch-'.$line->id.'-'.$i))) {
$langs->load("errors");
setEventMessages($langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Batch"), $tmpproduct->ref), null, 'errors');
$error++;
}
}
if (! $error) {
$pos = 0;
// Record consumption
$moline = new MoLine($db);
$moline->fk_mo = $object->id;
$moline->position = $pos;
$moline->fk_product = $line->fk_product;
$moline->fk_warehouse = GETPOST('idwarehouse-'.$line->id.'-'.$i);
$moline->qty = price2num(GETPOST('qty-'.$line->id.'-'.$i));
$moline->batch = GETPOST('batch-'.$line->id.'-'.$i);
$moline->role = 'consumed';
$moline->fk_mrp_production = $line->id;
$moline->fk_stock_movement = $idstockmove;
$moline->fk_user_creat = $user->id;
$idstockmove = 0;
if (! $error && GETPOST('idwarehouse-'.$line->id.'-'.$i) > 0) {
// Record stock movement
$id_product_batch = 0;
$stockmove->origin = $object;
$idstockmove = $stockmove->livraison($user, $line->fk_product, GETPOST('idwarehouse-'.$line->id.'-'.$i), $qtytoprocess, 0, $labelmovement, dol_now(), '', '', GETPOST('batch-'.$line->id.'-'.$i), $id_product_batch, $codemovement);
if ($idstockmove < 0) {
$error++;
setEventMessages($stockmove->error, $stockmove->errors, 'errors');
}
}
$resultmoline = $moline->create($user);
if ($resultmoline <= 0) {
$error++;
setEventMessages($moline->error, $moline->errors, 'errors');
}
if (! $error) {
$pos = 0;
// Record consumption
$moline = new MoLine($db);
$moline->fk_mo = $object->id;
$moline->position = $pos;
$moline->fk_product = $line->fk_product;
$moline->fk_warehouse = GETPOST('idwarehouse-'.$line->id.'-'.$i);
$moline->qty = $qtytoprocess;
$moline->batch = GETPOST('batch-'.$line->id.'-'.$i);
$moline->role = 'consumed';
$moline->fk_mrp_production = $line->id;
$moline->fk_stock_movement = $idstockmove;
$moline->fk_user_creat = $user->id;
$pos++;
}
$resultmoline = $moline->create($user);
if ($resultmoline <= 0) {
$error++;
setEventMessages($moline->error, $moline->errors, 'errors');
}
$pos++;
}
}
$i++;
}
@ -236,54 +240,58 @@ if (empty($reshook))
$i=1;
while (GETPOSTISSET('qtytoproduce-'.$line->id.'-'.$i)) {
// Check warehouse is set if we should have to
if (GETPOSTISSET('idwarehousetoproduce-'.$line->id.'-'.$i)) { // If there is a warehouse to set
if (price2num(GETPOST('qtytoproduce-'.$line->id.'-'.$i)) > 0 && ! (GETPOST('idwarehousetoproduce-'.$line->id.'-'.$i) > 0)) { // If there is a quantity to dispatch and warehouse not set.
$langs->load("errors");
setEventMessages($langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Warehouse"), $tmpproduct->ref), null, 'errors');
$error++;
}
if ($tmpproduct->status_batch && (! GETPOST('batchtoproduce-'.$line->id.'-'.$i))) {
$langs->load("errors");
setEventMessages($langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Batch"), $tmpproduct->ref), null, 'errors');
$error++;
}
}
$qtytoprocess = price2num(GETPOST('qtytoproduce-'.$line->id.'-'.$i));
$idstockmove = 0;
if (! $error && GETPOST('idwarehousetoproduce-'.$line->id.'-'.$i) > 0) {
// Record stock movement
$id_product_batch = 0;
$stockmove->origin = $object;
$idstockmove = $stockmove->reception($user, $line->fk_product, GETPOST('idwarehousetoproduce-'.$line->id.'-'.$i), price2num(GETPOST('qtytoproduce-'.$line->id.'-'.$i)), 0, $labelmovement, dol_now(), '', '', GETPOST('batchtoproduce-'.$line->id.'-'.$i), $id_product_batch, $codemovement);
if ($idstockmove < 0) {
$error++;
setEventMessages($stockmove->error, $stockmove->errors, 'errors');
}
}
if ($qtytoprocess != 0) {
// Check warehouse is set if we should have to
if (GETPOSTISSET('idwarehousetoproduce-'.$line->id.'-'.$i)) { // If there is a warehouse to set
if (! (GETPOST('idwarehousetoproduce-'.$line->id.'-'.$i) > 0)) { // If there is no warehouse set.
$langs->load("errors");
setEventMessages($langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Warehouse"), $tmpproduct->ref), null, 'errors');
$error++;
}
if ($tmpproduct->status_batch && (! GETPOST('batchtoproduce-'.$line->id.'-'.$i))) {
$langs->load("errors");
setEventMessages($langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Batch"), $tmpproduct->ref), null, 'errors');
$error++;
}
}
if (! $error) {
$pos = 0;
// Record production
$moline = new MoLine($db);
$moline->fk_mo = $object->id;
$moline->position = $pos;
$moline->fk_product = $line->fk_product;
$moline->fk_warehouse = GETPOST('idwarehousetoproduce-'.$line->id.'-'.$i);
$moline->qty = price2num(GETPOST('qtytoproduce-'.$line->id.'-'.$i));
$moline->batch = GETPOST('batchtoproduce-'.$line->id.'-'.$i);
$moline->role = 'produced';
$moline->fk_mrp_production = $line->id;
$moline->fk_stock_movement = $idstockmove;
$moline->fk_user_creat = $user->id;
$idstockmove = 0;
if (! $error && GETPOST('idwarehousetoproduce-'.$line->id.'-'.$i) > 0) {
// Record stock movement
$id_product_batch = 0;
$stockmove->origin = $object;
$idstockmove = $stockmove->reception($user, $line->fk_product, GETPOST('idwarehousetoproduce-'.$line->id.'-'.$i), $qtytoprocess, 0, $labelmovement, dol_now(), '', '', GETPOST('batchtoproduce-'.$line->id.'-'.$i), $id_product_batch, $codemovement);
if ($idstockmove < 0) {
$error++;
setEventMessages($stockmove->error, $stockmove->errors, 'errors');
}
}
$resultmoline = $moline->create($user);
if ($resultmoline <= 0) {
$error++;
setEventMessages($moline->error, $moline->errors, 'errors');
}
if (! $error) {
$pos = 0;
// Record production
$moline = new MoLine($db);
$moline->fk_mo = $object->id;
$moline->position = $pos;
$moline->fk_product = $line->fk_product;
$moline->fk_warehouse = GETPOST('idwarehousetoproduce-'.$line->id.'-'.$i);
$moline->qty = $qtytoprocess;
$moline->batch = GETPOST('batchtoproduce-'.$line->id.'-'.$i);
$moline->role = 'produced';
$moline->fk_mrp_production = $line->id;
$moline->fk_stock_movement = $idstockmove;
$moline->fk_user_creat = $user->id;
$pos++;
$resultmoline = $moline->create($user);
if ($resultmoline <= 0) {
$error++;
setEventMessages($moline->error, $moline->errors, 'errors');
}
$pos++;
}
}
$i++;