Merge pull request #13426 from TobiasSekan/FixSupplierProposalMulticurrency

FIX not working add/change supplier proposal line with multi-currency value
This commit is contained in:
Laurent Destailleur 2020-03-30 19:00:08 +02:00 committed by GitHub
commit 593a78dda7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 16 deletions

View File

@ -11,6 +11,7 @@
* Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es> * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr> * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -715,7 +716,7 @@ if (empty($reshook))
setEventMessages($langs->trans("ErrorQtyTooLowForThisSupplier"), null, 'errors'); setEventMessages($langs->trans("ErrorQtyTooLowForThisSupplier"), null, 'errors');
} }
} }
elseif ((GETPOST('price_ht') !== '' || GETPOST('price_ttc') !== '') && empty($error)) // Free product. // $price_ht is already set elseif ((GETPOST('price_ht') !== '' || GETPOST('price_ttc') !== '' || GETPOST('multicurrency_price_ht') != '') && empty($error)) // Free product. // $price_ht is already set
{ {
$pu_ht = price2num($price_ht, 'MU'); $pu_ht = price2num($price_ht, 'MU');
$pu_ttc = price2num(GETPOST('price_ttc'), 'MU'); $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
@ -745,8 +746,31 @@ if (empty($reshook))
$price_base_type = 'HT'; $price_base_type = 'HT';
$pu_ht_devise = price2num($price_ht_devise, 'MU'); $pu_ht_devise = price2num($price_ht_devise, 'MU');
$result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $pu_ttc, $info_bits, $type, - 1, 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $array_options, $ref_supplier, $fk_unit); $result = $object->addline(
//$result = $object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, $ttc, $type,'','', $date_start, $date_end, $array_options, $fk_unit); $desc,
$pu_ht,
$qty,
$tva_tx,
$localtax1_tx,
$localtax2_tx,
$idprod,
$remise_percent,
$price_base_type,
$pu_ttc,
$info_bits,
$type,
-1, // rang
0, // special_code
GETPOST('fk_parent_line'),
$fournprice,
$buyingprice,
$label,
$array_options,
$ref_supplier,
$fk_unit,
'', // origin
0, // origin_id
$pu_ht_devise);
} }
@ -839,10 +863,10 @@ if (empty($reshook))
if (GETPOST('price_ht') != '') if (GETPOST('price_ht') != '')
{ {
$price_base_type = 'HT';
$ht = price2num(GETPOST('price_ht')); $ht = price2num(GETPOST('price_ht'));
} }
else
if (GETPOST('price_ttc') != '')
{ {
$reg = array(); $reg = array();
$vatratecleaned = $vat_rate; $vatratecleaned = $vat_rate;
@ -854,9 +878,9 @@ if (empty($reshook))
$ttc = price2num(GETPOST('price_ttc')); $ttc = price2num(GETPOST('price_ttc'));
$ht = $ttc / (1 + ($vatratecleaned / 100)); $ht = $ttc / (1 + ($vatratecleaned / 100));
$price_base_type = 'HT';
} }
$price_base_type = 'HT';
$pu_ht_devise = GETPOST('multicurrency_subprice'); $pu_ht_devise = GETPOST('multicurrency_subprice');
// Add buying price // Add buying price

View File

@ -14,6 +14,7 @@
* Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es> * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com> * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr> * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -708,6 +709,10 @@ class SupplierProposal extends CommonObject
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
} }
if ($conf->multicurrency->enabled && $pu_ht_devise > 0) {
$pu = 0;
}
$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise); $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
$total_ht = $tabprice[0]; $total_ht = $tabprice[0];
$total_tva = $tabprice[1]; $total_tva = $tabprice[1];
@ -719,6 +724,7 @@ class SupplierProposal extends CommonObject
$multicurrency_total_ht = $tabprice[16]; $multicurrency_total_ht = $tabprice[16];
$multicurrency_total_tva = $tabprice[17]; $multicurrency_total_tva = $tabprice[17];
$multicurrency_total_ttc = $tabprice[18]; $multicurrency_total_ttc = $tabprice[18];
$pu_ht_devise = $tabprice[19];
//Fetch current line from the database and then clone the object and set it in $oldline property //Fetch current line from the database and then clone the object and set it in $oldline property
$line = new SupplierProposalLine($this->db); $line = new SupplierProposalLine($this->db);
@ -785,7 +791,7 @@ class SupplierProposal extends CommonObject
} }
// Multicurrency // Multicurrency
$this->line->multicurrency_subprice = price2num($pu * $this->multicurrency_tx); $this->line->multicurrency_subprice = $pu_ht_devise;
$this->line->multicurrency_total_ht = $multicurrency_total_ht; $this->line->multicurrency_total_ht = $multicurrency_total_ht;
$this->line->multicurrency_total_tva = $multicurrency_total_tva; $this->line->multicurrency_total_tva = $multicurrency_total_tva;
$this->line->multicurrency_total_ttc = $multicurrency_total_ttc; $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;