Пример #1
0
 def _portal_post_check_attachments(self, attachment_ids, attachment_tokens):
     if len(attachment_tokens) != len(attachment_ids):
         raise UserError(_("An access token must be provided for each attachment."))
     for (attachment_id, access_token) in zip(attachment_ids, attachment_tokens):
         try:
             CustomerPortal._document_check_access(self, 'ir.attachment', attachment_id, access_token)
         except (AccessError, MissingError):
             raise UserError(_("The attachment %s does not exist or you do not have the rights to access it.", attachment_id))
Пример #2
0
    def portal_chatter_post(self,
                            res_model,
                            res_id,
                            message,
                            redirect=None,
                            attachment_ids='',
                            attachment_tokens='',
                            **kw):
        """Create a new `mail.message` with the given `message` and/or
        `attachment_ids` and redirect the user to the newly created message.

        The message will be associated to the record `res_id` of the model
        `res_model`. The user must have access rights on this target document or
        must provide valid identifiers through `kw`. See `_message_post_helper`.
        """
        url = redirect or (request.httprequest.referrer
                           and request.httprequest.referrer +
                           "#discussion") or '/my'

        res_id = int(res_id)

        attachment_ids = [
            int(attachment_id) for attachment_id in attachment_ids.split(',')
            if attachment_id
        ]
        attachment_tokens = [
            attachment_token
            for attachment_token in attachment_tokens.split(',')
            if attachment_token
        ]
        if len(attachment_tokens) != len(attachment_ids):
            raise UserError(
                _("An access token must be provided for each attachment."))
        for (attachment_id, access_token) in zip(attachment_ids,
                                                 attachment_tokens):
            try:
                CustomerPortal._document_check_access(self, 'ir.attachment',
                                                      attachment_id,
                                                      access_token)
            except (AccessError, MissingError):
                raise UserError(
                    _("The attachment %s does not exist or you do not have the rights to access it."
                      ) % attachment_id)

        if message or attachment_ids:
            # message is received in plaintext and saved in html
            if message:
                message = plaintext2html(message)
            message = _message_post_helper(res_model=res_model,
                                           res_id=res_id,
                                           token=kw.get('token'),
                                           _hash=kw.get('hash'),
                                           pid=kw.get('pid'),
                                           message=message,
                                           send_after_commit=False,
                                           attachment_ids=attachment_ids)

        return request.redirect(url)
Пример #3
0
    def _post_process_portal_attachments(self, message, res_model, res_id,
                                         attachment_ids, attachment_tokens):
        """Associate "pending" attachments to a message and its main record.

        The user must have the rights to all attachments or he must provide a
        valid access_token for each of them. The attachments have to be on a
        "pending" state as well: res_id=0 and res_model='mail.compose.message'.

        :param message: the related message on which to link the attachments
        :type message: recordset of one `mail.message`

        :param res_model: the related model that will be saved on the attachment
        :type res_model: string

        :param res_id: the id of the record that will be saved on the attachment
        :type res_id: int

        :param attachment_ids: id of the attachments to associate
        :type attachment_ids: iterable of int

        :param attachment_tokens: access_token of the attachments to associate.
            Must always be the same length as `attachment_ids`, but only has to
            contain a valid access_token if the user does not have the rights to
            access the attachment without token.
        :type attachment_tokens: iterable of string
        """
        message.ensure_one()
        attachments = request.env['ir.attachment'].sudo()
        for (attachment_id, access_token) in zip(attachment_ids,
                                                 attachment_tokens):
            try:
                attachment = CustomerPortal._document_check_access(
                    self, 'ir.attachment', attachment_id, access_token)
                if attachment.res_model == 'mail.compose.message' and attachment.res_id == 0:
                    attachments += attachment
            except (AccessError, MissingError):
                pass
        attachments.write({'res_model': res_model, 'res_id': res_id})
        message.attachment_ids |= attachments
Пример #4
0
    def _get_invoices(self,
                      Order,
                      values,
                      page=1,
                      date_begin=None,
                      date_end=None,
                      sortby=None,
                      **kw):
        partner = request.env.user.partner_id
        domain = [('id', 'in', [x.id for x in Order.invoice_ids]),
                  ('type', 'in', ['out_invoice', 'out_refund']),
                  ('message_partner_ids', 'child_of',
                   [partner.commercial_partner_id.id]),
                  ('state', 'in', ['open', 'paid', 'cancel'])]
        AccountInvoice = request.env['account.invoice']
        _logger.info("Domain %s" % domain)
        searchbar_sortings = {
            'date': {
                'label': _('Invoice Date'),
                'order': 'date_invoice desc'
            },
            'duedate': {
                'label': _('Due Date'),
                'order': 'date_due desc'
            },
            'name': {
                'label': _('Reference'),
                'order': 'name desc'
            },
            'state': {
                'label': _('Status'),
                'order': 'state'
            },
        }
        # default sort by order
        if not sortby:
            sortby = 'date'
        order = searchbar_sortings[sortby]['order']

        archive_groups = CustomerPortal._get_archive_groups(
            CustomerPortal, 'account.invoice', domain)
        if date_begin and date_end:
            domain += [('create_date', '>', date_begin),
                       ('create_date', '<=', date_end)]

        # count for pager
        invoice_count = AccountInvoice.search_count(domain)

        # pager
        pager = portal_pager(url="/my/invoices",
                             url_args={
                                 'date_begin': date_begin,
                                 'date_end': date_end,
                                 'sortby': sortby
                             },
                             total=invoice_count,
                             page=page,
                             step=CustomerPortal._items_per_page)
        # content according to pager and archive selected
        invoices = AccountInvoice.search(domain,
                                         order=order,
                                         limit=CustomerPortal._items_per_page,
                                         offset=pager['offset'])
        values.update({
            'date': date_begin,
            'invoices': invoices,
            'page_name': 'invoice',
            'pager': pager,
            'archive_groups': archive_groups,
            'default_url': '/my/invoices',
            'searchbar_sortings': searchbar_sortings,
            'sortby': sortby,
        })
        return values