source: trunk/ShoeBox/ShoeBoxAccount.py @ 5

Revision 5, 2.6 KB checked in by nigel.sim, 5 years ago (diff)
Line 
1#
2# ShoeBox
3#  A start product for Plone - ShoeBox
4#
5# ShoeBox.py
6#  The Product
7#
8# Author: Christian Koller <admin@iecw.net>
9#
10# Released under GNU GPL v2 or later
11#
12from zLOG import LOG, INFO
13
14from Products.Archetypes.public import *
15from Products.ShoeBox.config import PROJECTNAME
16from Products.CMFCore import CMFCorePermissions
17from Products.validation import V_REQUIRED
18from AccessControl import ClassSecurityInfo
19from DocumentTemplate import sequence
20
21from Products.ShoeBox.config import PROJECTNAME
22
23class ShoeBoxAccount(BaseFolder):
24    """ Shoe Box account """
25    meta_type = 'ShoeBoxAccount'
26   
27    security  = ClassSecurityInfo()
28   
29    _at_rename_after_creation = True
30   
31    allowed_content_types = (
32            'ShoeBoxEntry',
33            )
34   
35    ##
36    ##  The Schema includes two variables, on for the Repository itself and one for a Path within the Repository
37    ##
38   
39    ## Set the icon for the ShoeBox
40    content_icon = 'shoebox.png'
41   
42    ##
43    ##  Redefine the view tab (action) for ShoeBox
44    ##
45    actions = (
46            {
47                    'id': 'view',
48                    'name': 'View',
49                    'action': 'string:${object_url}/shoeboxaccount_view',
50                    'permissions': (CMFCorePermissions.View,),
51                    'category':'object',
52            },
53    )
54   
55    def getEntries(self, removeOrphans=True):
56        """
57        Return the account entries for this account
58        """
59        entries = self.getFolderContents(batch=False,
60            contentFilter={'portal_type' : 'ShoeBoxEntry'}, full_objects=True)
61        if removeOrphans:
62            for e in entries:
63                if e.account != self.id:
64                    entries.remove(e)
65        entries = sequence.sort(entries, (('date','cmp'),))
66        return entries
67   
68    def initializeArchetype(self, **kwargs):
69        BaseFolder.initializeArchetype(self, **kwargs)
70        LOG("ShoeBoxAccount",INFO, "initializeArchetype")
71       
72    def at_post_edit_script(self):
73        entries = self.getEntries(False)
74        for e in entries:
75            e.account = self.id
76            e.update()
77       
78    def getSummary(self):
79        """
80        Returns the summary of transactions
81        [in, out, balance]
82        """
83        entries = self.getEntries()
84        inComing = 0
85        outGoing = 0
86        for e in entries:
87            if e.direction == 'Incoming':
88                inComing += e.getAmount()
89            else:
90                outGoing += e.getAmount()
91        balance = inComing - outGoing
92        return [inComing, outGoing, balance]
93## Register the new type within Zope
94registerType(ShoeBoxAccount,PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.