GnuCash  5.6-150-g038405b370+
test_business.py
1 from unittest import main
2 
3 from datetime import datetime, timezone, timedelta
4 
5 from gnucash import Account, \
6  ACCT_TYPE_RECEIVABLE, ACCT_TYPE_INCOME, ACCT_TYPE_BANK, \
7  GncNumeric
8 from gnucash.gnucash_business import Vendor, Employee, Customer, Job, Invoice, Entry
9 
10 from test_book import BookSession
11 
13  def setUp(self):
14  BookSession.setUp(self)
15 
16  self.today = datetime.today()
17 
18  self.bank = Account(self.book)
19  self.bank.SetType(ACCT_TYPE_BANK)
20  self.bank.SetCommodity(self.currency)
21  self.income = Account(self.book)
22  self.income.SetType(ACCT_TYPE_INCOME)
23  self.income.SetCommodity(self.currency)
24  self.receivable = Account(self.book)
25  self.receivable.SetType(ACCT_TYPE_RECEIVABLE)
26  self.receivable.SetCommodity(self.currency)
27 
28  self.customer = Customer(self.book,'CustomerID',self.currency)
29  self.vendor = Vendor(self.book,'VendorID',self.currency)
30  self.employee = Employee(self.book,'EmployeeID',self.currency)
31  self.job = Job(self.book,'JobID',self.customer)
32 
33  self.invoice = Invoice(self.book,'InvoiceID',self.currency,self.customer)
34  self.invoice.SetDateOpened(self.today)
35  entry = Entry(self.book)
36  entry.SetDate(self.today)
37  entry.SetDescription("Some income")
38  entry.SetQuantity(GncNumeric(1))
39  entry.SetInvAccount(self.income)
40  entry.SetInvPrice(GncNumeric(100))
41  self.invoice.AddEntry(entry)
42 
43  self.invoice.PostToAccount(self.receivable,
44  self.today, self.today, "", True, False)
45 
47  def test_equal(self):
48  self.assertTrue( self.vendor.Equal( self.vendor.GetVendor() ) )
49  self.assertTrue( self.customer.Equal( self.job.GetOwner() ) )
50  self.assertTrue( self.customer.Equal( self.invoice.GetOwner() ) )
51 
52  def test_employee_name(self):
53  NAME = 'John Doe'
54  self.assertEqual( '', self.employee.GetUsername() )
55  self.employee.SetUsername(NAME)
56  self.assertEqual( NAME, self.employee.GetUsername() )
57 
58  def test_post(self):
59  utc_offset = datetime.now().astimezone().utcoffset()
60  now = datetime.now().astimezone()
61  neutral_time = (now + utc_offset).astimezone(timezone.utc).replace(hour=10, minute=59, second=0, microsecond=0)
62  if utc_offset > timedelta(hours=13):
63  neutral_time -= utc_offset - timedelta(hours=13);
64  if utc_offset < timedelta(hours=-10):
65  neutral_time += timedelta(hours=-10) - utc_offset
66  self.assertEqual(neutral_time,
67  self.invoice.GetDatePosted().astimezone(timezone.utc))
68  self.assertTrue( self.invoice.IsPosted() )
69 
70  def test_owner(self):
71  OWNER = self.invoice.GetOwner()
72  self.assertTrue( self.customer.Equal( OWNER ) )
73 
74  def test_commodities(self):
75  self.assertTrue( self.currency.equal( self.customer.GetCommoditiesList()[0] ) )
76 
77 if __name__ == '__main__':
78  main()
The primary numeric class for representing amounts and values.
Definition: gnc-numeric.hpp:60