示例#1
0
    def accounting(self):
        """
        return a Person Account.

        The NonDES person is a fictitious one that symbolize the Out Of Network accounting
        It permit to count money transfert between (entering or escaping) the DES and the market
        """
        try:
            nondes = Person.objects.get(name__exact=NONDES_NAME,
                                        surname__exact=NONDES_SURNAME)
        except Person.DoesNotExist:
            #Create accounting system for a NonDES in the DES accounting system

            #Possibility 1: Set DES as subject (@economic_subject) and create Accounting proxy
            #            des.subject.init_accounting_system()
            #            system = des.accounting.system
            #            system.add_account(parent_path='/', name='cash', kind=account_type.asset)

            #Possibility 2 (LF): Create fictitious person and use it as NonDES account

            #Create the fictitious person account without address and user
            nondes = Person(name=NONDES_NAME, surname=NONDES_SURNAME)
            nondes.save()

        return nondes.accounting
示例#2
0
    def accounting(self):
        """
        return a Person Account.

        The NonDES person is a fictitious one that symbolize the Out Of Network accounting
        It permit to count money transfert between (entering or escaping) the DES and the market
        """
        try:
            nondes = Person.objects.get(
                name__exact=NONDES_NAME,
                surname__exact=NONDES_SURNAME
            )
        except Person.DoesNotExist:
            #Create accounting system for a NonDES in the DES accounting system

            #Possibility 1: Set DES as subject (@economic_subject) and create Accounting proxy
#            des.subject.init_accounting_system()
#            system = des.accounting.system
#            system.add_account(parent_path='/', name='cash', kind=account_type.asset)

            #Possibility 2 (LF): Create fictitious person and use it as NonDES account

            #Create the fictitious person account without address and user
            nondes = Person(name = NONDES_NAME, surname = NONDES_SURNAME)
            nondes.save()

        return nondes.accounting
示例#3
0
    def profile_callback(self, user):

        user.first_name = self.cleaned_data['name']
        user.last_name = self.cleaned_data['surname']
        user.save()
        
        #2-Create base objects
        try:
            place, created = Place.objects.get_or_create(
                city=self.cleaned_data['city'],
                address='', name=''
            )
        except Place.MultipleObjectsReturned as e:
            places = Place.objects.filter(city=self.cleaned_data['city'], address='', name='')
            place = places[0]
            log.warning("Multiple places found: %s id = %s" % (
                place, map(lambda x : x.pk, places))
            )

        try:
            contact_email, created = \
                Contact.objects.get_or_create(flavour="EMAIL", value=self.cleaned_data['email'])
        except Contact.MultipleObjectsReturned as e:
            contacts = Contact.objects.filter(flavour="EMAIL", value=self.cleaned_data['email'])
            contact_email = contacts[0]
            log.warning("Multiple contact found: %s id = %s" % (
                contact_email, map(lambda x : x.pk, contacts))
            )

        try:
            contact_phone, created = \
                Contact.objects.get_or_create(flavour="PHONE", value=self.cleaned_data['phone'])
        except Contact.MultipleObjectsReturned as e:
            contacts = Contact.objects.filter(flavour="PHONE", value=self.cleaned_data['phone'])
            contact_phone = contacts[0]
            log.warning("Multiple contact found: %s id = %s" % (
                contact_phone, map(lambda x : x.pk, contacts))
            )
        
        #3-Create person
        # COMMENT matteo: even if there are already one (or more) persons with the same values (name, 
        # username, place) it is not a problem, the data will be normalized after.

        person = Person(
            name = self.cleaned_data['name'],
            surname = self.cleaned_data['surname'],
            address = place,
            user = user
        )
        person.save()
        person.contact_set.add( contact_email, contact_phone)

        gas = self.cleaned_data.get('gas_choice')
        if gas:

            # COMMENT fero: following our workflow we can't bind person to GAS now
            # we can bind User to role GAS Member for this GAS
            # in the activation phase (4a.) we would perform this step
            gm = GASMember( person=person, gas=gas )
            gm.save()
            #WAS: pr = ParamRole.get_role(GAS_MEMBER, gas=gas)
            #WAS: ppr = PrincipalParamRoleRelation.objects.create(user=user, role=pr)
            #WAS: ppr.save()

            given_token = self.cleaned_data.get('gas_registration_token')
            if given_token:
                token_comment_text = "%s%s" % (DESRegistrationForm.REGISTRATION_TOKEN_PREFIX, given_token)
                Comment.objects.create(
                            site = DjangoSite.objects.all()[0],
                            content_object=gm, 
                            comment=token_comment_text
                )
            #Send email for GAS_REFERRER_TECH
            techs = gas.tech_referrers_people
            if techs:
                #TODO Matteo: put also 'city' and 'phone' form fields in this email
                body = _("new registration from %(username)s %(usersurname)s with email %(email)s. User active status is %(active)s. Motivation: %(motivation)s...") % {
                    'username' : user.first_name,
                    'usersurname' : user.last_name,
                    'email' : user.email,
                    'active' : user.is_active,
                    'motivation' : self.cleaned_data['motivation'],
                }
                #from notification.models import Notice
                #GAS_REFERRER_TECH
                for tech in techs:
                    #TODO: Notification or send email
                    recipient = tech.user.email
                    recipient = tech.preferred_email_contacts
                    log.debug("Send email for tech %s with body %s" % (recipient, body))
                #FORUM
                #FIXME: not set! Quale è l'email del FORUM del GAS?
                if gas.orders_email_contact:
                    #TODO: Notification or send email
                    forum = gas.orders_email_contact.value
                    log.debug("Send email for FORUM %s with body %s" % (forum, body))

        supplier = self.cleaned_data.get('supplier_choice')
        if supplier:
            pr = ParamRole.get_role(SUPPLIER_REFERRER, supplier=supplier)
            ppr = PrincipalParamRoleRelation.objects.create(user=user, role=pr)
            ppr.save()