Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet

Hello, everybody!

I am new at Odoo, and I am trying to make my custom module talk to the contacts' module to grab useful information for a mailing list. Below you will find the code of my solution.

Question: Is there a better way of getting the "name" field from the contact list, and together with it, automatically, the "email" field? I feel that my solution is hard to maintain and not very good for the job. Please let me know if there is a better way to do this, and thank you in advance!


models.py
​from odoo import models, fields, api

class MailingList(models.Model):
_name = 'mailing_list.mailing_list'
_description = 'Exercise #1 of Task #12'

name = fields.Many2one('res.partner', string='Name')
email = fields.Char(string='Email')

@api.model
def create(self, vals):
if vals.get('name'):
partner = self.env['res.partner'].browse(vals['name'])
vals['email'] = partner.email

result = super(MailingList, self).create(vals)
return result

def write(self, vals):
print("\n\tYou are on the method write override")
print("\tEnd of method write override\n")

if vals.get('name'):
partner = self.env['res.partner'].browse(vals['name'])
vals['email'] = partner.email

result = super(MailingList, self).write(vals)
return result



Avatar
Verwerfen
Beste Antwort

Hi,

Try this to get email.

from odoo import models, fields, api


class MailingList(models.Model):

    _name = 'mailing_list.mailing_list'

    _description = 'Exercise #1 of Task #12'


    name = fields.Many2one('res.partner', string='Name')

    email = fields.Char(string='Email', related='name.email')


Hope it helps

Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
2
März 23
3788
2
Okt. 19
4190
2
Okt. 19
3628
0
Sept. 17
2987
1
Juli 24
3242