Debug the asset module. Can't delete.
This commit is contained in:
parent
354a314843
commit
62e305f7fa
7 changed files with 225 additions and 6 deletions
|
|
@ -52,6 +52,24 @@ class Asset extends CommonObject
|
|||
*/
|
||||
public $picto = 'asset';
|
||||
|
||||
/**
|
||||
* @var string|int Field with ID of parent key if this field has a parent (a string). For example 'fk_product'.
|
||||
* ID of parent key itself (an int). For example in few classes like 'Comment', 'ActionComm' or 'AdvanceTargetingMailing'.
|
||||
*/
|
||||
public $fk_element = 'fk_asset';
|
||||
|
||||
/**
|
||||
* @var array List of child tables. To know object to delete on cascade.
|
||||
* If name matches '@ClassName:FilePathClass:ParentFkFieldName' (the recommended mode) it will
|
||||
* call method ClassName->deleteByParentField(parentId, 'ParentFkFieldName') to fetch and delete child object.
|
||||
* Using an array like childtables should not be implemented because a child may have other child, so we must only use the method that call deleteByParentField().
|
||||
*/
|
||||
protected $childtablesoncascade = array(
|
||||
'@AssetAccountancyCodes:/asset/class/assetaccountancycodes.class.php:fk_asset',
|
||||
'@AssetAccountancyCodesFiscal:/asset/class/assetaccountancycodesfiscal.class.php:fk_asset'
|
||||
);
|
||||
|
||||
|
||||
const STATUS_DRAFT = 0; // Draft
|
||||
const STATUS_VALIDATED = 1; // In progress
|
||||
const STATUS_DISPOSED = 9; // Disposed
|
||||
|
|
@ -246,15 +264,18 @@ class Asset extends CommonObject
|
|||
* @var AssetDepreciationOptions Used for computed fields of depreciation options class.
|
||||
*/
|
||||
public $asset_depreciation_options;
|
||||
|
||||
/**
|
||||
* @var AssetAccountancyCodes
|
||||
*/
|
||||
public $asset_accountancy_codes;
|
||||
|
||||
/**
|
||||
* @var array<string,array<array{id:int,ref:string,depreciation_date:string,depreciation_ht:string,cumulative_depreciation_ht:string,bookkeeping:Bookkeeping}>> List of depreciation lines for each mode (sort by depreciation date).
|
||||
*/
|
||||
public $depreciation_lines = array();
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
|
|
@ -569,6 +590,15 @@ class Asset extends CommonObject
|
|||
*/
|
||||
public function delete(User $user, $notrigger = 0)
|
||||
{
|
||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'asset_depreciation_options_fiscal WHERE fk_asset = '.((int) $this->id);
|
||||
$this->db->query($sql);
|
||||
|
||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'asset_depreciation_options_economic WHERE fk_asset = '.((int) $this->id);
|
||||
$this->db->query($sql);
|
||||
|
||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'asset_depreciation WHERE fk_asset = '.((int) $this->id);
|
||||
$this->db->query($sql);
|
||||
|
||||
return $this->deleteCommon($user, $notrigger);
|
||||
//return $this->deleteCommon($user, $notrigger, 1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,11 +24,41 @@
|
|||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
|
||||
|
||||
|
||||
/**
|
||||
* Class for AssetAccountancyCodes
|
||||
*/
|
||||
class AssetAccountancyCodes extends CommonObject
|
||||
{
|
||||
// TODO This class and table should not exists and should be properties of llx_asset_asset.
|
||||
|
||||
/**
|
||||
* @var string Name of table without prefix where object is stored. This is also the key used for extrafields management (so extrafields know the link to the parent table).
|
||||
*/
|
||||
public $table_element = 'asset_accountancy_codes_economic';
|
||||
|
||||
/**
|
||||
* @var string Field with ID of parent key if this object has a parent
|
||||
*/
|
||||
public $fk_element = 'fk_asset';
|
||||
|
||||
// BEGIN MODULEBUILDER PROPERTIES
|
||||
/**
|
||||
* @inheritdoc
|
||||
* Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
|
||||
*/
|
||||
public $fields = array(
|
||||
'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => 'Id'),
|
||||
//...
|
||||
);
|
||||
|
||||
/**
|
||||
* @var int ID
|
||||
*/
|
||||
public $rowid;
|
||||
// END MODULEBUILDER PROPERTIES
|
||||
|
||||
|
||||
/**
|
||||
* @var array<string,array<string,string|array<string,array{label:string,columnbreak?:bool}>>> Array with all accountancy codes info by mode.
|
||||
* Note : 'economic' mode is mandatory and is the primary accountancy codes
|
||||
|
|
@ -64,6 +94,11 @@ class AssetAccountancyCodes extends CommonObject
|
|||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* @var int ID parent asset
|
||||
*/
|
||||
public $fk_asset;
|
||||
|
||||
/**
|
||||
* @var array<string,array<string,string>> Array with all accountancy codes by mode.
|
||||
*/
|
||||
|
|
@ -79,6 +114,34 @@ class AssetAccountancyCodes extends CommonObject
|
|||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load object in memory from the database
|
||||
*
|
||||
* @param int $id Id object
|
||||
* @param string $ref Ref
|
||||
* @return int<-1,max> Return integer <0 if KO, 0 if not found, >0 if OK
|
||||
*/
|
||||
public function fetch($id, $ref = null)
|
||||
{
|
||||
$result = $this->fetchCommon($id, $ref);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete object in database
|
||||
*
|
||||
* @param User $user User that deletes
|
||||
* @param int<0,1> $notrigger 0=launch triggers, 1=disable triggers
|
||||
* @return int<-1,1> Return integer <0 if KO, >0 if OK
|
||||
*/
|
||||
public function delete(User $user, $notrigger = 0)
|
||||
{
|
||||
return $this->deleteCommon($user, $notrigger);
|
||||
//return $this->deleteCommon($user, $notrigger, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fill accountancy_codes property of object (using for data sent by forms)
|
||||
*
|
||||
|
|
|
|||
103
htdocs/asset/class/assetaccountancycodesfiscal.class.php
Normal file
103
htdocs/asset/class/assetaccountancycodesfiscal.class.php
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
/* Copyright (C) 2021 Open-Dsi <support@open-dsi.fr>
|
||||
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.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
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file asset/class/assetaccountancycodesfiscal.class.php
|
||||
* \ingroup asset
|
||||
* \brief This file is a class file for AssetAccountancyCodesFiscal
|
||||
*/
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
|
||||
|
||||
|
||||
/**
|
||||
* Class for AssetAccountancyCodes
|
||||
*/
|
||||
class AssetAccountancyCodesFiscal extends CommonObject
|
||||
{
|
||||
// TODO This class and table should not exists and should be properties of llx_asset_asset.
|
||||
|
||||
/**
|
||||
* @var string Name of table without prefix where object is stored. This is also the key used for extrafields management (so extrafields know the link to the parent table).
|
||||
*/
|
||||
public $table_element = 'asset_accountancy_codes_fiscal';
|
||||
|
||||
/**
|
||||
* @var string Field with ID of parent key if this object has a parent
|
||||
*/
|
||||
public $fk_element = 'fk_asset';
|
||||
|
||||
// BEGIN MODULEBUILDER PROPERTIES
|
||||
/**
|
||||
* @inheritdoc
|
||||
* Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
|
||||
*/
|
||||
public $fields = array(
|
||||
'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => 'Id'),
|
||||
//...
|
||||
);
|
||||
|
||||
/**
|
||||
* @var int ID
|
||||
*/
|
||||
public $rowid;
|
||||
// END MODULEBUILDER PROPERTIES
|
||||
|
||||
/**
|
||||
* @var int ID parent asset
|
||||
*/
|
||||
public $fk_asset;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
*/
|
||||
public function __construct(DoliDB $db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load object in memory from the database
|
||||
*
|
||||
* @param int $id Id object
|
||||
* @param string $ref Ref
|
||||
* @return int<-1,max> Return integer <0 if KO, 0 if not found, >0 if OK
|
||||
*/
|
||||
public function fetch($id, $ref = null)
|
||||
{
|
||||
$result = $this->fetchCommon($id, $ref);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete object in database
|
||||
*
|
||||
* @param User $user User that deletes
|
||||
* @param int<0,1> $notrigger 0=launch triggers, 1=disable triggers
|
||||
* @return int<-1,1> Return integer <0 if KO, >0 if OK
|
||||
*/
|
||||
public function delete(User $user, $notrigger = 0)
|
||||
{
|
||||
return $this->deleteCommon($user, $notrigger);
|
||||
//return $this->deleteCommon($user, $notrigger, 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -107,7 +107,7 @@ class AssetDepreciationOptions extends CommonObject
|
|||
),
|
||||
);
|
||||
/**
|
||||
* @var int
|
||||
* @var int ID parent asset
|
||||
*/
|
||||
public $fk_asset;
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4910,8 +4910,6 @@ abstract class CommonObject
|
|||
*/
|
||||
public function getCanvas($id = 0, $ref = '')
|
||||
{
|
||||
global $conf;
|
||||
|
||||
if (empty($id) && empty($ref)) {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -10926,6 +10924,7 @@ abstract class CommonObject
|
|||
if (!empty($deleteFromObject[3])) {
|
||||
$filter = $deleteFromObject[3];
|
||||
}
|
||||
|
||||
if (dol_include_once($filePath)) {
|
||||
$childObject = new $className($this->db);
|
||||
if (method_exists($childObject, 'deleteByParentField')) {
|
||||
|
|
@ -11031,7 +11030,28 @@ abstract class CommonObject
|
|||
$error = 0;
|
||||
$deleted = 0;
|
||||
|
||||
//dol_syslog("deleteByParentField for ".$parentId.' '.$parentField);
|
||||
|
||||
if (!empty($parentId) && !empty($parentField)) {
|
||||
if (empty($this->table_element)) {
|
||||
$this->error = 'Property table_element for object is not defined';
|
||||
$this->errors[] = $this->error;
|
||||
$error++;
|
||||
return -1;
|
||||
}
|
||||
if (!method_exists($this, 'fetch')) {
|
||||
$this->error = 'Method fetch for object is not defined';
|
||||
$this->errors[] = $this->error;
|
||||
$error++;
|
||||
return -1;
|
||||
}
|
||||
if (!method_exists($this, 'delete')) {
|
||||
$this->error = 'Method delete for object is not defined';
|
||||
$this->errors[] = $this->error;
|
||||
$error++;
|
||||
return -1;
|
||||
}
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "SELECT rowid FROM ".$this->db->prefix().$this->table_element;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
-- along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
-- ========================================================================
|
||||
|
||||
-- TODO This table seems to contains properties of llx_asset so should not exists and fields should be into llx_asset.
|
||||
|
||||
ALTER TABLE llx_asset_accountancy_codes_economic ADD INDEX idx_asset_ace_rowid (rowid);
|
||||
ALTER TABLE llx_asset_accountancy_codes_economic ADD UNIQUE uk_asset_ace_fk_asset (fk_asset);
|
||||
ALTER TABLE llx_asset_accountancy_codes_economic ADD UNIQUE uk_asset_ace_fk_asset_model (fk_asset_model);
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ class MyObject extends CommonObject
|
|||
// public $table_element_line = 'mymodule_myobjectline';
|
||||
|
||||
// /**
|
||||
// * @var string Field with ID of parent key if this object has a parent
|
||||
// * @var string Field name with ID of parent key if this object has a parent, Or Field name of in child tables to link to this record.
|
||||
// */
|
||||
// public $fk_element = 'fk_myobject';
|
||||
|
||||
|
|
@ -217,8 +217,9 @@ class MyObject extends CommonObject
|
|||
|
||||
// /**
|
||||
// * @var array List of child tables. To know object to delete on cascade.
|
||||
// * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
|
||||
// * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
|
||||
// * If name matches '@ClassName:FilePathClass:ParentFkFieldName' (the recommended mode) it will
|
||||
// * call method ClassName->deleteByParentField(parentId, 'ParentFkFieldName') to fetch and delete child object.
|
||||
// * Using an array like childtables should not be implemented because a child may have other child, so we must only use the method that call deleteByParentField().
|
||||
// */
|
||||
// protected $childtablesoncascade = array('mymodule_myobjectdet');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue