Merge pull request #18795 from Hystepik/develop#4

NEW #18770 : Can enter the buying price (for Weighted Average Price update) on lines during the reception step
This commit is contained in:
Laurent Destailleur 2021-09-28 13:24:41 +02:00 committed by GitHub
commit 107b3286c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 10 deletions

View File

@ -103,6 +103,7 @@ class CommandeFournisseurDispatch extends CommonObjectLine
public $batch;
public $eatby = '';
public $sellby = '';
public $cost_price = 0;
@ -189,7 +190,8 @@ class CommandeFournisseurDispatch extends CommonObjectLine
$sql .= "batch,";
$sql .= "eatby,";
$sql .= "sellby,";
$sql .= "fk_reception";
$sql .= "fk_reception,";
$sql .= "cost_price";
$sql .= ") VALUES (";
@ -205,7 +207,8 @@ class CommandeFournisseurDispatch extends CommonObjectLine
$sql .= " ".(!isset($this->batch) ? 'NULL' : "'".$this->db->escape($this->batch)."'").",";
$sql .= " ".(!isset($this->eatby) || dol_strlen($this->eatby) == 0 ? 'NULL' : "'".$this->db->idate($this->eatby)."'").",";
$sql .= " ".(!isset($this->sellby) || dol_strlen($this->sellby) == 0 ? 'NULL' : "'".$this->db->idate($this->sellby)."'").",";
$sql .= " ".(!isset($this->fk_reception) ? 'NULL' : "'".$this->db->escape($this->fk_reception)."'")."";
$sql .= " ".(!isset($this->fk_reception) ? 'NULL' : "'".$this->db->escape($this->fk_reception)."'").",";
$sql .= " ".(!isset($this->cost_price) ? '0' : "'".$this->db->escape($this->cost_price)."'")."";
$sql .= ")";
$this->db->begin();

View File

@ -134,6 +134,8 @@ ALTER TABLE llx_product_lot ADD COLUMN fk_barcode_type integer DEFAULT NULL;
ALTER TABLE llx_projet ADD COLUMN max_attendees integer DEFAULT 0;
ALTER TABLE llx_commande_fournisseur_dispatch ADD COLUMN cost_price double(24,8) DEFAULT 0;
INSERT INTO llx_c_forme_juridique (fk_pays, code, libelle) VALUES (20, '2001', 'Aktiebolag');
INSERT INTO llx_c_forme_juridique (fk_pays, code, libelle) VALUES (20, '2002', 'Publikt aktiebolag (AB publ)');
INSERT INTO llx_c_forme_juridique (fk_pays, code, libelle) VALUES (20, '2003', 'Ekonomisk förening (ek. för.)');
@ -146,3 +148,4 @@ INSERT INTO llx_c_forme_juridique (fk_pays, code, libelle) VALUES (20, '2009', '
INSERT INTO llx_c_forme_juridique (fk_pays, code, libelle) VALUES (20, '2010', 'Enkelt bolag');
INSERT INTO llx_c_forme_juridique (fk_pays, code, libelle) VALUES (20, '2011', 'Ideell förening');
INSERT INTO llx_c_forme_juridique (fk_pays, code, libelle) VALUES (20, '2012', 'Stiftelse');

View File

@ -36,5 +36,6 @@ create table llx_commande_fournisseur_dispatch
sellby date DEFAULT NULL,
status integer,
datec datetime,
tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
cost_price double(24,8) DEFAULT 0
)ENGINE=innodb;

View File

@ -45,3 +45,4 @@ ReceptionsNumberingModules=Numbering module for receptions
ReceptionsReceiptModel=Document templates for receptions
NoMorePredefinedProductToDispatch=No more predefined products to dispatch
ReceptionExist=A reception exists
ByingPrice=Bying price

View File

@ -45,3 +45,4 @@ ReceptionsNumberingModules=Module de numérotation pour les réceptions
ReceptionsReceiptModel=Modèles de document pour les réceptions
NoMorePredefinedProductToDispatch=Plus de produits prédéfinis à expédier
ReceptionExist=Une réception existe
ByingPrice=Prix d'achat

View File

@ -340,6 +340,7 @@ if (empty($reshook)) {
$eatby = "dlc".$i;
$sellby = "dluo".$i;
$batch = "batch".$i;
$cost_price = "cost_price".$i;
if (GETPOST($qty, 'int') > 0 || (GETPOST($qty, 'int') == 0 && $conf->global->RECEPTION_GETS_ALL_ORDER_PRODUCTS)) {
$ent = "entl".$i;
@ -364,8 +365,11 @@ if (empty($reshook)) {
$sellby = GETPOST($sellby, 'alpha');
$eatbydate = str_replace('/', '-', $eatby);
$sellbydate = str_replace('/', '-', $sellby);
$ret = $object->addline($entrepot_id, GETPOST($idl, 'int'), GETPOST($qty, 'int'), $array_options[$i], GETPOST($comment, 'alpha'), strtotime($eatbydate), strtotime($sellbydate), GETPOST($batch, 'alpha'));
if (!empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
$ret = $object->addline($entrepot_id, GETPOST($idl, 'int'), GETPOST($qty, 'int'), $array_options[$i], GETPOST($comment, 'alpha'), strtotime($eatbydate), strtotime($sellbydate), GETPOST($batch, 'alpha'), price2num(GETPOST($cost_price, 'double'), 'MU'));
} else {
$ret = $object->addline($entrepot_id, GETPOST($idl, 'int'), GETPOST($qty, 'int'), $array_options[$i], GETPOST($comment, 'alpha'), strtotime($eatbydate), strtotime($sellbydate), GETPOST($batch, 'alpha'));
}
if ($ret < 0) {
setEventMessages($object->error, $object->errors, 'errors');
$error++;
@ -989,6 +993,9 @@ if ($action == 'create') {
print '<td class="center">'.$langs->trans("QtyOrdered").'</td>';
print '<td class="center">'.$langs->trans("QtyReceived").'</td>';
print '<td class="center">'.$langs->trans("QtyToReceive");
if (!empty($conf->global->STOCK_CALCULATE_ON_RECEPTION || $conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
print '<td>'.$langs->trans("ByingPrice").'</td>';
}
if (empty($conf->productbatch->enabled)) {
print ' <br>(<a href="#" id="autofill">'.$langs->trans("Fill").'</a>';
print ' / <a href="#" id="autoreset">'.$langs->trans("Reset").'</a>)';
@ -1118,6 +1125,7 @@ if ($action == 'create') {
$stock = + $product->stock_warehouse[$dispatchLines[$indiceAsked]['ent']]->real; // Convert to number
$deliverableQty = $dispatchLines[$indiceAsked]['qty'];
$cost_price = $dispatchLines[$indiceAsked]['pu'];
// Quantity to send
print '<td class="center">';
@ -1132,6 +1140,12 @@ if ($action == 'create') {
}
print '</td>';
if (!empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
print '<td>';
print '<input name="cost_price'.$indiceAsked.'" id="cost_price'.$indiceAsked.'" value="'.$cost_price.'">';
print '</td>';
}
// Stock
if (!empty($conf->stock->enabled)) {
print '<td class="left">';

View File

@ -561,7 +561,8 @@ class Reception extends CommonObject
// TODO in future, reception lines may not be linked to order line
$sql = "SELECT cd.fk_product, cd.subprice,";
$sql .= " ed.rowid, ed.qty, ed.fk_entrepot,";
$sql .= " ed.eatby, ed.sellby, ed.batch";
$sql .= " ed.eatby, ed.sellby, ed.batch,";
$sql .= " ed.cost_price";
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
$sql .= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
$sql .= " WHERE ed.fk_reception = ".((int) $this->id);
@ -589,7 +590,11 @@ class Reception extends CommonObject
// line without batch detail
// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record.
$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionValidatedInDolibarr", $numref));
if (!empty($conf->global->STOCK_CALCULATE_ON_RECEPTION || $conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans("ReceptionValidatedInDolibarr", $numref));
} else {
$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionValidatedInDolibarr", $numref));
}
if ($result < 0) {
$error++;
$this->errors[] = $mouvS->error;
@ -601,7 +606,11 @@ class Reception extends CommonObject
// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record.
// Note: ->fk_origin_stock = id into table llx_product_batch (may be rename into llx_product_stock_batch in another version)
$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionValidatedInDolibarr", $numref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch);
if (!empty($conf->global->STOCK_CALCULATE_ON_RECEPTION || $conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans("ReceptionValidatedInDolibarr", $numref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch);
} else {
$result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionValidatedInDolibarr", $numref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch);
}
if ($result < 0) {
$error++;
$this->errors[] = $mouvS->error;
@ -704,9 +713,10 @@ class Reception extends CommonObject
* @param integer $eatby eat-by date
* @param integer $sellby sell-by date
* @param string $batch Lot number
* @param double $cost_price Line cost
* @return int <0 if KO, index of line if OK
*/
public function addline($entrepot_id, $id, $qty, $array_options = 0, $comment = '', $eatby = '', $sellby = '', $batch = '')
public function addline($entrepot_id, $id, $qty, $array_options = 0, $comment = '', $eatby = '', $sellby = '', $batch = '', $cost_price = 0)
{
global $conf, $langs, $user;
@ -746,8 +756,8 @@ class Reception extends CommonObject
$line->eatby = $eatby;
$line->sellby = $sellby;
$line->status = 1;
$line->cost_price = $cost_price;
$line->fk_reception = $this->id;
$this->lines[$num] = $line;
return $num;