Skip to content

Instantly share code, notes, and snippets.

@ari
Created October 21, 2018 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ari/38ccdd984bd1eae8e19b80783a0e7c96 to your computer and use it in GitHub Desktop.
Save ari/38ccdd984bd1eae8e19b80783a0e7c96 to your computer and use it in GitHub Desktop.
Create BAS entries
#!python3
import argparse
import locale
import logging
from datetime import datetime, date
from lib.moneyworks import Moneyworks
from lib.transaction import Transaction
mw = Moneyworks('/usr/local/etc/salt/runner/mw.ini')
locale.setlocale(locale.LC_ALL, 'en_AU.UTF-8')
log = logging.getLogger(__name__)
ATO_REF = "12345678"
def create_transactions(gst_on_sales=None, gst_on_purchases=None, payg_installment=None, payg_withheld=None, report_date=None):
today = date.today()
# create a set of due dates all in the future
gst_due_dates = [datetime.strptime(str(today.year) + '-' + x, "%Y-%m-%d").date() for x in [
'02-21', # GST and PAYG (from Dec and Jan)
'04-28',
'07-28',
'10-28',
]]
gst_due_dates = [x if x > report_date else x.replace(year=x.year + 1) for x in gst_due_dates]
payg_due_dates = [datetime.strptime(str(report_date.year) + '-' + x, "%Y-%m-%d").date() for x in [
'02-21', # GST and PAYG (from Dec and Jan)
'03-21',
'04-28',
'05-21',
'06-21',
'07-28',
'08-21',
'09-21',
'10-28',
'11-21',
'12-21'
]]
payg_due_dates = [x if x > report_date else x.replace(year=x.year + 1) for x in payg_due_dates]
# Get the next
gst_due = next(x for x in sorted(gst_due_dates) if x > report_date)
payg_due = next(x for x in sorted(payg_due_dates) if x > report_date)
# GST purchase invoice
t = Transaction()
t.add("type", "CI")
t.add("theirref", ATO_REF)
t.add("transdate", today)
t.add("namecode", 'ATO')
t.add("description", "BAS GST: %s" % report_date.strftime('%B %Y'))
t.add("colour", 5)
l = t.add_line()
l.add("detail.account", '5850')
l.add("detail.net", gst_on_sales)
l.add("detail.description", 'GST collected on sales')
l = t.add_line()
l.add("detail.account", '5850')
l.add("detail.net", -gst_on_purchases)
l.add("detail.description", 'GST paid on purchases')
l = t.add_line()
l.add("detail.account", '5120')
l.add("detail.net", payg_installment)
l.add("detail.description", 'Income tax installment')
t.add("contra")
t.add("ourRef")
t.add("duedate", gst_due)
mw.create_transaction(t.to_xml())
# PAYG purchase invoice
t = Transaction()
t.add("type", "CI")
t.add("theirref", ATO_REF)
t.add("transdate", today)
t.add("namecode", 'ATO')
t.add("description", "BAS PAYG: %s" % report_date.strftime('%B %Y'))
t.add("colour", 5)
l = t.add_line()
l.add("detail.account", '5100')
l.add("detail.net", payg_withheld)
l.add("detail.description", 'Tax deducted from wages')
t.add("contra")
t.add("ourRef")
t.add("duedate", payg_due)
mw.create_transaction(t.to_xml())
def get_bas_data():
bas = {}
data = mw.export_one("taxrate", "taxcode=`G`")
bas['reportdate'] = datetime.strptime(data['reportdate'], "%Y%m%d").date()
bas['1A'] = round(float(data['gstreceived']))
bas['1B'] = round(float(data['gstpaid']))
bas['G1'] = round(float(data['netreceived'])) + bas['1A']
print(data)
# exports
data = mw.export_one("taxrate", "taxcode=`X`")
bas['G2'] = round(float(data['netreceived'])) + round(float(data['gstreceived']))
bas['G1'] += bas['G2']
# tax free
data = mw.export_one("taxrate", "taxcode=`F`")
bas['G3'] = round(float(data['netreceived'])) + round(float(data['gstreceived']))
bas['G1'] += bas['G3']
# input taxed
data = mw.export_one("taxrate", "taxcode=`I`")
bas['G1'] += round(float(data['netreceived'])) + round(float(data['gstreceived']))
# capital purchases
data = mw.export_one("taxrate", "taxcode=`C`")
bas['G10'] = round(float(data['netreceived'])) + round(float(data['gstreceived']))
bas['G1'] += bas['G10']
data = mw.export_one("taxrate", "taxcode=`W`")
bas['w1'] = round(float(data['netpaid']))
data = mw.export_one("taxrate", "taxcode=`P`")
bas['w2'] = -round(float(data['netpaid']))
data = mw.export_one("taxrate", "taxcode=`U`")
bas['w4'] = -round(float(data['netpaid']))
return bas
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-t7', '--payg_installment', type=int, required=True)
args = parser.parse_args()
bas = get_bas_data()
create_transactions(gst_on_sales = bas['1A'],
gst_on_purchases = bas['1B'],
payg_installment = args.payg_installment,
payg_withheld = bas['W2'] + bas['W4'],
report_date = bas['reportdate']
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment