Tips and Tricks (internal only)

Welcome!

This community is for professionals and enthusiasts of our products and services. Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

0

Verschillende lay outs per helpdesk team

Avatar
Mitchell Berendhuysen
Avatar
Negeren
1 Antwoord
0
Avatar
Mitchell Berendhuysen
Beste antwoord


Het model heeft een aantal ouders. Al deze ouders hebben functies gedefineerd waarmee dingen als de chatter makkelijk aan gestuurd kunnen worden. Het helpdesk.ticket model heeft er 5.

classHelpdeskTicket(models.Model):
    _name 'helpdesk.ticket' 
    _description 'Helpdesk Ticket'
    _order 'priority desc, id desc' 
    _inherit = ['portal.mixin''mail.thread.cc''utm.mixin''rating.mixin''mail.activity.mixin']
 

Het mail.thread.cc model heeft in dit geval ook een ouder, het mail.thread model. Op dat model word een functie gedefineerd waar de organisatie in de context word door gegeven.

 

    @api.model
    def _notify_prepare_template_context(self, message, msg_vals, model_description=False, mail_auto_delete=True):
        # compute send user and its related signature
        signature = ''
        user = self.env.user
        author = message.env['res.partner'].browse(msg_vals.get('author_id')) if msg_vals else message.author_id
        model = msg_vals.get('model') if msg_vals else message.model
        add_sign = msg_vals.get('add_sign') if msg_vals else message.add_sign
        subtype_id = msg_vals.get('subtype_id') if msg_vals else message.subtype_id.id
        message_id = message.id
        record_name = msg_vals.get('record_name') if msg_vals else message.record_name
        author_user = user if user.partner_id == author else author.user_ids[0] if author and author.user_ids else False
        # trying to use user (self.env.user) instead of browing user_ids if he is the author will give a sudo user,
        # improving access performances and cache usage.
        if author_user:
            user = author_user
            if add_sign:
                signature = user.signature
        else:
            if add_sign:
                signature = "<p>-- <br/>%s</p>" % author.name

        company = self.company_id.sudo() if self and 'company_id' in self else user.company_id
        if company.website:
            website_url = 'http://%s' % company.website if not company.website.lower().startswith(('http:', 'https:')) else company.website
        else:
            website_url = False

        # Retrieve the language in which the template was rendered, in order to render the custom
        # layout in the same language.
        # TDE FIXME: this whole brol should be cleaned !
        lang = self.env.context.get('lang')
        if {'default_template_id', 'default_model', 'default_res_id'} <= self.env.context.keys():
            template = self.env['mail.template'].browse(self.env.context['default_template_id'])
            if template and template.lang:
                lang = template._render_lang([self.env.context['default_res_id']])[self.env.context['default_res_id']]

        if not model_description and model:
            model_description = self.env['ir.model'].with_context(lang=lang)._get(model).display_name

        tracking = []
        if msg_vals.get('tracking_value_ids', True) if msg_vals else bool(self): # could be tracking
            for tracking_value in self.env['mail.tracking.value'].sudo().search([('mail_message_id', '=', message.id)]):
                groups = tracking_value.field_groups
                if not groups or self.env.is_superuser() or self.user_has_groups(groups):
                    tracking.append((tracking_value.field_desc,
                                    tracking_value.get_old_display_value()[0],
                                    tracking_value.get_new_display_value()[0]))

        is_discussion = subtype_id == self.env['ir.model.data'].xmlid_to_res_id('mail.mt_comment')

        return {
            'message': message,
            'signature': signature,
            'website_url': website_url,
            'company': company,
            'model_description': model_description,
            'record': self,
            'record_name': record_name,
            'tracking_values': tracking,
            'is_discussion': is_discussion,
            'subtype': message.subtype_id,
            'lang': lang,
        }

 

Hier refereert self naar het model in kwestie. in dit geval de helpdesk.ticket. Op dat model bestaat een veld genaamd x_company2 (toegevoegd met studio) waar een waarde ingevuld kan worden.

Deze regel wordt veranderd naar het onderstaande in een aparte module op het model helpdesk.ticket zodat andere modellen die deze ouder functies ook gebruiken niet worden aangepast.

 

        company = self.x_company2 if self and 'x_company2' in self else self.company_id.sudo() or user.company_id 

 



Avatar
Negeren