edgar 8 gadi atpakaļ
revīzija
30bed317a6

+ 3 - 0
__init__.py

@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+
+import smtp_per_user 

+ 38 - 0
__openerp__.py

@@ -0,0 +1,38 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#    
+#    Odoo, Open Source Management Solution
+#
+#    Author: Andrius Laukavičius. Copyright: JSC Boolit
+#
+#    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 <http://www.gnu.org/licenses/>.     
+#
+##############################################################################
+
+{
+    'name': "SMTP Per User",
+    'version': '0.33',
+    'summary': 'Send letters from Odoo using your own mail',
+    'category': 'Mail',
+    'description': """Can configure different mail servers per user""",
+    'author': 'OERP',
+    'license': 'AGPL-3',
+    'website': "www.oerp.eu",
+    "depends" : ['mail'],
+    'data': [
+        'smtp_per_user_view.xml',
+        'security/ir.model.access.csv',
+    ],
+    "installable": True
+}

+ 2 - 0
security/ir.model.access.csv

@@ -0,0 +1,2 @@
+id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
+access_ir_mail_server_read,ir.mail_server readonly,model_ir_mail_server,base.group_user,1,0,0,0

+ 2 - 0
security/ir.model.access.csv~

@@ -0,0 +1,2 @@
+id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
+access_crm_stage_activity,crm.stage.activity user,model_crm_stage_activity,base.group_user,1,0,0,0

+ 58 - 0
smtp_per_user.py

@@ -0,0 +1,58 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#    
+#    Odoo, Open Source Management Solution
+#
+#    Author: Andrius Laukavičius. Copyright: JSC Boolit
+#
+#    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 <http://www.gnu.org/licenses/>.     
+#
+##############################################################################
+from openerp import models, fields, api
+from email.utils import parseaddr, formataddr
+
+class ir_mail_server(models.Model):
+    _inherit = "ir.mail_server"
+
+    user_id = fields.Many2one('res.users', string="Owner")
+    email_name = fields.Char('Email Name', help="Overrides default email name")
+    force_use = fields.Boolean('Force Use', help="If checked and this server is chosen to send mail message, It will ignore owners mail server")
+
+    @api.model
+    def replace_email_name(self, old_email):
+        """
+        Replaces email name if new one is provided
+        """
+        if self.email_name:
+            old_name, email = parseaddr(old_email)
+            return formataddr((self.email_name, email))
+        else:
+            return old_email    
+
+class mail_mail(models.Model):
+    _inherit = 'mail.mail'
+
+    @api.multi
+    def send(self, auto_commit=False, raise_exception=False):
+        ir_mail_server_obj = self.env['ir.mail_server']
+        res_user_obj = self.env['res.users']
+        for email in self:
+            if not email.mail_server_id.force_use:
+                user = res_user_obj.search([('partner_id', '=', email.author_id.id)], limit=1)
+                if user:
+                    mail_server = ir_mail_server_obj.search([('user_id', '=', user.id)], limit=1)
+                    if mail_server:
+                        email.mail_server_id = mail_server.id
+            email.email_from = email.mail_server_id.replace_email_name(email.email_from)
+        return super(mail_mail, self).send(auto_commit=False, raise_exception=False)

+ 16 - 0
smtp_per_user_view.xml

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        <record id="ir_mail_server_form" model="ir.ui.view">
+            <field name="model">ir.mail_server</field>
+            <field name="inherit_id" ref="base.ir_mail_server_form"/>
+            <field name="arch" type="xml">
+                <field name="smtp_user" position="before">
+                    <field name="force_use"/>
+                    <field name="email_name"/>
+                    <field name="user_id"/>
+                </field>
+            </field>
+        </record>
+    </data>
+</openerp>

+ 16 - 0
static/description/index.html

@@ -0,0 +1,16 @@
+<section class="oe_container">
+    <div class="oe_row oe_spaced">
+        <div class="oe_span12">
+            <h2 class="oe_slogan">SMTP Per User</h2>
+            <h3 class="oe_slogan">Send letters from Odoo using your own mail</h3>
+        </div>
+        <div class="oe_span6">
+            <p class="oe_mt32">
+Can configure different mail servers per user. Can specify email name for every server. For example - Email Name: <i>'My Custom Name'</i> and sending mail is <i>example@example.com</i>. When sent, it will show like this: <i>"My Custom Name example@example.com"</i>. Specific mail server can be set to ignore owner mail server and use forced server which was chosen by priority or by other means. This is forked and improved version of <a href="https://github.com/bamps/smtp-per-user">smpt-per-user</a> for Odoo 8.0.
+            </p>
+            <div class="oe_centeralign oe_websiteonly">
+                <a href="http://www.oerp.eu/#trial" class="oe_button oe_big oe_tacky">Start your <span class="oe_emph">free</span> trial</a>
+            </div>
+        </div>
+    </div>
+</section>