Use new origin field to mark free lines.

Allow add free line when production started
This commit is contained in:
Francis Appels 2021-02-02 11:19:58 +01:00
parent 45970ac443
commit 731ca02789
2 changed files with 13 additions and 6 deletions

View File

@ -655,6 +655,8 @@ class Mo extends CommonObject
$moline = new MoLine($this->db);
$moline->fk_mo = $this->id;
$moline->origin_id = $line->id;
$moline->origin_type = 'bom';
if ($line->qty_frozen) {
$moline->qty = $line->qty; // Qty to consume does not depends on quantity to produce
} else {
@ -1386,6 +1388,8 @@ class MoLine extends CommonObjectLine
public $fields = array(
'rowid' =>array('type'=>'integer', 'label'=>'ID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10),
'fk_mo' =>array('type'=>'integer', 'label'=>'Mo', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>15),
'origin_id' =>array('type'=>'integer', 'label'=>'Origin', 'enabled'=>1, 'visible'=>-1, 'notnull'=>0, 'position'=>17),
'origin_type' =>array('type'=>'varchar(10)', 'label'=>'Origin type', 'enabled'=>1, 'visible'=>-1, 'notnull'=>0, 'position'=>18),
'position' =>array('type'=>'integer', 'label'=>'Position', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>20),
'fk_product' =>array('type'=>'integer', 'label'=>'Product', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>25),
'fk_warehouse' =>array('type'=>'integer', 'label'=>'Warehouse', 'enabled'=>1, 'visible'=>-1, 'position'=>30),
@ -1405,6 +1409,8 @@ class MoLine extends CommonObjectLine
public $rowid;
public $fk_mo;
public $origin_id;
public $origin_type;
public $position;
public $fk_product;
public $fk_warehouse;

View File

@ -151,7 +151,8 @@ if (empty($reshook))
$moline->fk_mo = $object->id;
$moline->qty = GETPOST('qtytoadd', 'int'); ;
$moline->fk_product = GETPOST('productidtoadd', 'int');
$moline->role = 'toconsumef'; // free consume line
$moline->role = 'toconsume';
$moline->origin_type = 'free'; // free consume line
$moline->position = 0;
$resultline = $moline->create($user, false); // Never use triggers here
@ -173,7 +174,7 @@ if (empty($reshook))
$pos = 0;
// Process line to consume
foreach ($object->lines as $line) {
if (preg_match('/toconsume/', $line->role)) {
if ($line->role == 'toconsume') {
$tmpproduct = new Product($db);
$tmpproduct->fetch($line->fk_product);
@ -311,7 +312,7 @@ if (empty($reshook))
if (GETPOST('autoclose', 'int')) {
foreach ($object->lines as $line) {
if (preg_match('/toconsume/', $line->role)) {
if ($line->role == 'toconsume') {
$arrayoflines = $object->fetchLinesLinked('consumed', $line->id);
$alreadyconsumed = 0;
foreach ($arrayoflines as $line2) {
@ -695,7 +696,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '<div class="clearboth"></div>';
$newlinetext = '';
if (($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_VALIDATED) && $action != 'consumeorproduce' && $action != 'consumeandproduceall') {
if ($object->status != $object::STATUS_PRODUCED && $object->status != $object::STATUS_CANCELED && $action != 'consumeorproduce' && $action != 'consumeandproduceall') {
$newlinetext = '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=addconsumeline">'.$langs->trans("AddNewConsumeLines").'</a>';
}
print load_fiche_titre($langs->trans('Consumption'), '', '', 0, '', '', $newlinetext);
@ -749,13 +750,13 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
$nblinetoconsumecursor = 0;
foreach ($object->lines as $line) {
if (preg_match('/toconsume/', $line->role)) {
if ($line->role == 'toconsume') {
$nblinetoconsumecursor++;
$tmpproduct = new Product($db);
$tmpproduct->fetch($line->fk_product);
if (!empty($bomcost) && $line->role == 'toconsumef' && $object->qty > 0) {
if ($line->origin_type == 'free' && $object->qty > 0) {
// add free consume line cost to bomcost
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
$productFournisseur = new ProductFournisseur($db);