<commit_before># -*- coding: utf-8 -*-

from openerp import models, fields, api, _
from datetime import date


class prosecution(models.Model):

    """"""

    _name = 'legal.prosecution'
    _description = 'prosecution'
    _inherit = ['mail.thread']
    _rec_name = 'folder_name'

    @api.one
    def action_compute(self):
        name = ''
        if self.partner_id:
            name = self.partner_id.name[0]
        if self.prosecution_type_id:
            name += '-' + str(self.prosecution_type_id.code)
        name += '-' + self.env['ir.sequence'].get('legal.prosecution')
        self.folder_name = name

    def create(self, cr, uid, vals, context=None):
        name = ''
        partner_obj = self.pool['res.partner']
        prosecution_type_obj = self.pool['legal.prosecution_type']
        if vals.get('partner_id', False):
            name = partner_obj.browse(
                cr, uid, vals.get('partner_id', False), context=context).name[0]
        if vals.get('prosecution_type_id', False):
            name += '-' + str(prosecution_type_obj.browse(cr, uid,
                                                          vals.get('prosecution_type_id', False), context=context).code)
        name += '-' + \
            self.pool['ir.sequence'].get(cr, uid, 'legal.prosecution')
        vals['folder_name'] = name
        vals['opening_date_folder'] = date.today()
        return super(prosecution, self).create(cr, uid, vals, context=None)

    @api.one
    @api.depends('radication_ids')
    def _get_data(self):
        if self.radication_ids:
            self.current_judged_id = self.radication_ids[
                0].judged_id.id
            self.number_current_file = self.radication_ids[0].num_filed
            if not self.radication_ids[0].num_3_ins:
                if not self.radication_ids[0].num_2_ins:
                    if not self.radication_ids[0].num_1_ins:
                        self.last_complete_instance = ''
                    else:
                        self.last_complete_instance = self.radication_ids[
                            0].num_1_ins
                else:
                    self.last_complete_instance = self.radication_ids[
                        0].num_2_ins
            else:
                self.last_complete_instance = self.radication_ids[0].num_3_ins

        else:
            self.last_complete_instance = ''
            self.current_judged_id = []
            self.number_current_file = ''

    @api.one
    def _audiences_event_count(self):
        self.audiences_event_count = len(self.sudo().event_audiences_ids)

    @api.one
    def _expiry_event_count(self):
        self.expiry_event_count = len(self.sudo().event_expiry_ids)

    @api.one
    def _calculate_amount(self):
        self.claim_amount = sum([x.total for x in self.claim_ids])

    @api.one
    @api.constrains('member_ids')
    def action_follow(self):
        return self.message_subscribe_users(self.member_ids.ids)

    @api.one
    @api.onchange('prosecution_type_id')
    def auto_complete_auxiliar_field(self):
        self.auxiliary_ids = self.env[
            'legal.auxiliary']
        auxiliary_field_obj = self.env['legal.auxiliary.field']
        if self.prosecution_type_id:
            auxiliary_field_ids = auxiliary_field_obj.search(
                [('prosecution_type_id', '=', self.prosecution_type_id.id)])
            lines = []
            for line in auxiliary_field_ids:
                values = {
                    'field_id': line.id,<commit_msg>FIX calculate funtion to events<commit_after># -*- coding: utf-8 -*-

from openerp import models, fields, api, _
from datetime import date


class prosecution(models.Model):

    """"""

    _name = 'legal.prosecution'
    _description = 'prosecution'
    _inherit = ['mail.thread']
    _rec_name = 'folder_name'

    @api.one
    def action_compute(self):
        name = ''
        if self.partner_id:
            name = self.partner_id.name[0]
        if self.prosecution_type_id:
            name += '-' + str(self.prosecution_type_id.code)
        name += '-' + self.env['ir.sequence'].get('legal.prosecution')
        self.folder_name = name

    def create(self, cr, uid, vals, context=None):
        name = ''
        partner_obj = self.pool['res.partner']
        prosecution_type_obj = self.pool['legal.prosecution_type']
        if vals.get('partner_id', False):
            name = partner_obj.browse(
                cr, uid, vals.get('partner_id', False), context=context).name[0]
        if vals.get('prosecution_type_id', False):
            name += '-' + str(prosecution_type_obj.browse(cr, uid,
                                                          vals.get('prosecution_type_id', False), context=context).code)
        name += '-' + \
            self.pool['ir.sequence'].get(cr, uid, 'legal.prosecution')
        vals['folder_name'] = name
        vals['opening_date_folder'] = date.today()
        return super(prosecution, self).create(cr, uid, vals, context=None)

    @api.one
    @api.depends('radication_ids')
    def _get_data(self):
        if self.radication_ids:
            self.current_judged_id = self.radication_ids[
                0].judged_id.id
            self.number_current_file = self.radication_ids[0].num_filed
            if not self.radication_ids[0].num_3_ins:
                if not self.radication_ids[0].num_2_ins:
                    if not self.radication_ids[0].num_1_ins:
                        self.last_complete_instance = ''
                    else:
                        self.last_complete_instance = self.radication_ids[
                            0].num_1_ins
                else:
                    self.last_complete_instance = self.radication_ids[
                        0].num_2_ins
            else:
                self.last_complete_instance = self.radication_ids[0].num_3_ins

        else:
            self.last_complete_instance = ''
            self.current_judged_id = []
            self.number_current_file = ''

    @api.one
    def _audiences_event_count(self):
        self.audiences_event_count = len(
            self.sudo().event_audiences_ids.filtered(
                lambda x: x.state == 'draft'))

    @api.one
    def _expiry_event_count(self):
        self.expiry_event_count = len(
            self.sudo().event_expiry_ids.filtered(
                lambda x: x.state == 'draft'))

    @api.one
    def _calculate_amount(self):
        self.claim_amount = sum([x.total for x in self.claim_ids])

    @api.one
    @api.constrains('member_ids')
    def action_follow(self):
        return self.message_subscribe_users(self.member_ids.ids)

    @api.one
    @api.onchange('prosecution_type_id')
    def auto_complete_auxiliar_field(self):
        self.auxiliary_ids = self.env[
            'legal.auxiliary']
        auxiliary_field_obj = self.env['legal.auxiliary.field']
        if self.prosecution_type_id:
            auxiliary_field_ids = auxiliary_field_obj.search(
                [('prosecution_type_id', '=', self.prosecution_type_id.id)])
            lines = []
            for line in auxiliary_field_ids:
                values = {
                    'field_id': line.id,
{'fraction_non_alphanumeric': 0.11392053348152265, 'fraction_numerical': 0.004723534315087524, 'mean_word_length': 2.0133947258267058, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1161805', 'n_tokens_mistral': 2285, 'n_tokens_neox': 2201, 'n_words': 347}