Hi All,
One of our customers requested to send email notifications to the email defined in the company of the records. In order to achieve it I implemented the following code:
from trytond.pool import Pool, PoolMeta
class EmailTemplate(metaclass=PoolMeta):
__name__ = 'ir.email.template'
@classmethod
def email_models(cls):
return super().email_models() + ['company.company']
@classmethod
def _get_address(cls, record):
pool = Pool()
Company = pool.get('company.company')
address = super()._get_address(record)
if isinstance(record, Company):
address = cls._get_address(record.party)
return address
@classmethod
def _get_language(cls, record):
pool = Pool()
Company = pool.get('company.company')
language = super()._get_language(record)
if isinstance(record, Company):
language = cls._get_language(record.party)
return language
And registered the class on the pool in a custom module.
On the same module I defined an XML record which defines the notification emails and uses the company field of the invoice class.
When activating the module I get the following error:
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/pokoli/projectes/xxxx/tryton/trytond/trytond/convert.py", line 464, in parse_xmlstream
self.sax_parser.parse(source)
File "/usr/lib/python3.12/xml/sax/expatreader.py", line 105, in parse
xmlreader.IncrementalParser.parse(self, source)
File "/usr/lib/python3.12/xml/sax/xmlreader.py", line 124, in parse
self.feed(buffer)
File "/usr/lib/python3.12/xml/sax/expatreader.py", line 211, in feed
self._parser.Parse(data, isFinal)
File "./Modules/pyexpat.c", line 475, in EndElement
File "/usr/lib/python3.12/xml/sax/expatreader.py", line 344, in end_element
self._cont_handler.endElement(name)
File "/home/pokoli/projectes/xxxx/tryton/trytond/trytond/convert.py", line 519, in endElement
self.taghandler = self.taghandler.endElement(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/pokoli/projectes/xxxx/tryton/trytond/trytond/convert.py", line 314, in endElement
self.mh.import_record(
File "/home/pokoli/projectes/xxxx/tryton/trytond/trytond/convert.py", line 695, in import_record
self.create_records(model, [values], [fs_id])
File "/home/pokoli/projectes/xxxx/tryton/trytond/trytond/convert.py", line 701, in create_records
records = Model.create(vlist)
^^^^^^^^^^^^^^^^^^^
File "/home/pokoli/projectes/xxxx/tryton/trytond/trytond/model/modelsql.py", line 262, in wrapper
return func(cls, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/pokoli/projectes/xxxx/tryton/trytond/trytond/model/modelsql.py", line 964, in create
cls._validate(sub_records)
File "/home/pokoli/projectes/xxxx/tryton/trytond/trytond/transaction.py", line 50, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/home/pokoli/projectes/xxxx/tryton/trytond/trytond/model/modelstorage.py", line 1373, in _validate
validate_domain(field)
File "/home/pokoli/projectes/xxxx/tryton/trytond/trytond/model/modelstorage.py", line 1274, in validate_domain
validate_relation_domain(
File "/home/pokoli/projectes/xxxx/tryton/trytond/trytond/model/modelstorage.py", line 1355, in validate_relation_domain
raise DomainValidationError(
trytond.model.modelstorage.DomainValidationError: The value "Company (company)" for field "Recipients" in "New Invoice Notification" of "Email Notification" is not valid according to its domain. -
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/pokoli/projectes/xxxx/tryton/trytond/trytond/tests/test_tryton.py", line 294, in setUpClass
activate_module(modules, lang=cls.language)
File "/home/pokoli/projectes/xxxx/tryton/trytond/trytond/tests/test_tryton.py", line 114, in activate_module
ActivateUpgrade(instance_id).transition_upgrade()
File "/home/pokoli/projectes/xxxx/tryton/trytond/trytond/ir/module.py", line 505, in transition_upgrade
pool.init(update=update, lang=lang)
File "/home/pokoli/projectes/xxxx/tryton/trytond/trytond/pool.py", line 167, in init
restart = not load_modules(
^^^^^^^^^^^^^
File "/home/pokoli/projectes/xxxx/tryton/trytond/trytond/modules/__init__.py", line 394, in load_modules
_load_modules(update)
File "/home/pokoli/projectes/xxxx/tryton/trytond/trytond/modules/__init__.py", line 357, in _load_modules
load_module_graph(graph, pool, update, lang)
File "/home/pokoli/projectes/xxxx/tryton/trytond/trytond/modules/__init__.py", line 208, in load_module_graph
tryton_parser.parse_xmlstream(fp)
File "/home/pokoli/projectes/xxxx/tryton/trytond/trytond/convert.py", line 466, in parse_xmlstream
raise ParsingError("in %s" % self.current_state()) from e
trytond.convert.ParsingError: in record 'custom_module.posted_invoice_notification'
What I’m doing wrong? How can I extend the recipients of the notification email to include also the company?
P.S: If you thin interesting to add the company as a recipient of the emails, just let me know and I will be happy to contribute the needed code to add it as part of standard modules.