diff --git a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_workflow/transitions/cancel.xml b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_workflow/transitions/cancel.xml
index 4b09ff649ab5ecc11539952b6754c75651d24367..3e6ab316f9a1c3864e1ef7e8f1ffbbbe9cc6c87c 100644
--- a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_workflow/transitions/cancel.xml
+++ b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_workflow/transitions/cancel.xml
@@ -29,7 +29,7 @@
         </item>
         <item>
             <key> <string>after_script_name</string> </key>
-            <value> <string></string> </value>
+            <value> <string>resetGroupingReference</string> </value>
         </item>
         <item>
             <key> <string>description</string> </key>
diff --git a/bt5/erp5_accounting/bt/revision b/bt5/erp5_accounting/bt/revision
index 191829efad4f7b6293301a32fb61608624f07377..ffad77660d58cac71bebe6d65fdb62d4eb628aac 100644
--- a/bt5/erp5_accounting/bt/revision
+++ b/bt5/erp5_accounting/bt/revision
@@ -1 +1 @@
-735
\ No newline at end of file
+736
\ No newline at end of file
diff --git a/product/ERP5/tests/testAccounting.py b/product/ERP5/tests/testAccounting.py
index 11b6295ad314b9665e72e18d6988dcc856b2c922..69e0dd5ca8b7b3f5787301cd6b3b8cc8fd796398 100644
--- a/product/ERP5/tests/testAccounting.py
+++ b/product/ERP5/tests/testAccounting.py
@@ -2180,6 +2180,43 @@ class TestTransactions(AccountingTestCase):
     self.failIf(invoice_line.getGroupingReference())
     self.failIf(payment_line.getGroupingReference())
 
+  def test_automatically_unsetting_grouping_reference_when_cancelling(self):
+    invoice = self._makeOne(
+               title='First Invoice',
+               destination_section_value=self.organisation_module.client_1,
+               lines=(dict(source_value=self.account_module.goods_purchase,
+                           source_debit=100),
+                      dict(source_value=self.account_module.receivable,
+                           source_credit=100,
+                           id='line_for_grouping_reference',)))
+    invoice_line = invoice.line_for_grouping_reference
+
+    payment = self._makeOne(
+               title='First Invoice Payment',
+               portal_type='Payment Transaction',
+               simulation_state='delivered',
+               causality_value=invoice,
+               source_payment_value=self.section.newContent(
+                                            portal_type='Bank Account'),
+               destination_section_value=self.organisation_module.client_1,
+               lines=(dict(source_value=self.account_module.receivable,
+                           id='line_for_grouping_reference',
+                           source_debit=100),
+                      dict(source_value=self.account_module.bank,
+                           source_credit=100,)))
+    payment_line = payment.line_for_grouping_reference
+
+    invoice.stop()
+    self.failUnless(invoice_line.getGroupingReference())
+    self.failUnless(payment_line.getGroupingReference())
+
+    invoice.cancel()
+    get_transaction().commit()
+    self.tic()
+    self.failIf(invoice_line.getGroupingReference())
+    self.failIf(payment_line.getGroupingReference())
+
+
 
 class TestAccountingWithSequences(ERP5TypeTestCase):
   """The first test for Accounting