Пример #1
0
    def partner_desinterested(self,
                              comment=False,
                              contacted=False,
                              spam=False):
        if contacted:
            message = '<p>%s</p>' % _(
                'I am not interested by this lead. I contacted the lead.')
        else:
            message = '<p>%s</p>' % _(
                'I am not interested by this lead. I have not contacted the lead.'
            )
        partner_ids = self.env['res.partner'].search([
            ('id', 'child_of',
             self.env.user.partner_id.commercial_partner_id.id)
        ])
        self.message_unsubscribe(partner_ids=partner_ids.ids)
        if comment:
            message += '<p>%s</p>' % html_escape(comment)
        self.message_post(body=message)
        values = {
            'partner_assigned_id': False,
        }

        if spam:
            tag_spam = self.env.ref(
                'website_crm_partner_assign.tag_portal_lead_is_spam', False)
            if tag_spam and tag_spam not in self.tag_ids:
                values['tag_ids'] = [(4, tag_spam.id, False)]
        if partner_ids:
            values['partner_declined_ids'] = [(4, p, 0)
                                              for p in partner_ids.ids]
        self.sudo().write(values)
Пример #2
0
    def remove(self, ids, **kwargs):
        """ Removes a web-based image attachment if it is used by no view (template)

        Returns a dict mapping attachments which would not be removed (if any)
        mapped to the views preventing their removal
        """
        Attachment = attachments_to_remove = request.env['ir.attachment']
        Views = request.env['ir.ui.view']

        # views blocking removal of the attachment
        removal_blocked_by = {}

        for attachment in Attachment.browse(ids):
            # in-document URLs are html-escaped, a straight search will not
            # find them
            url = tools.html_escape(attachment.local_url)
            views = Views.search([
                "|", ('arch_db', 'like', '"%s"' % url),
                ('arch_db', 'like', "'%s'" % url)
            ])

            if views:
                removal_blocked_by[attachment.id] = views.read(['name'])
            else:
                attachments_to_remove += attachment
        if attachments_to_remove:
            attachments_to_remove.unlink()
        return removal_blocked_by
Пример #3
0
 def partner_interested(self, comment=False):
     message = _('<p>I am interested by this lead.</p>')
     if comment:
         message += '<p>%s</p>' % html_escape(comment)
     for lead in self:
         lead.message_post(body=message)
         lead.sudo().convert_opportunity(
             lead.partner_id.id)  # sudo required to convert partner data
Пример #4
0
 def _execute_command_lead(self, **kwargs):
     partner = self.env.user.partner_id
     key = kwargs['body']
     channel_partners = self.env['mail.channel.partner'].search(
         [('partner_id', '!=', partner.id), ('channel_id', '=', self.id)],
         limit=1)
     if key.strip() == '/lead':
         msg = self._define_command_lead()['help']
     else:
         lead = self._convert_visitor_to_lead(partner, channel_partners,
                                              key)
         msg = _(
             'Created a new lead: <a href="#" data-oe-id="%s" data-oe-model="crm.lead">%s</a>'
         ) % (lead.id, html_escape(lead.name))
     self._send_transient_message(partner, msg)
Пример #5
0
 def report(self, output_format, report_name, token, report_id=False, **kw):
     uid = request.session.uid
     domain = [('create_uid', '=', uid)]
     stock_traceability = request.env[
         'stock.traceability.report'].with_user(uid).search(domain, limit=1)
     line_data = json.loads(kw['data'])
     try:
         if output_format == 'pdf':
             response = request.make_response(
                 stock_traceability.with_context(
                     active_id=report_id).get_pdf(line_data),
                 headers=[('Content-Type', 'application/pdf'),
                          ('Content-Disposition', 'attachment; filename=' +
                           'stock_traceability' + '.pdf;')])
             response.set_cookie('fileToken', token)
             return response
     except Exception as e:
         se = _serialize_exception(e)
         error = {
             'code': 200,
             'message': 'Harpiya Server Error',
             'data': se
         }
         return request.make_response(html_escape(json.dumps(error)))