From da9b44114c702ed0e7ef8e06f6f6f792fdbfd554 Mon Sep 17 00:00:00 2001 From: youssef Date: Tue, 13 Nov 2018 02:18:39 +0100 Subject: [PATCH] Create golem.mail.recipient pivot model to facilitate adding emails to list --- golem_mail/wizard/golem_mail_recipient.py | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 golem_mail/wizard/golem_mail_recipient.py diff --git a/golem_mail/wizard/golem_mail_recipient.py b/golem_mail/wizard/golem_mail_recipient.py new file mode 100644 index 0000000..d505b94 --- /dev/null +++ b/golem_mail/wizard/golem_mail_recipient.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +""" GOLEM Mail Recipient Management """ + +import logging +from odoo import models, fields, api, _ +_LOGGER = logging.getLogger(__name__) + +class GolemMailRecipient(models.TransientModel): + """ GOLEM Mail Recipient """ + _name = 'golem.mail.recipient' + + partner_id = fields.Many2one('res.partner') + email = fields.Char() + firstname = fields.Char() + lastname = fields.Char() + phone = fields.Char() + opt_out = fields.Boolean() + presend_wizard_id = fields.Many2one('golem.mail.presend.wizard') + + @api.multi + @api.constrains('partner_id') + def fill_related_fields(self): + """ fill related fields from partner_id """ + for recipient in self: + if recipient.partner_id: + recipient.email = recipient.partner_id.email + recipient.firstname = recipient.partner_id.firstname + recipient.lastname = recipient.partner_id.lastname + recipient.phone = recipient.partner_id.phone + recipient.opt_out = recipient.partner_id.opt_out