Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set period on registration/renewal invoices #3456

Merged
merged 48 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
574846c
Fix moneybird mandate synchronization bug
T8902 Oct 17, 2023
a33330a
Rename stuff
DeD1rk Oct 17, 2023
6f0ff2d
Add starting point for testing
DeD1rk Oct 17, 2023
26bca9d
Implement bulk moneybird payment creation
DeD1rk Oct 18, 2023
0138add
Push most invoices at night
DeD1rk Oct 18, 2023
31596c9
Make EventRegistration.payment_amount queryable
DeD1rk Oct 18, 2023
444c65e
Push EventRegistration invoices nightly
DeD1rk Oct 18, 2023
6a95359
Remove customer_id from contact
JobDoesburg Oct 18, 2023
1d50f96
Improve displaying of transactions
JobDoesburg Oct 18, 2023
b8a6265
Fix
JobDoesburg Oct 18, 2023
861cbcd
Add SEPA fields to transactions
JobDoesburg Oct 18, 2023
b354df9
Improve SEPA fields
JobDoesburg Oct 18, 2023
965a0f7
Improve SEPA fields
JobDoesburg Oct 18, 2023
5877aef
Improve SEPA fields
JobDoesburg Oct 18, 2023
a9a293e
Fix timezone
JobDoesburg Oct 18, 2023
1fd71df
Slightly improved admins
tmgdejong Oct 18, 2023
8efd8a7
Slightly improved admins
tmgdejong Oct 18, 2023
3d3efd8
Actually remove customer ID
DeD1rk Oct 19, 2023
f1a8364
Make moneybird client retry on ratelimit
DeD1rk Oct 19, 2023
9b11a54
contribution to sales invoices
Oct 19, 2023
eae8d84
type bug
Oct 19, 2023
de53a58
Organize services
DeD1rk Oct 20, 2023
aa667c8
Use loggers
DeD1rk Oct 20, 2023
3620bba
Implement deleting eventregistration invoices
DeD1rk Oct 20, 2023
f4612da
Implement updating invoices
DeD1rk Oct 20, 2023
f07810b
Send error report email after logging
DeD1rk Oct 20, 2023
4de7f61
Make migration set needs_synchronization False
DeD1rk Oct 20, 2023
3e2c43a
Implement deleting invoices
DeD1rk Oct 20, 2023
59c52a6
Improve admins
DeD1rk Oct 20, 2023
9b94c68
Refactor services
DeD1rk Oct 20, 2023
f45b76a
Never use thaliawebsite.settings
DeD1rk Oct 21, 2023
060ae2c
Improve model constraints
DeD1rk Oct 21, 2023
6faa1ca
Write a test
DeD1rk Oct 21, 2023
5e64cef
Merge branch 'overhaul-moneybird' into moneybird/contribution-to-invoice
Oct 24, 2023
ee8f9d5
merge migrations
Oct 24, 2023
09db21e
Merge branch 'overhaul-moneybird' into moneybird/contribution-to-invoice
Oct 24, 2023
42fde9b
merge migrations
Oct 24, 2023
7431424
fix update function
Oct 24, 2023
934f0e8
Merge branch 'master' into contribution-to-invoice
Oct 26, 2023
4a11280
readd period function
Oct 26, 2023
9c51a1f
CI
Oct 26, 2023
a2b4700
CI
Oct 26, 2023
af2a7f2
sales -> external
Oct 26, 2023
4896b81
Cleanup PR
JobDoesburg Oct 26, 2023
62c11d4
Merge branch 'master' into moneybird/contribution-to-invoice
nvoers Oct 27, 2023
c17cc95
Improve
JobDoesburg Oct 27, 2023
72f587f
Try-catch broken memberships
JobDoesburg Oct 27, 2023
eb844dc
Simplify try-catch
DeD1rk Oct 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions website/moneybirdsynchronization/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ def ledger_id_for_payable_model(obj) -> Optional[int]:
return None


def datetime_to_membership_period(date):
"""Convert a :class:`~datetime.date` to a period that corresponds with the current membership period."""
start_date = date
if start_date.month == 8:
start_date = start_date.replace(month=9, day=1)
end_date = start_date.replace(month=8, day=31)
if start_date.month > 8:
end_date = end_date.replace(year=start_date.year + 1)
return f"{start_date.strftime('%Y%m%d')}..{end_date.strftime('%Y%m%d')}"


class MoneybirdProject(models.Model):
name = models.CharField(
_("Name"),
Expand Down Expand Up @@ -269,6 +280,14 @@ def to_moneybird(self):

ledger_id = ledger_id_for_payable_model(self.payable_object)

period = None
tax_rate_id = None
if isinstance(self.payable_object, (Registration, Renewal)):
period = datetime_to_membership_period(
self.payable_object.created_at.date()
)
tax_rate_id = settings.MONEYBIRD_ZERO_TAX_RATE_ID

source_url = settings.BASE_URL + reverse(
f"admin:{self.payable_object._meta.app_label}_{self.payable_object._meta.model_name}_change",
args=(self.object_id,),
Expand Down Expand Up @@ -306,6 +325,12 @@ def to_moneybird(self):
data["external_sales_invoice"]["details_attributes"][0]["id"] = int(
self.moneybird_details_attribute_id
)
if period is not None:
data["external_sales_invoice"]["details_attributes"][0]["period"] = period
if tax_rate_id is not None:
data["external_sales_invoice"]["details_attributes"][0][
"tax_rate_id"
] = int(tax_rate_id)

return data

Expand Down
6 changes: 6 additions & 0 deletions website/thaliawebsite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,3 +1115,9 @@ def from_env(
if os.environ.get("MONEYBIRD_CARD_FINANCIAL_ACCOUNT_ID")
else None
)

MONEYBIRD_ZERO_TAX_RATE_ID: Optional[int] = (
int(os.environ.get("MONEYBIRD_ZERO_TAX_RATE_ID"))
if os.environ.get("MONEYBIRD_ZERO_TAX_RATE_ID")
else None
)