Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
I
invoice
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
2
Merge Requests
2
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kb
invoice
Commits
e36952d4
Commit
e36952d4
authored
Apr 14, 2020
by
Patrick Kimber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add an 'on_account' field to the 'InvoiceContact' model
parent
da0160bb
Pipeline
#135876258
passed with stage
in 4 minutes and 56 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
13 deletions
+58
-13
invoice/migrations/0023_invoicecontact_on_account.py
invoice/migrations/0023_invoicecontact_on_account.py
+21
-0
invoice/models.py
invoice/models.py
+17
-3
invoice/tests/test_invoice_contact.py
invoice/tests/test_invoice_contact.py
+20
-10
No files found.
invoice/migrations/0023_invoicecontact_on_account.py
0 → 100644
View file @
e36952d4
# Generated by Django 3.0.5 on 2020-04-14 15:12
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
"invoice"
,
"0022_auto_20191029_1235"
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
"invoicecontact"
,
name
=
"on_account"
,
field
=
models
.
BooleanField
(
default
=
False
,
help_text
=
"Post the invoice on-account (do not batch)"
,
),
),
]
invoice/models.py
View file @
e36952d4
...
...
@@ -180,20 +180,28 @@ class TimeAnalysis:
class
InvoiceContactManager
(
models
.
Manager
):
def
_create_invoice_contact
(
self
,
contact
,
country
,
hourly_rate
,
vat_number
self
,
contact
,
country
,
hourly_rate
,
vat_number
,
on_account
):
x
=
self
.
model
(
contact
=
contact
,
country
=
country
,
hourly_rate
=
hourly_rate
,
on_account
=
on_account
,
vat_number
=
vat_number
or
""
,
)
x
.
save
()
return
x
def
init_invoice_contact
(
self
,
contact
,
country
=
None
,
hourly_rate
=
None
,
vat_number
=
None
self
,
contact
,
country
=
None
,
hourly_rate
=
None
,
vat_number
=
None
,
on_account
=
None
,
):
if
on_account
is
None
:
on_account
=
False
try
:
x
=
self
.
model
.
objects
.
get
(
contact
=
contact
)
update
=
False
...
...
@@ -203,6 +211,9 @@ class InvoiceContactManager(models.Manager):
if
hourly_rate
:
x
.
hourly_rate
=
hourly_rate
update
=
True
if
on_account
!=
x
.
on_account
:
x
.
on_account
=
on_account
update
=
True
if
vat_number
:
x
.
vat_number
=
vat_number
update
=
True
...
...
@@ -210,7 +221,7 @@ class InvoiceContactManager(models.Manager):
x
.
save
()
except
self
.
model
.
DoesNotExist
:
x
=
self
.
_create_invoice_contact
(
contact
,
country
,
hourly_rate
,
vat_number
contact
,
country
,
hourly_rate
,
vat_number
,
on_account
)
return
x
...
...
@@ -231,6 +242,9 @@ class InvoiceContact(TimeStampedModel):
on_delete
=
models
.
CASCADE
,
related_name
=
"+"
,
)
on_account
=
models
.
BooleanField
(
default
=
False
,
help_text
=
"Post the invoice on-account (do not batch)"
)
# Maximum of 12 characters?
# https://www.gov.uk/guidance/vat-eu-country-codes-vat-numbers-and-vat-in-other-languages
# 10/09/2019 The Xero 'TaxNumber' has a maximum length of 50 characters.
...
...
invoice/tests/test_invoice_contact.py
View file @
e36952d4
...
...
@@ -40,16 +40,19 @@ def test_str(hourly_rate, vat_number, expect):
@
pytest
.
mark
.
parametrize
(
"country_code,hourly,vat_number,expect_country_code,expect_hourly,expect_vat_number"
,
(
"country_code,hourly,vat_number,on_account,"
"expect_country_code,expect_hourly,expect_vat_number,expect_on_account"
),
[
(
"GB"
,
Decimal
(
"1"
),
"ABC"
,
"GB"
,
Decimal
(
"1"
),
"ABC"
),
(
"GB"
,
Decimal
(
"1"
),
"XYZ"
,
"GB"
,
Decimal
(
"1"
),
"XYZ"
),
(
"GB"
,
Decimal
(
"2"
),
"ABC"
,
"GB"
,
Decimal
(
"2"
),
"ABC"
),
(
"GB"
,
Decimal
(
"2"
),
"XYZ"
,
"GB"
,
Decimal
(
"2"
),
"XYZ"
),
(
"GB"
,
Decimal
(),
""
,
"GB"
,
Decimal
(
"1"
),
"ABC"
),
(
None
,
Decimal
(),
""
,
"FR"
,
Decimal
(
"1"
),
"ABC"
),
(
"GB"
,
Decimal
(),
"ABC"
,
"GB"
,
Decimal
(
"1"
),
"ABC"
),
(
None
,
None
,
None
,
"FR"
,
Decimal
(
"1"
),
"ABC"
),
(
"GB"
,
Decimal
(
"1"
),
"ABC"
,
False
,
"GB"
,
Decimal
(
"1"
),
"ABC"
,
False
),
(
"GB"
,
Decimal
(
"1"
),
"XYZ"
,
True
,
"GB"
,
Decimal
(
"1"
),
"XYZ"
,
True
),
(
"GB"
,
Decimal
(
"2"
),
"ABC"
,
False
,
"GB"
,
Decimal
(
"2"
),
"ABC"
,
False
),
(
"GB"
,
Decimal
(
"2"
),
"XYZ"
,
None
,
"GB"
,
Decimal
(
"2"
),
"XYZ"
,
False
),
(
"GB"
,
Decimal
(),
""
,
True
,
"GB"
,
Decimal
(
"1"
),
"ABC"
,
True
),
(
None
,
Decimal
(),
""
,
False
,
"FR"
,
Decimal
(
"1"
),
"ABC"
,
False
),
(
"GB"
,
Decimal
(),
"ABC"
,
True
,
"GB"
,
Decimal
(
"1"
),
"ABC"
,
True
),
(
None
,
None
,
None
,
False
,
"FR"
,
Decimal
(
"1"
),
"ABC"
,
False
),
],
)
@
pytest
.
mark
.
django_db
...
...
@@ -57,9 +60,11 @@ def test_init_invoice_contact(
country_code
,
hourly
,
vat_number
,
on_account
,
expect_country_code
,
expect_hourly
,
expect_vat_number
,
expect_on_account
,
):
contact
=
ContactFactory
()
country
=
None
...
...
@@ -73,11 +78,16 @@ def test_init_invoice_contact(
vat_number
=
"ABC"
,
)
x
=
InvoiceContact
.
objects
.
init_invoice_contact
(
contact
,
country
=
country
,
hourly_rate
=
hourly
,
vat_number
=
vat_number
contact
,
country
=
country
,
hourly_rate
=
hourly
,
vat_number
=
vat_number
,
on_account
=
on_account
,
)
assert
contact
==
x
.
contact
assert
Country
.
objects
.
get
(
iso2_code
=
expect_country_code
)
==
x
.
country
assert
expect_hourly
==
x
.
hourly_rate
assert
expect_on_account
==
x
.
on_account
assert
expect_vat_number
==
x
.
vat_number
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment