439
edits
(→Implementing the change of price in margin module: Optimized code a bit) |
(→Implementing the change of price in margin module: Adding an overloading function to refresh the prices instantly) |
||
| Line 486: | Line 486: | ||
That's all, the price should be reflected in the margin. Just refresh the page to reflect the change. | That's all, the price should be reflected in the margin. Just refresh the page to reflect the change. | ||
== Refresh the price instantly == | |||
Maybe you noticed one glitch: when you modify the global_coefficient, the global total price isn't updated until you add/edit a product/service line. This is because the update_price() function is only called when we add/edit a product/service line. | |||
To fix that, we need now to force the refreshing of price. To do that, we will use an "aftersave" overloading function, which will execute commands after our custom field is saved. | |||
Go to the folder /htdocs/customfields/fields and rename the file customfields_fields_extend.lib.php.example into customfields_fields_extend.lib.php . | |||
Now, open it in your favourite text editor, and add the following function : | |||
<source lang="php"> | |||
function customfields_field_aftersave_facture_global_coefficient (&$currentmodule, &$object, &$action, &$user, &$customfields, &$field, &$name, &$value, $fields) { | |||
// Force refreshing total price | |||
$object->parent_object->update_price(0, 'auto'); | |||
} | |||
</source> | |||
That's all. Now, when you edit your global_coefficient, this will force refresh the total price. | |||
= Modify the total price PER product/service line with a coefficient (without tampering the discount) = | = Modify the total price PER product/service line with a coefficient (without tampering the discount) = | ||
edits