diff --git a/CHANGELOG b/CHANGELOG
index 08cfe6de2d..33c35e0b0c 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,5 @@
+* Add option to cancel customer invoice
+
Version 5.2.0 - 2019-05-06
* Bug fixes (see mercurial logs for details)
* Show reconciliation lines as payment lines
diff --git a/__init__.py b/__init__.py
index aa806d4b1c..18c99476dd 100644
--- a/__init__.py
+++ b/__init__.py
@@ -6,6 +6,7 @@ from .payment_term import *
from .invoice import *
from . import party
from .account import *
+from . import company
def register():
@@ -36,6 +37,7 @@ def register():
MoveLine,
Reconciliation,
PaymentMethod,
+ company.Company,
module='account_invoice', type_='model')
Pool.register(
TestPaymentTerm,
diff --git a/company.py b/company.py
new file mode 100644
index 0000000000..7a6e883f4f
--- /dev/null
+++ b/company.py
@@ -0,0 +1,16 @@
+# This file is part of Tryton. The COPYRIGHT file at the top level of
+# this repository contains the full copyright notices and license terms.
+from trytond.model import fields
+from trytond.pool import PoolMeta
+
+
+class Company(metaclass=PoolMeta):
+ __name__ = 'company.company'
+
+ cancel_invoice_out = fields.Boolean(
+ "Cancel Customer Invoice",
+ help="Allow cancelling move of customer invoice.")
+
+ @classmethod
+ def default_cancel_invoice_out(cls):
+ return False
diff --git a/company.xml b/company.xml
new file mode 100644
index 0000000000..b5bf699aec
--- /dev/null
+++ b/company.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+ company.company
+
+ company_form
+
+
+
diff --git a/invoice.py b/invoice.py
index 8c87ced7bc..5beabf5ee3 100644
--- a/invoice.py
+++ b/invoice.py
@@ -1423,7 +1423,8 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin):
if invoice.move.state == 'draft':
delete_moves.append(invoice.move)
elif not invoice.cancel_move:
- if invoice.type == 'out':
+ if (invoice.type == 'out'
+ and not invoice.company.cancel_invoice_out):
raise AccessError(
gettext('account_invoice'
'.msg_invoice_customer_cancel_move',
diff --git a/message.xml b/message.xml
index f4c75c80d9..f701a9216a 100644
--- a/message.xml
+++ b/message.xml
@@ -34,7 +34,7 @@ this repository contains the full copyright notices and license terms. -->
You cannot delete invoice "%(invoice)s" because it has a number.
- You cannot cancel customer invoice "%(invoice)s" because it is posted.
+ You cannot cancel customer invoice "%(invoice)s" because it is posted and company setup does not allow it.
Payment lines amount on invoice "%(invoice)s" can not be greater than the invoice amount.
diff --git a/tryton.cfg b/tryton.cfg
index 522986450e..cb37851edf 100644
--- a/tryton.cfg
+++ b/tryton.cfg
@@ -14,4 +14,5 @@ xml:
payment_term.xml
party.xml
account.xml
+ company.xml
message.xml
diff --git a/view/company_form.xml b/view/company_form.xml
new file mode 100644
index 0000000000..0f0b7f544e
--- /dev/null
+++ b/view/company_form.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+