Example #1
0
    def confirm(self, ids):
        "Send an email after sale is confirmed"
        super(Sale, self).confirm(ids)

        if has_request_context():
            for sale in self.browse(ids):
                self.send_confirmation_email(sale)
Example #2
0
    def default_price_list(user=None):
        """Get the pricelist of active user. In the
        event that the logged in user does not have a pricelist set against
        the user, the guest user's pricelist is chosen.

        :param user: active record of the nereid user
        """
        if not has_request_context():
            # Not a nereid request
            return None

        if user is not None and user.party.sale_price_list:
            # If a user was provided and the user has a pricelist, use
            # that
            return user.party.sale_price_list.id

        if not current_user.is_anonymous() and \
                current_user.party.sale_price_list:
            # If the currently logged in user has a pricelist defined, use
            # that
            return current_user.party.sale_price_list.id

        # Since there is no pricelist for the user, use the guest user's
        # pricelist if one is defined.
        guest_user = request.nereid_website.guest_user
        if guest_user.party.sale_price_list:
            return guest_user.party.sale_price_list.id

        return None
Example #3
0
    def default_price_list():
        """Get the pricelist of active user. In the
        event that the logged in user does not have a pricelist set against
        the user, the channel's pricelist is chosen.

        :param user: active record of the nereid user
        """
        User = Pool().get('res.user')
        user = User(Transaction().user)
        channel_price_list = user.current_channel.price_list.id if \
            user.current_channel else None

        if not has_request_context():
            # Not a nereid request
            return channel_price_list

        # If control reaches here, then this is a nereid request. Lets try
        # and personalise the pricelist of the user logged in.
        if current_user.is_anonymous():
            # Sorry anonymous users, you get the shop price
            return channel_price_list

        if current_user.party.sale_price_list:
            # There is a sale pricelist for the specific user's party.
            return current_user.party.sale_price_list.id

        return channel_price_list
Example #4
0
    def confirm(cls, sales):
        "Send an email after sale is confirmed"
        super(Sale, cls).confirm(sales)

        if has_request_context():
            for sale in sales:
                sale.send_confirmation_email()
Example #5
0
    def default_price_list():
        """Get the pricelist of active user. In the
        event that the logged in user does not have a pricelist set against
        the user, the shop's pricelist is chosen.

        :param user: active record of the nereid user
        """
        User = Pool().get('res.user')
        user = User(Transaction().user)
        shop_price_list = user.shop.price_list.id if user.shop else None

        if not has_request_context():
            # Not a nereid request
            return shop_price_list

        # If control reaches here, then this is a nereid request. Lets try
        # and personalise the pricelist of the user logged in.
        if current_user.is_anonymous():
            # Sorry anonymous users, you get the shop price
            return shop_price_list

        if current_user.party.sale_price_list:
            # There is a sale pricelist for the specific user's party.
            return current_user.party.sale_price_list.id

        return shop_price_list
Example #6
0
 def validate_for_product_inventory(self):
     """
     This method validates the sale line against the product's inventory
     attributes. This method requires request context.
     """
     if has_request_context() and not self.product.can_buy_from_eshop():
         flash(_('This product is no longer available'))
         abort(redirect(request.referrer))
Example #7
0
 def validate_for_product_inventory(self):
     """
     This method validates the sale line against the product's inventory
     attributes. This method requires request context.
     """
     if has_request_context() and not self.product.can_buy_from_eshop():
         flash(_("This product is no longer available"))
         abort(redirect(request.referrer))
Example #8
0
 def default_active():
     """
     If the user gets created from the web the activation should happen
     through the activation link. However, users created from tryton
     interface are activated by default
     """
     if has_request_context():
         return False
     return True
Example #9
0
 def default_active():
     """
     If the user gets created from the web the activation should happen
     through the activation link. However, users created from tryton
     interface are activated by default
     """
     if has_request_context():
         return False
     return True
Example #10
0
    def confirm(cls, sales):
        "Send an email after sale is confirmed"
        super(Sale, cls).confirm(sales)

        if has_request_context():
            for sale in sales:

                # Change party name to invoice address name for guest user
                if current_user.is_anonymous():
                    sale.party.name = sale.invoice_address.name
                    sale.party.save()
Example #11
0
    def _get_email_template_context(self):
        """
        Update context
        """
        context = super(Sale, self)._get_email_template_context()

        if has_request_context() and not current_user.is_anonymous():
            customer_name = current_user.display_name
        else:
            customer_name = self.party.name

        context.update({
            'url_for': lambda *args, **kargs: url_for(*args, **kargs),
            'has_request_context': lambda *args, **kargs: has_request_context(
                *args, **kargs),
            'current_user': current_user,
            'customer_name': customer_name,
            'to_json': lambda *args, **kargs: json.dumps(*args, **kargs),
        })
        return context
Example #12
0
    def default_employee():
        User = Pool().get('res.user')

        if 'employee' in Transaction().context:
            return Transaction().context['employee']

        user = User(Transaction().user)
        if user.employee:
            return user.employee.id

        if has_request_context() and request.nereid_user.employee:
            return request.nereid_user.employee.id
Example #13
0
    def default_employee():
        User = Pool().get('res.user')

        if 'employee' in Transaction().context:
            return Transaction().context['employee']

        user = User(Transaction().user)
        if user.employee:
            return user.employee.id

        if has_request_context() and current_user.employee:
            return current_user.employee.id
Example #14
0
    def _get_receiver_email_address(self):
        """
        Update reciever's email address(s)
        """
        to_emails = set()
        if self.party.email:
            to_emails.add(self.party.email.lower())
        if has_request_context() and not current_user.is_anonymous() and \
                current_user.email:
            to_emails.add(current_user.email.lower())

        return list(to_emails)
Example #15
0
 def create(self, values):
     if has_request_context():
         values['created_by'] = request.nereid_user.id
         if values['type'] == 'task':
             values.setdefault('participants', [])
             values['participants'].append(
                 ('add', [request.nereid_user.id])
             )
     else:
         # TODO: identify the nereid user through employee
         pass
     return super(Project, self).create(values)
Example #16
0
    def create(self, values):
        """
        Update create to save uploaded by

        :param values: A dictionary
        """
        if has_request_context():
            values['uploaded_by'] = request.nereid_user.id
        #else:
            # TODO: try to find the nereid user from the employee
            # if an employee made the update

        return super(IrAttachment, self).create(values)
Example #17
0
    def create(cls, vlist):
        """
        Create a Task and add current user as participant of the project

        :param vlist: List of dictionaries of values to create
        """
        for values in vlist:
            if has_request_context():
                if values["type"] == "task":
                    values.setdefault("participants", []).append(("add", [request.nereid_user.id]))
            else:
                # TODO: identify the nereid user through employee
                pass
        return super(Task, cls).create(vlist)
Example #18
0
    def create(cls, vlist):
        '''
        Create a Task and add current user as participant of the project

        :param vlist: List of dictionaries of values to create
        '''
        for values in vlist:
            if has_request_context():
                if values['type'] == 'task' and not current_user.is_anonymous():
                    values.setdefault('participants', []).append(
                        ('add', [current_user.id])
                    )
            else:
                # TODO: identify the nereid user through employee
                pass
        return super(Task, cls).create(vlist)
Example #19
0
 def serialize(self, purpose=None):
     rv = {
         'create_date': self.create_date.isoformat(),
         "objectType": self.__name__,
         "id": self.id,
         "updatedBy": self.uploaded_by.serialize('listing'),
         "displayName": self.name,
         "description": self.description,
     }
     if has_request_context():
         rv['downloadUrl'] = url_for(
             'project.work.download_file',
             attachment_id=self.id,
             task=Transaction().context.get('task'),
         )
     return rv
Example #20
0
    def create(cls, vlist):
        '''
        Create a Task and add current user as participant of the project

        :param vlist: List of dictionaries of values to create
        '''
        for values in vlist:
            if has_request_context():
                if values['type'] == 'task' and not current_user.is_anonymous(
                ):
                    values.setdefault('participants', []).append(
                        ('add', [current_user.id]))
            else:
                # TODO: identify the nereid user through employee
                pass
        return super(Task, cls).create(vlist)
Example #21
0
    def create_history_line(self, project, changed_values):
        """
        Creates a history line from the changed values of a project.work
        """
        if changed_values:
            data = {}

            # TODO: Also create a line when assigned user is cleared from task
            for field in ('assigned_to', 'state',
                    'constraint_start_time', 'constraint_finish_time'):
                if field not in changed_values or not changed_values[field]:
                    continue
                data['previous_%s' % field] = getattr(project, field)
                data['new_%s' % field] = changed_values[field]

            if data:
                if has_request_context():
                    data['updated_by'] = request.nereid_user.id
                else:
                    # TODO: try to find the nereid user from the employee
                    # if an employee made the update
                    pass
                data['project'] = project.id
                return self.create(data)
Example #22
0
 def default_user():
     if has_request_context() and not current_user.is_anonymous:
         return current_user.id
Example #23
0
 def default_user():
     if has_request_context() and not current_user.is_anonymous:
         return current_user.id
Example #24
0
 def default_sessionid():
     if has_request_context():
         return session.sid
Example #25
0
 def default_website():
     if has_request_context():
         return current_website.id
Example #26
0
 def default_author():
     if has_request_context():
         return current_user.id
Example #27
0
 def default_author():
     if has_request_context():
         return request.nereid_user.id
Example #28
0
 def default_website():
     if has_request_context():
         return current_website.id
Example #29
0
 def default_sessionid():
     if has_request_context():
         return session.sid
Example #30
0
 def default_author():
     if has_request_context():
         return request.nereid_user.id
Example #31
0
 def default_uploaded_by():
     """
     Sets current nereid user as default for uploaded_by
     """
     if has_request_context():
         return request.nereid_user.id