def save(self, *args, **kwargs):
<EOL>if not hasattr(self,'<STR_LIT>'):<EOL><INDENT>if self.received and not self.receivedDate:<EOL><INDENT>self.receivedDate = timezone.now()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if self.received and not self.receivedDate and not self.__receivedDate:<EOL><INDENT>self.receivedDate = timezone.now()<EOL><DEDENT><DEDENT>if not self.accrualDate:<EOL><INDENT>if self.invoiceItem and self.invoiceItem.finalEventRegistration:<EOL><INDENT>min_event_time = self.invoiceItem.finalEventRegistration.event.eventoccurrence_set.filter(**{'<STR_LIT>':self.invoiceItem.finalEventRegistration.event.month}).first().startTime<EOL>self.accrualDate = min_event_time<EOL><DEDENT>elif self.event:<EOL><INDENT>self.accrualDate = self.event.eventoccurrence_set.order_by('<STR_LIT>').filter(**{'<STR_LIT>': self.event.month}).last().startTime<EOL><DEDENT>elif self.invoiceItem:<EOL><INDENT>self.accrualDate = self.invoiceItem.invoice.creationDate<EOL><DEDENT>elif self.receivedDate:<EOL><INDENT>self.accrualDate = self.receivedDate<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.invoiceItem and self.invoiceItem.finalEventRegistration:<EOL><INDENT>self.event = self.invoiceItem.finalEventRegistration.event<EOL><DEDENT>elif self.invoiceItem and self.invoiceItem.temporaryEventRegistration:<EOL><INDENT>self.event = self.invoiceItem.temporaryEventRegistration.event<EOL><DEDENT>if self.grossTotal is None and self.total:<EOL><INDENT>self.grossTotal = self.total<EOL><DEDENT>if self.total is None and self.grossTotal:<EOL><INDENT>self.total = self.grossTotal<EOL><DEDENT>super(RevenueItem, self).save(*args, **kwargs)<EOL>self.__received = self.received<EOL>self.__receivedDate = self.receivedDate<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 a revenue item is not attributed to multiple categories.
It also ensures that the series and event properties are always associated with any
type of revenue of that series or event.