diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php
index 7c75e0ae49b9940632d715fcda957f8a7311705f..7723123bc0e6406e3882fcd521261f762823528b 100644
--- a/htdocs/core/tpl/objectline_edit.tpl.php
+++ b/htdocs/core/tpl/objectline_edit.tpl.php
@@ -252,6 +252,10 @@ if (! empty($conf->margin->enabled))
 			jQuery("input[name='np_marginRate']:first").val('');
 			jQuery("input[name='np_markRate']:first").val('');
 		});
+		jQuery("#qty").keyup(function() {
+			jQuery("input[name='np_marginRate']:first").val('');
+			jQuery("input[name='np_markRate']:first").val('');
+		});
 		jQuery("#remise_percent").keyup(function() {
 			jQuery("input[name='np_marginRate']:first").val('');
 			jQuery("input[name='np_markRate']:first").val('');
@@ -300,7 +304,7 @@ if (! empty($conf->margin->enabled))
 
 		/* Add rules to reset price_ht from margin info */
 		<?php
-		if (! empty($conf->global->DISPLAY_MARGIN_RATES))
+		if (! empty($conf->global->DISPLAY_MARGIN_RATES) && !empty($conf->global->MARGIN_RESET_HT_FROM_MARGIN_FIELD))
 		{
 		?>
 			$('#savelinebutton').click(function (e) {
@@ -312,7 +316,7 @@ if (! empty($conf->margin->enabled))
 			});*/
 		<?php
 		}
-		if (! empty($conf->global->DISPLAY_MARK_RATES))
+		if (! empty($conf->global->DISPLAY_MARK_RATES) && !empty($conf->global->MARGIN_RESET_HT_FROM_MARGIN_FIELD))
 		{
 		?>
 			$('#savelinebutton').click(function (e) {