diff --git a/ChangeLog b/ChangeLog index 04e63ec1c8ec6fa68c32334defe796bd63ee6b9b..b277355b9d79535f2bfc6ecce7e54238603290c0 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 dc2fe2888ad1620f930fa20cbb2617028ec03c0f..6439e3e003eb08a795b4d93c66f3e1f058c1df23 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 52ad1a7f3235711f1b61e9d623452ee569c6bd57..d7bdec8207965c5050d15d0f6172800b274da3ed 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 <jean@tiaris.info> * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2013 Cedric GROSS <c.gross@kreiz-it.fr> - * Copyright (C) 2013 Marcos García <marcosgdf@gmail.com> + * Copyright (C) 2013-2014 Marcos García <marcosgdf@gmail.com> * * 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 d96aac8fc335a05b9b8c424aa00133822518bf73..3c3d7ad820696ed763bc7606f9911e7ef03d4b0a 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -6,7 +6,7 @@ * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr> * Copyright (C) 2006 Auguria SARL <info@auguria.org> * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es> - * Copyright (C) 2013 Marcos García <marcosgdf@gmail.com> + * Copyright (C) 2013-2014 Marcos García <marcosgdf@gmail.com> * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr> * * 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