<commit_before># -*- coding: utf-8 -*-
##############################################################################
#
#    Copyright (C) 2014-2017 Compassion CH (http://www.compassion.ch)
#    Releasing children from poverty in Jesus' name
#    @author: <NAME> <<EMAIL>>
#
#    The licence is in the file __manifest__.py
#
##############################################################################
import logging
import re
import traceback
from datetime import datetime

from odoo.addons.queue_job.job import job, related_action

from odoo import api, models, fields, _
from odoo.exceptions import UserError
from ..mappings import base_mapping as mapping
from ..tools.onramp_connector import OnrampConnector

logger = logging.getLogger(__name__)

try:
    import simplejson as json
except ImportError:
    logger.warning("Please install simplejson")


class GmcMessagePoolProcess(models.TransientModel):
    _name = 'gmc.message.pool.process'

    @api.multi
    def process_messages(self):
        active_ids = self.env.context.get('active_ids', [])
        self.env['gmc.message.pool'].browse(active_ids).process_messages()
        action = {
            'name': 'Message treated',
            'type': 'ir.actions.act_window',
            'view_type': 'form',
            'view_mode': 'tree, form',
            'views': [(False, 'tree'), (False, 'form')],
            'res_model': 'gmc.message.pool',
            'domain': [('id', 'in', active_ids)],
            'target': 'current',
        }

        return action


class GmcMessagePool(models.Model):
    """ Pool of messages exchanged between Compassion CH and GMC. """
    _name = 'gmc.message.pool'
    _inherit = ['mail.thread', 'ir.needaction_mixin']
    _description = 'Connect Message'

    _order = 'date desc'

    ##########################################################################
    #                                 FIELDS                                 #
    ##########################################################################
    name = fields.Char(
        related='action_id.name', readonly=True)
    description = fields.Text(
        'Action to execute', related='action_id.description', readonly=True)
    direction = fields.Selection(related='action_id.direction', store=True)
    object_id = fields.Integer('Resource')
    object_ids = fields.Char(
        'Related records', help='Used for incoming messages containing '
                                'several records. (ids separated by commas)')
    res_name = fields.Char(compute='_compute_res_name', store=True)
    partner_id = fields.Many2one('res.partner', 'Partner')

    request_id = fields.Char('Unique request ID', readonly=True)
    date = fields.Datetime(
        'Message Date', required=True,
        default=fields.Datetime.now)
    action_id = fields.Many2one(
        'gmc.action', 'GMC Message', ondelete='restrict',
        required=False, readonly=True)
    process_date = fields.Datetime(readonly=True, track_visibility='onchange')
    state = fields.Selection(
        [('new', _('New')),
         ('pending', _('Pending')),
         ('postponed', _('Postponed')),
         ('success', _('Success')),
         ('failure', _('Failure'))],
        'State', readonly=True, default='new', track_visibility='always')
    failure_reason = fields.Text(
        'Failure details', track_visibility='onchange')
    headers = fields.Text(readonly=True)
    content = fields.Text(readonly=True)
    answer = fields.Text(readonly=True)

    _sql_constraints = [
        ('request_id_uniq', 'UNIQUE(request_id)',
         _("You cannot have two requests with same id."))]

    ##########################################################################
    #                             FIELDS METHODS                             #
    ##########################################################################
    @api.depends('object_id', 'action_id')
    def _compute_res_name(self):
        for message in self:
            try:
                res_object = self.env[message.action_id.model].browse(
                    message.object_id)
                if res_object:
                    message.res_name = res_object.display_name
            except KeyError:
                message.res_name = 'Unknown'

    ##########################################################################
    #                              ORM METHODS                               #
    ##########################################################################
    @api.model
    def create(self, vals):<commit_msg>Let the content of message be editable<commit_after># -*- coding: utf-8 -*-
##############################################################################
#
#    Copyright (C) 2014-2017 Compassion CH (http://www.compassion.ch)
#    Releasing children from poverty in Jesus' name
#    @author: <NAME> <<EMAIL>>
#
#    The licence is in the file __manifest__.py
#
##############################################################################
import logging
import re
import traceback
from datetime import datetime

from odoo.addons.queue_job.job import job, related_action

from odoo import api, models, fields, _
from odoo.exceptions import UserError
from ..mappings import base_mapping as mapping
from ..tools.onramp_connector import OnrampConnector

logger = logging.getLogger(__name__)

try:
    import simplejson as json
except ImportError:
    logger.warning("Please install simplejson")


class GmcMessagePoolProcess(models.TransientModel):
    _name = 'gmc.message.pool.process'

    @api.multi
    def process_messages(self):
        active_ids = self.env.context.get('active_ids', [])
        self.env['gmc.message.pool'].browse(active_ids).process_messages()
        action = {
            'name': 'Message treated',
            'type': 'ir.actions.act_window',
            'view_type': 'form',
            'view_mode': 'tree, form',
            'views': [(False, 'tree'), (False, 'form')],
            'res_model': 'gmc.message.pool',
            'domain': [('id', 'in', active_ids)],
            'target': 'current',
        }

        return action


class GmcMessagePool(models.Model):
    """ Pool of messages exchanged between Compassion CH and GMC. """
    _name = 'gmc.message.pool'
    _inherit = ['mail.thread', 'ir.needaction_mixin']
    _description = 'Connect Message'

    _order = 'date desc'

    ##########################################################################
    #                                 FIELDS                                 #
    ##########################################################################
    name = fields.Char(
        related='action_id.name', readonly=True)
    description = fields.Text(
        'Action to execute', related='action_id.description', readonly=True)
    direction = fields.Selection(related='action_id.direction', store=True)
    object_id = fields.Integer('Resource')
    object_ids = fields.Char(
        'Related records', help='Used for incoming messages containing '
                                'several records. (ids separated by commas)')
    res_name = fields.Char(compute='_compute_res_name', store=True)
    partner_id = fields.Many2one('res.partner', 'Partner')

    request_id = fields.Char('Unique request ID', readonly=True)
    date = fields.Datetime(
        'Message Date', required=True,
        default=fields.Datetime.now)
    action_id = fields.Many2one(
        'gmc.action', 'GMC Message', ondelete='restrict',
        required=False, readonly=True)
    process_date = fields.Datetime(readonly=True, track_visibility='onchange')
    state = fields.Selection(
        [('new', _('New')),
         ('pending', _('Pending')),
         ('postponed', _('Postponed')),
         ('success', _('Success')),
         ('failure', _('Failure'))],
        'State', readonly=True, default='new', track_visibility='always')
    failure_reason = fields.Text(
        'Failure details', track_visibility='onchange')
    headers = fields.Text(readonly=True)
    content = fields.Text()
    answer = fields.Text(readonly=True)

    _sql_constraints = [
        ('request_id_uniq', 'UNIQUE(request_id)',
         _("You cannot have two requests with same id."))]

    ##########################################################################
    #                             FIELDS METHODS                             #
    ##########################################################################
    @api.depends('object_id', 'action_id')
    def _compute_res_name(self):
        for message in self:
            try:
                res_object = self.env[message.action_id.model].browse(
                    message.object_id)
                if res_object:
                    message.res_name = res_object.display_name
            except KeyError:
                message.res_name = 'Unknown'

    ##########################################################################
    #                              ORM METHODS                               #
    ##########################################################################
    @api.model
    def create(self, vals):
{'fraction_non_alphanumeric': 0.237308533916849, 'fraction_numerical': 0.0024070021881838076, 'mean_word_length': 2.852085967130215, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5036747', 'n_tokens_mistral': 2453, 'n_tokens_neox': 2317, 'n_words': 521}