[ bug #1555 ] Update accountancy code of products does not throw PRODUCT_MODIFY trigger

This commit is contained in:
Marcos García de La Fuente 2014-09-14 13:59:06 +02:00
parent ba70c1a08a
commit 7a28f8e4aa
4 changed files with 62 additions and 11 deletions

View File

@ -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.

View File

@ -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.

View File

@ -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

View File

@ -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