# -*- coding: utf-8 -*-
|
|
|
|
from odoo import models, fields, api
|
|
from odoo.exceptions import UserError, ValidationError
|
|
from psycopg2 import sql, DatabaseError
|
|
|
|
from werkzeug import utils
|
|
|
|
class opendons_returnmail(models.Model):
|
|
_name = 'opendons_returnmail'
|
|
_description = 'manage return mail'
|
|
|
|
return_type=fields.Selection(string='Type',
|
|
selection=[
|
|
('npai', 'NPAI'),
|
|
('decedee','Décédée'),
|
|
('refusee','Refusée')
|
|
],default='npai')
|
|
|
|
return_count=fields.Integer(string='returns count', readonly=True)
|
|
return_input=fields.Char('Input field')
|
|
|
|
npai_lines = fields.One2many(
|
|
'opendons_returnmail.npai',
|
|
'returnmail_id',
|
|
string='NPAI',
|
|
track_visibility='onchange')
|
|
|
|
company_id = fields.Many2one(
|
|
"res.company",
|
|
string="Company",
|
|
required=True,
|
|
default=lambda self: self.env.company
|
|
|
|
)
|
|
def action_ajouter_npai(self):
|
|
|
|
data=self.return_input.split(';')
|
|
vals={}
|
|
vals['partner_id']=data[0]
|
|
vals['operation_id']=data[1]
|
|
vals['segment_id']=data[2]
|
|
vals['returnmail_id']=self.id
|
|
|
|
p=self.env['res.partner'].search_count([('id','=',int(vals['partner_id']))])
|
|
if p==0 : raise UserError("ce contact n'existe pas")
|
|
|
|
op=self.env['opendons.operation'].search_count([('id','=',int(vals['operation_id']))])
|
|
if op==0 : raise UserError("cette operation n'existe pas")
|
|
|
|
seg=self.env['opendons.segment'].search_count([('id','=',int(vals['segment_id']))])
|
|
if seg==0 : raise UserError("ce segment n'existe pas")
|
|
|
|
|
|
res=self.env['opendons_returnmail.npai'].create(vals)
|
|
self.env.cr.commit()
|
|
|
|
class opendons_returnmailNpai(models.Model):
|
|
_name = 'opendons_returnmail.npai'
|
|
_description = 'gestion des retours NPAI'
|
|
|
|
returnmail_id = fields.Many2one(
|
|
'opendons_returnmail',
|
|
string='return mail',
|
|
ondelete='set null'
|
|
)
|
|
partner_id=fields.Many2one(
|
|
'res.partner',
|
|
string='Partner',
|
|
required=True,
|
|
index=True,
|
|
track_visibility='onchange',
|
|
ondelete='restrict'
|
|
)
|
|
operation_id=fields.Many2one(
|
|
'opendons.operation',
|
|
string='Operation',
|
|
required=True,
|
|
index=True,
|
|
track_visibility='onchange',
|
|
ondelete='restrict'
|
|
)
|
|
segment_id=fields.Many2one(
|
|
'opendons.segment',
|
|
string='Segment',
|
|
required=True,
|
|
index=True,
|
|
track_visibility='onchange',
|
|
ondelete='restrict'
|
|
)
|
|
|