From 7a28f8e4aaf009ae5354565140abdc8d471d2dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Sun, 14 Sep 2014 13:59:06 +0200 Subject: [PATCH] [ bug #1555 ] Update accountancy code of products does not throw PRODUCT_MODIFY trigger --- ChangeLog | 1 + htdocs/core/class/commonobject.class.php | 1 - htdocs/product/class/product.class.php | 55 +++++++++++++++++++++++- htdocs/product/fiche.php | 16 +++---- 4 files changed, 62 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 04e63ec1c8e..b277355b9d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -25,6 +25,7 @@ Fix: [ bug #1544 ] Can remove date from invoice. Fix: list event view lost type event filter. Fix: Add code save on create event. Fix: SQL injection. +Fix: [ bug #1555 ] Update accountancy code of products does not throw PRODUCT_MODIFY trigger ***** ChangeLog for 3.5.4 compared to 3.5.3 ***** Fix: Hide title of event when agenda module disabled. diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index dc2fe2888ad..6439e3e003e 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1053,7 +1053,6 @@ abstract class CommonObject } } - /** * Save a new position (field rang) for details lines. * You can choose to set position for lines with already a position or lines without any position defined. diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 52ad1a7f323..d7bdec82079 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -6,7 +6,7 @@ * Copyright (C) 2007-2011 Jean Heimburger * Copyright (C) 2010-2011 Juanjo Menent * Copyright (C) 2013 Cedric GROSS - * Copyright (C) 2013 Marcos García + * Copyright (C) 2013-2014 Marcos García * * 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 @@ -796,6 +796,59 @@ class Product extends CommonObject return 1; } + /** + * Sets an accountancy code for a product. + * Also calls PRODUCT_MODIFY trigger when modified + * + * @param string $type It can be 'buy' or 'sell' + * @param string $value Accountancy code + * @return int <0 KO >0 OK + */ + public function setAccountancyCode($type, $value) + { + $this->db->begin(); + + if ($type == 'buy') { + $field = 'accountancy_code_buy'; + } elseif ($type == 'sell') { + $field = 'accountancy_code_sell'; + } else { + return -1; + } + + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET "; + $sql.= "$field = '".$this->db->escape($value)."'"; + $sql.= " WHERE rowid = ".$this->id; + + dol_syslog(get_class($this)."::".__FUNCTION__." sql=".$sql, LOG_DEBUG); + $resql = $this->db->query($sql); + + if ($resql) { + global $user, $langs, $conf; + + // Call triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('PRODUCT_MODIFY',$this,$user,$langs,$conf); + if ($result < 0) { + $this->errors=$interface->errors; + $this->db->rollback(); + return -1; + } + // End call triggers + + $this->$field = $value; + + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->lasterror(); + $this->db->rollback(); + return -1; + } + } /** * Load array this->multilangs diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index d96aac8fc33..3c3d7ad8206 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -6,7 +6,7 @@ * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2006 Auguria SARL * Copyright (C) 2010-2011 Juanjo Menent - * Copyright (C) 2013 Marcos García + * Copyright (C) 2013-2014 Marcos García * Copyright (C) 2013 Cédric Salvador * * This program is free software; you can redistribute it and/or modify @@ -122,20 +122,18 @@ if (empty($reshook)) exit; } - if ($action == 'setaccountancy_code_buy') - { - $result = $object->setValueFrom('accountancy_code_buy', GETPOST('accountancy_code_buy')); + if ($action == 'setaccountancy_code_buy') { + + $result = $object->setAccountancyCode('buy', GETPOST('accountancy_code_buy')); if ($result < 0) setEventMessage(join(',',$object->errors), 'errors'); - else $object->accountancy_code_buy=GETPOST('accountancy_code_buy'); $action=""; } if ($action == 'setaccountancy_code_sell') { - $result = $object->setValueFrom('accountancy_code_sell', GETPOST('accountancy_code_sell')); - if ($result < 0) setEventMessage(join(',',$object->errors), 'errors'); - else $object->accountancy_code_sell=GETPOST('accountancy_code_sell'); - $action=""; + $result = $object->setAccountancyCode('sell', GETPOST('accountancy_code_sell')); + if ($result < 0) setEventMessage(join(',',$object->errors), 'errors'); + $action=""; } // Add a product or service