Fix: Load priceparser only if required.

This commit is contained in:
Laurent Destailleur 2015-02-01 15:08:56 +01:00
parent 968b2b433b
commit 9285897759
3 changed files with 17 additions and 15 deletions

View File

@ -20,7 +20,7 @@
/** /**
* \file htdocs/product/class/priceexpression.class.php * \file htdocs/product/class/priceexpression.class.php
* \ingroup product * \ingroup product
* \brief Class for accesing price expression table * \brief Class for accessing price expression table
*/ */

View File

@ -21,7 +21,6 @@
* \brief File of class to calculate prices using expression * \brief File of class to calculate prices using expression
*/ */
require_once DOL_DOCUMENT_ROOT.'/includes/evalmath/evalmath.class.php'; require_once DOL_DOCUMENT_ROOT.'/includes/evalmath/evalmath.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/priceexpression.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/priceexpression.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
@ -267,7 +266,7 @@ class PriceParser
public function parseProductSupplierExpression($product_id, $expression, $quantity = null, $tva_tx = null, $extra_values = array()) public function parseProductSupplierExpression($product_id, $expression, $quantity = null, $tva_tx = null, $extra_values = array())
{ {
//Get the product data //Get the product data
$product = new Product($this->db); $product = new ProductFournisseur($this->db);
$product->fetch($product_id, '', '', 1); $product->fetch($product_id, '', '', 1);
//Accessible values by expressions //Accessible values by expressions

View File

@ -33,7 +33,6 @@
*/ */
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/priceparser.class.php';
/** /**
@ -1175,7 +1174,6 @@ class Product extends CommonObject
*/ */
function get_buyprice($prodfournprice,$qty,$product_id=0,$fourn_ref=0) function get_buyprice($prodfournprice,$qty,$product_id=0,$fourn_ref=0)
{ {
require_once DOL_DOCUMENT_ROOT.'/product/class/priceparser.class.php';
$result = 0; $result = 0;
// We do select by searching with qty and prodfournprice // We do select by searching with qty and prodfournprice
@ -1192,8 +1190,10 @@ class Product extends CommonObject
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
if ($obj && $obj->quantity > 0) // If found if ($obj && $obj->quantity > 0) // If found
{ {
if (!empty($obj->fk_supplier_price_expression)) { if (!empty($obj->fk_supplier_price_expression))
$priceparser = new PriceParser($this->db); {
require_once DOL_DOCUMENT_ROOT.'/product/class/priceparser.class.php';
$priceparser = new PriceParser($this->db);
$price_result = $priceparser->parseProductSupplier($obj->fk_product, $obj->fk_supplier_price_expression, $obj->quantity, $obj->tva_tx); $price_result = $priceparser->parseProductSupplier($obj->fk_product, $obj->fk_supplier_price_expression, $obj->quantity, $obj->tva_tx);
if ($price_result >= 0) { if ($price_result >= 0) {
$obj->price = $price_result; $obj->price = $price_result;
@ -1225,8 +1225,10 @@ class Product extends CommonObject
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
if ($obj && $obj->quantity > 0) // If found if ($obj && $obj->quantity > 0) // If found
{ {
if (!empty($obj->fk_supplier_price_expression)) { if (!empty($obj->fk_supplier_price_expression))
$priceparser = new PriceParser($this->db); {
require_once DOL_DOCUMENT_ROOT.'/product/class/priceparser.class.php';
$priceparser = new PriceParser($this->db);
$price_result = $priceparser->parseProductSupplier($obj->fk_product, $obj->fk_supplier_price_expression, $obj->quantity, $obj->tva_tx); $price_result = $priceparser->parseProductSupplier($obj->fk_product, $obj->fk_supplier_price_expression, $obj->quantity, $obj->tva_tx);
if ($result >= 0) { if ($result >= 0) {
$obj->price = $price_result; $obj->price = $price_result;
@ -1681,7 +1683,8 @@ class Product extends CommonObject
if (!empty($this->fk_price_expression) && empty($ignore_expression)) if (!empty($this->fk_price_expression) && empty($ignore_expression))
{ {
$priceparser = new PriceParser($this->db); require_once DOL_DOCUMENT_ROOT.'/product/class/priceparser.class.php';
$priceparser = new PriceParser($this->db);
$price_result = $priceparser->parseProduct($this); $price_result = $priceparser->parseProduct($this);
if ($price_result >= 0) if ($price_result >= 0)
{ {