from odoo import models, fields, api
|
|
from odoo.exceptions import UserError, ValidationError
|
|
from psycopg2 import sql, DatabaseError
|
|
|
|
from werkzeug import utils
|
|
|
|
class opendons_operation(models.Model):
|
|
_name = 'opendons.operation'
|
|
_description = 'opération marketing : mailing, emailing evenements'
|
|
_inherit = ['mail.thread']
|
|
|
|
code=fields.Char(string='Code',required=True, translate=True,track_visibility='always')
|
|
name=fields.Char(string='Name',required=True, translate=True,track_visibility='always')
|
|
begin_date=fields.Date(string='Date begin',required=True, translate=True,track_visibility='always')
|
|
end_date=fields.Date(string='Date end',required=True, translate=True,track_visibility='always')
|
|
chanel=fields.Selection([
|
|
('mail', 'Mailing'),
|
|
('email', 'E-mailing'),
|
|
('event', 'Event')],
|
|
string='Chanel',required=True, translate=True,track_visibility='always')
|
|
|
|
user_id = fields.Many2one('res.users', string='Author', default=lambda self: self.env.uid)
|
|
cost = fields.Monetary(
|
|
string='Cost',
|
|
currency_field='currency_id')
|
|
|
|
@api.model
|
|
def _default_currency(self):
|
|
company = self.env['res.company']._company_default_get(
|
|
'opendons.operation')
|
|
return company.currency_id
|
|
|
|
currency_id = fields.Many2one(
|
|
'res.currency',
|
|
string='Currency',
|
|
required=True,
|
|
track_visibility='onchange',
|
|
ondelete='restrict',
|
|
default=_default_currency
|
|
)
|
|
_sql_constraints = [
|
|
('name_uniq', 'unique (name)', "Name already exists !"),
|
|
('code_uniq', 'unique (code)', "Code already exists !"),
|
|
]
|
|
|
|
number_of_sending = fields.Integer(
|
|
compute='_compute_number_of_sending',
|
|
string="# of sending",
|
|
readonly=True
|
|
)
|
|
segment_ids = fields.One2many(
|
|
'opendons.segment',
|
|
'operation_id',
|
|
string='Segments',
|
|
required=True,
|
|
track_visibility='onchange')
|
|
|
|
|
|
class opendons_segment(models.Model):
|
|
_name = 'opendons.segment'
|
|
_description = 'operation marketing segment : a segment is a part of contacts selected for an operation '
|
|
_inherit = ['mail.thread']
|
|
code=fields.Char(string='Code',required=True, translate=True,track_visibility='always')
|
|
name=fields.Char(string='Name',required=True, translate=True,track_visibility='always')
|
|
cost = fields.Monetary(
|
|
string='Cost',
|
|
currency_field='currency_id')
|
|
|
|
@api.model
|
|
def _default_currency(self):
|
|
company = self.env['res.company']._company_default_get(
|
|
'opendons.segment')
|
|
return company.currency_id
|
|
|
|
currency_id = fields.Many2one(
|
|
'res.currency',
|
|
string='Currency',
|
|
required=True,
|
|
track_visibility='onchange',
|
|
ondelete='restrict',
|
|
default=_default_currency
|
|
)
|
|
|
|
operation_id = fields.Many2one(
|
|
'opendons.operation','Operation',
|
|
ondelete='cascade',
|
|
track_visibility='always')
|
|
|
|
|