Commit af0b39c9 authored by Patrick Kimber's avatar Patrick Kimber

If the invoices for a contact are posted 'on_account' then don't allow this to change

parent e36952d4
Pipeline #135893931 passed with stage
in 5 minutes and 1 second
......@@ -200,6 +200,14 @@ class InvoiceContactManager(models.Manager):
vat_number=None,
on_account=None,
):
"""Initialise the invoice details for the contact.
.. note:: The on account flag (``on_account``) can only be switched on.
It can't be switched off.
If we are posting to an accounts package e.g. Xero, then we
should always post on-account if we ever posted on-account.
"""
if on_account is None:
on_account = False
try:
......@@ -211,7 +219,7 @@ class InvoiceContactManager(models.Manager):
if hourly_rate:
x.hourly_rate = hourly_rate
update = True
if on_account != x.on_account:
if on_account is True and x.on_account is False:
x.on_account = on_account
update = True
if vat_number:
......
......@@ -137,6 +137,36 @@ def test_init_invoice_contact_hourly_rate():
assert "" == x.vat_number
@pytest.mark.parametrize(
"init_on_account,on_account,expect",
[
(True, True, True),
(True, False, True),
(False, False, False),
(False, True, True),
],
)
@pytest.mark.django_db
def test_init_invoice_on_account(init_on_account, on_account, expect):
"""Initialise the on-account status for the contact.
.. note:: The on account flag (``on_account``) can only be switched on.
It can't be switched off.
If we are posting to an accounts package e.g. Xero, then we
should always post on-account if we ever posted on-account.
"""
contact = ContactFactory()
InvoiceContact.objects.init_invoice_contact(
contact, on_account=init_on_account,
)
x = InvoiceContact.objects.init_invoice_contact(
contact, on_account=on_account,
)
x.refresh_from_db()
assert expect == x.on_account
@pytest.mark.django_db
def test_init_invoice_contact_vat_number():
contact = ContactFactory()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment