<commit_before># -*- coding: utf-8 -*-
from openerp import models,fields,api,tools,SUPERUSER_ID
from openerp.tools.translate import _
import time
from datetime import datetime
from dateutil.relativedelta import relativedelta
from openerp.osv import osv
import xmlrpclib
from is_outillage import date_prochain_controle


class is_piece_montabilite(models.Model):
    _name='is.piece.montabilite'
    _rec_name = 'code_pg'
    _sql_constraints = [('code_pg_uniq','UNIQUE(code_pg)', u'Ce code existe déjà')]
    
    @api.depends('moule_ids')
    def compute_client_id(self):
        for rec in self:
            client_id = False
            for moule in rec.moule_ids:
                if moule.client_id:
                    client_id = moule.client_id.id
                    break;
            rec.client_id = client_id
    
    code_pg                = fields.Char("Code PG", required=True)
    designation            = fields.Char("Désignation")
    fabriquant             = fields.Selection([('client','Client'),
                                   ('plastigray','Plastigray'),
                                   ('autre','Autre')
                                   ], string="Fabricant")
    fabricant_client_id    = fields.Many2one('res.partner', string='Fabricant (Client)', domain=[('supplier','=',True),('is_company','=',True)])
    fabriquant_mold_id     = fields.Many2one('is.mold', string='Fabricant (Moule)')
    fabriquant_autre       = fields.Char("Fabricant (Autre)")
    date_reception         = fields.Date("Date de réception")
    moule_ids              = fields.Many2many('is.mold','is_piece_montabilite_id', 'is_mold_id_piece_mont', string='Moules affectés')
    client_id              = fields.Many2one('res.partner', string='Client', compute="compute_client_id", store=True)
    site_id                = fields.Many2one('is.database', string='Site')
    lieu_stockage          = fields.Char("Lieu de stockage")
    periodicite            = fields.Integer("Périodicité ( en mois )")
    type_controle          = fields.Many2one('is.type.controle.gabarit', string='Type de contrôle')
    date_prochain_controle = fields.Date("Date prochain contrôle", compute='_compute_date_prochain_controle', readonly=True, store=True)
    is_database_origine_id = fields.Integer("Id d'origine", readonly=True)
    active                 = fields.Boolean('Active', default=True)
    controle_ids           = fields.One2many('is.historique.controle', 'piece_id', string='Historique des contrôles')


    @api.multi
    @api.depends('controle_ids','periodicite')
    def _compute_date_prochain_controle(self):
        for rec in self:
            date_prochain_controle(rec)
#            date_prochain_controle=False
#            if rec.controle_ids:
#                for row in rec.controle_ids:
#                    if row.operation_controle_id.code!='arret' and row.operation_controle_id.code!='maintenance':
#                        date_controle=row.date_controle
#                        if date_controle:
#                            date_controle = datetime.strptime(date_controle, "%Y-%m-%d")
#                            periodicite=0
#                            if rec.periodicite:
#                                try:
#                                    periodicite = int(rec.periodicite)
#                                except ValueError:
#                                    continue
#                            date_prochain_controle = date_controle + relativedelta(months=periodicite)
#                            date_prochain_controle = date_prochain_controle.strftime('%Y-%m-%d')
#                            break
#            rec.date_prochain_controle = date_prochain_controle<commit_msg>[1178] Liste de choix pour la fréquence<commit_after># -*- coding: utf-8 -*-
from openerp import models,fields,api,tools,SUPERUSER_ID
from openerp.tools.translate import _
import time
from datetime import datetime
from dateutil.relativedelta import relativedelta
from openerp.osv import osv
import xmlrpclib
from is_outillage import date_prochain_controle


class is_piece_montabilite(models.Model):
    _name='is.piece.montabilite'
    _rec_name = 'code_pg'
    _sql_constraints = [('code_pg_uniq','UNIQUE(code_pg)', u'Ce code existe déjà')]
    
    @api.depends('moule_ids')
    def compute_client_id(self):
        for rec in self:
            client_id = False
            for moule in rec.moule_ids:
                if moule.client_id:
                    client_id = moule.client_id.id
                    break;
            rec.client_id = client_id
    
    code_pg                = fields.Char("Code PG", required=True)
    designation            = fields.Char("Désignation")
    fabriquant             = fields.Selection([('client','Client'),
                                   ('plastigray','Plastigray'),
                                   ('autre','Autre')
                                   ], string="Fabricant")
    fabricant_client_id    = fields.Many2one('res.partner', string='Fabricant (Client)', domain=[('supplier','=',True),('is_company','=',True)])
    fabriquant_mold_id     = fields.Many2one('is.mold', string='Fabricant (Moule)')
    fabriquant_autre       = fields.Char("Fabricant (Autre)")
    date_reception         = fields.Date("Date de réception")
    moule_ids              = fields.Many2many('is.mold','is_piece_montabilite_id', 'is_mold_id_piece_mont', string='Moules affectés')
    client_id              = fields.Many2one('res.partner', string='Client', compute="compute_client_id", store=True)
    site_id                = fields.Many2one('is.database', string='Site')
    lieu_stockage          = fields.Char("Lieu de stockage")

    #periodicite            = fields.Integer("Périodicité ( en mois )")
    periodicite            = fields.Selection([
                                    ('24','24 mois (standard)'),
                                    ('48','48 mois ( qté annuelle < 10000p)'),
                                ], string="Périodicité ( en mois )")

    type_controle          = fields.Many2one('is.type.controle.gabarit', string='Type de contrôle')
    date_prochain_controle = fields.Date("Date prochain contrôle", compute='_compute_date_prochain_controle', readonly=True, store=True)
    is_database_origine_id = fields.Integer("Id d'origine", readonly=True)
    active                 = fields.Boolean('Active', default=True)
    controle_ids           = fields.One2many('is.historique.controle', 'piece_id', string='Historique des contrôles')


    @api.multi
    @api.depends('controle_ids','periodicite')
    def _compute_date_prochain_controle(self):
        for rec in self:
            date_prochain_controle(rec)
{'fraction_non_alphanumeric': 0.11038088125466766, 'fraction_numerical': 0.005078416728902166, 'mean_word_length': 2.266341463414634, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6402105', 'n_tokens_mistral': 2029, 'n_tokens_neox': 1973, 'n_words': 338}