def save(self, *args, **kwargs):
<EOL>if not hasattr(self,'<STR_LIT>') or not hasattr(self,'<STR_LIT>'):<EOL><INDENT>if self.approved and not self.approvalDate:<EOL><INDENT>self.approvalDate = timezone.now()<EOL><DEDENT>if self.paid and not self.paymentDate:<EOL><INDENT>self.paymentDate = timezone.now()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if self.approved and not self.approvalDate and not self.__approvalDate:<EOL><INDENT>self.approvalDate = timezone.now()<EOL><DEDENT>if self.paid and not self.paymentDate and not self.__paymentDate:<EOL><INDENT>self.paymentDate = timezone.now()<EOL><DEDENT><DEDENT>if self.expenseRule and not self.payTo:<EOL><INDENT>this_loc = getattr(self.expenseRule,'<STR_LIT:location>',None)<EOL>this_member = getattr(self.expenseRule,'<STR_LIT:location>',None)<EOL>if this_loc:<EOL><INDENT>self.payTo = TransactionParty.objects.get_or_create(<EOL>location=this_loc,<EOL>defaults={'<STR_LIT:name>': this_loc.name}<EOL>)[<NUM_LIT:0>]<EOL><DEDENT>elif this_member:<EOL><INDENT>self.payTo = TransactionParty.objects.get_or_create(<EOL>staffMember=this_member,<EOL>defaults={<EOL>'<STR_LIT:name>': this_member.fullName,<EOL>'<STR_LIT:user>': getattr(this_member,'<STR_LIT>',None)<EOL>}<EOL>)[<NUM_LIT:0>]<EOL><DEDENT><DEDENT>if not self.accrualDate:<EOL><INDENT>if self.event and self.event.month:<EOL><INDENT>self.accrualDate = self.event.eventoccurrence_set.order_by('<STR_LIT>').filter(**{'<STR_LIT>': self.event.month}).last().endTime<EOL><DEDENT>elif self.submissionDate:<EOL><INDENT>self.accrualDate = self.submissionDate<EOL><DEDENT>else:<EOL><INDENT>self.submissionDate = timezone.now()<EOL>self.accrualDate = self.submissionDate<EOL><DEDENT><DEDENT>if self.hours and not self.wageRate and not self.total and not getattr(getattr(self,'<STR_LIT>',None),'<STR_LIT:location>',None) and self.category:<EOL><INDENT>self.wageRate = self.category.defaultRate<EOL><DEDENT>elif self.hours and not self.wageRate and not self.total and getattr(getattr(self,'<STR_LIT>',None),'<STR_LIT:location>',None):<EOL><INDENT>self.wageRate = self.payTo.location.rentalRate<EOL><DEDENT>if self.hours and self.wageRate and not self.total:<EOL><INDENT>self.total = self.hours * self.wageRate<EOL><DEDENT>super(ExpenseItem, self).save(*args, **kwargs)<EOL>self.__approved = self.approved<EOL>self.__paid = self.paid<EOL>self.__approvalDate = self.approvalDate<EOL>self.__paymentDate = self.paymentDate<EOL>if self.attachment:<EOL><INDENT>try:<EOL><INDENT>self.attachment.folder = Folder.objects.get(name=_('<STR_LIT>'))<EOL><DEDENT>except ObjectDoesNotExist:<EOL><INDENT>pass<EOL><DEDENT>self.attachment.is_public = False<EOL>self.attachment.save()<EOL><DEDENT>
This custom save method ensures that an expense is not attributed to multiple categories.
It also ensures that the series and event properties are always associated with any
type of expense of that series or event.