add field to object product, add sql

This commit is contained in:
jpb 2021-07-19 14:03:03 +02:00
parent c0d54fe608
commit 97287af987
5 changed files with 40 additions and 4 deletions

View File

@ -36,4 +36,5 @@
-- v15
ALTER TABLE llx_product ADD COLUMN mandatory_period tinyint NULL DEFAULT 0 AFTER fk_project;

View File

@ -103,5 +103,7 @@ create table llx_product
desiredstock float DEFAULT 0,
fk_unit integer DEFAULT NULL,
price_autogen tinyint DEFAULT 0,
fk_project integer DEFAULT NULL -- Used when product was generated by a project or is specifif to a project
fk_project integer DEFAULT NULL, -- Used when product was generated by a project or is specifif to a project
mandatory_period tinyint DEFAULT 0 -- is used to signal to the user that the start and end dates are mandatory for this type of product the fk_product_type == 1 (service) (non-blocking action)
)ENGINE=innodb;

View File

@ -399,3 +399,4 @@ ProductSupplierExtraFields=Attributs supplémentaires (Prix fournisseur)
DeleteLinkedProduct=Supprimer le produit enfant lié à la combinaison
PMPValue=Prix moyen pondéré (PMP)
PMPValueShort=PMP
mandatoryperiod=Période obligatoires

View File

@ -551,7 +551,7 @@ if (empty($reshook)) {
$accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
$accountancy_code_buy_intra = GETPOST('accountancy_code_buy_intra', 'alpha');
$accountancy_code_buy_export = GETPOST('accountancy_code_buy_export', 'alpha');
$checkmandatory = GETPOST('mandatoryperiod', 'alpha');
if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') {
$object->accountancy_code_sell = '';
} else {
@ -582,6 +582,11 @@ if (empty($reshook)) {
} else {
$object->accountancy_code_buy_export = $accountancy_code_buy_export;
}
if ($object->isService()){
$object->mandatory_period = (!empty($checkmandatory)) ? 1 : 0 ;
}
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost(null, $object);
@ -1981,6 +1986,16 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyExportCode").'</td>';
print '<td><input name="accountancy_code_buy_export" class="maxwidth200" value="'.$object->accountancy_code_buy_export.'">';
print '</td></tr>';
if ($object->isService()) {
// Mandatory period
print '<tr><td class="titlefieldcreate">'.$langs->trans("mandatoryperiod").'</td>';
print '<td><input type="checkbox" name="mandatoryperiod"'.($object->mandatory_period == 1 ? ' checked="checked"' : '').' /> ';
print '</td></tr>';
}
}
}
print '</table>';
@ -2259,6 +2274,12 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
print (!empty($object->duration_unit) && isset($dur[$object->duration_unit]) ? $langs->trans($dur[$object->duration_unit]) : '')."&nbsp;";
print '</td></tr>';
// Mandatory period
print '<tr><td class="titlefield">'.$langs->trans("mandatoryperiod").'</td><td>';
print '<input type="checkbox" name="mandatoryperiod"'.($object->mandatory_period == 1 ? ' checked="checked"' : '').' disabled/> ';
print '</td></tr>';
} else {
if (empty($conf->global->PRODUCT_DISABLE_NATURE)) {
// Nature

View File

@ -426,6 +426,13 @@ class Product extends CommonObject
public $is_object_used;
/**
*
*
*
*/
public $mandatory_period;
/**
* 'type' if the field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
* Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
@ -476,6 +483,8 @@ class Product extends CommonObject
'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>0, 'position'=>1000),
//'tosell' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'default'=>0, 'index'=>1, 'position'=>1000, 'arrayofkeyval'=>array(0=>'Draft', 1=>'Active', -1=>'Cancel')),
//'tobuy' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'default'=>0, 'index'=>1, 'position'=>1000, 'arrayofkeyval'=>array(0=>'Draft', 1=>'Active', -1=>'Cancel')),
'mandatory_period' =>array('type'=>'integer', 'label'=>'mandatory_period', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'default'=>0, 'index'=>1, 'position'=>1000),
);
/**
@ -1141,7 +1150,7 @@ class Product extends CommonObject
$sql .= ", price_autogen = ".(!$this->price_autogen ? 0 : 1);
$sql .= ", fk_price_expression = ".($this->fk_price_expression != 0 ? (int) $this->fk_price_expression : 'NULL');
$sql .= ", fk_user_modif = ".($user->id > 0 ? $user->id : 'NULL');
$sql .= ", mandatory_period = ".($this->mandatory_period );
// stock field is not here because it is a denormalized value from product_stock.
$sql .= " WHERE rowid = ".((int) $id);
@ -2244,7 +2253,7 @@ class Product extends CommonObject
$sql .= " p.price_min, p.price_min_ttc, p.price_base_type, p.cost_price, p.default_vat_code, p.tva_tx, p.recuperableonly as tva_npr, p.localtax1_tx, p.localtax2_tx, p.localtax1_type, p.localtax2_type, p.tosell,";
$sql .= " p.tobuy, p.fk_product_type, p.duration, p.fk_default_warehouse, p.seuil_stock_alerte, p.canvas, p.net_measure, p.net_measure_units, p.weight, p.weight_units,";
$sql .= " p.length, p.length_units, p.width, p.width_units, p.height, p.height_units,";
$sql .= " p.surface, p.surface_units, p.volume, p.volume_units, p.barcode, p.fk_barcode_type, p.finished,";
$sql .= " p.surface, p.surface_units, p.volume, p.volume_units, p.barcode, p.fk_barcode_type, p.finished,p.mandatory_period,";
if (empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
$sql .= " p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export, p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,";
} else {
@ -2416,6 +2425,8 @@ class Product extends CommonObject
$this->price_autogen = $obj->price_autogen;
$this->model_pdf = $obj->model_pdf;
$this->mandatory_period = $obj->mandatory_period;
$this->db->free($resql);
// fetch optionals attributes and labels