Add fall-back and use mechanism usage

issue7624
review70311002
This commit is contained in:
Cédric Krier committed 2018-08-27 22:40:40 +02:00
1 parent e2c8c47e67
commit 87dd9eb287
6 files changed
+68 -5

No files matched your search

+2
View File
@@ -1,3 +1,5 @@
* Add contact mechanism usage
* Add fall-back user
* Remove support for Python 2.7
Version 4.8.0 - 2018-04-23
+1
View File
@@ -9,6 +9,7 @@ __all__ = ['register']
def register():
Pool.register(
account.Configuration,
account.DunningLevel,
account.Dunning,
account.DunningEmailLog,
+45 -4
View File
@@ -12,7 +12,19 @@ from trytond.sendmail import sendmail_transactional, SMTPDataManager
from trytond.transaction import Transaction
from trytond.wizard import StateTransition
__all__ = ['DunningLevel', 'ProcessDunning', 'Dunning', 'DunningEmailLog']
__all__ = ['Configuration', 'DunningLevel', 'ProcessDunning', 'Dunning',
'DunningEmailLog']
class Configuration(metaclass=PoolMeta):
__name__ = 'account.configuration'
dunning_email_fallback = fields.Many2One(
'res.user', "Fall-back User",
domain=[
('email', '!=', None),
],
help="User notified when no e-mail is found to send the dunning")
class DunningLevel(metaclass=PoolMeta):
@@ -36,6 +48,13 @@ class DunningLevel(metaclass=PoolMeta):
},
depends=['send_email'],
help="Leave empty for the value defined in the configuration file.")
email_contact_mechanism = fields.Selection(
'get_contact_mechanisms', "Contact Mechanism",
states={
'invisible': ~Eval('send_email'),
},
depends=['send_email'],
help="Define which e-mail to use from the party's contact mechanisms")
@classmethod
def default_email_template(cls):
@@ -46,6 +65,20 @@ class DunningLevel(metaclass=PoolMeta):
except KeyError:
return
@classmethod
def get_contact_mechanisms(cls):
pool = Pool()
ContactMechanism = pool.get('party.contact_mechanism')
return ContactMechanism.usages()
@classmethod
def view_attributes(cls):
return super().view_attributes() + [
('//separator[@id="email"]', 'states', {
'invisible': ~Eval('send_email'),
}),
]
class ProcessDunning(metaclass=PoolMeta):
__name__ = 'account.dunning.process'
@@ -81,13 +114,21 @@ class Dunning(metaclass=PoolMeta):
def send_email(self, datamanager=None):
pool = Pool()
Configuration = pool.get('ir.configuration')
AccountConfig = pool.get('account.configuration')
Lang = pool.get('ir.lang')
account_config = AccountConfig(1)
from_ = self.level.email_from or config.get('email', 'from')
to = []
if self.party.email:
name = str(Header(self.party.rec_name))
to.append(formataddr((name, self.party.email)))
contact = self.party.contact_mechanism_get(
'email', usage=self.level.email_contact_mechanism)
if contact and contact.email:
name = str(Header(contact.name or self.party.rec_name))
to.append(formataddr((name, contact.email)))
elif account_config.dunning_email_fallback:
user = account_config.dunning_email_fallback
to.append(formataddr((self.party.rec_name, user.email)))
cc = []
bcc = []
languages = set()
+6
View File
@@ -3,6 +3,12 @@
this repository contains the full copyright notices and license terms. -->
<tryton>
<data>
<record model="ir.ui.view" id="configuration_view_form">
<field name="model">account.configuration</field>
<field name="inherit" ref="account.configuration_view_form"/>
<field name="name">configuration_form</field>
</record>
<record model="ir.ui.view" id="dunning_level_view_form">
<field name="model">account.dunning.level</field>
<field name="inherit"
+9
View File
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="/form/field[@name='default_dunning_procedure']" position="after">
<label name="dunning_email_fallback"/>
<field name="dunning_email_fallback"/>
</xpath>
</data>
+5 -1
View File
@@ -5,10 +5,14 @@ this repository contains the full copyright notices and license terms. -->
<xpath expr="/form/field[@name='print_on_letter']" position="after">
<label name="send_email"/>
<field name="send_email"/>
<newline/>
<separator string="E-mail" id="email" colspan="4"/>
<label name="email_template"/>
<field name="email_template"/>
<newline/>
<label name="email_from"/>
<field name="email_from"/>
<label name="email_contact_mechanism"/>
<field name="email_contact_mechanism"/>
<newline/>
</xpath>
</data>