summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models')
-rwxr-xr-xindoteknik_custom/models/res_users.py19
-rw-r--r--indoteknik_custom/models/user_company_request.py13
2 files changed, 29 insertions, 3 deletions
diff --git a/indoteknik_custom/models/res_users.py b/indoteknik_custom/models/res_users.py
index 33f64ce3..cedf19bd 100755
--- a/indoteknik_custom/models/res_users.py
+++ b/indoteknik_custom/models/res_users.py
@@ -11,6 +11,8 @@ class ResUsers(models.Model):
activation_token = fields.Char(string="Activation Token")
otp_code = fields.Char(string='OTP Code')
otp_create_date = fields.Datetime(string='OTP Create Date')
+ user_company_name = fields.Char(string="User Company Name")
+
def _generate_otp(self):
for user in self:
@@ -28,7 +30,22 @@ class ResUsers(models.Model):
user._generate_otp()
user._generate_activation_token()
template.send_mail(user.id, force_send=True)
-
+
+ def send_company_request_mail(self):
+ template = self.env.ref('indoteknik_custom.mail_template_res_user_company_request')
+ for user in self:
+ template.send_mail(user.id, force_send=True)
+
+ def send_company_request_approve_mail(self):
+ template = self.env.ref('indoteknik_custom.mail_template_res_user_company_request_approve')
+ for user in self:
+ template.send_mail(user.id, force_send=True)
+
+ def send_company_request_reject_mail(self):
+ template = self.env.ref('indoteknik_custom.mail_template_res_user_company_request_reject')
+ for user in self:
+ template.send_mail(user.id, force_send=True)
+
def get_activation_token_url(self):
base_url = self.env['ir.config_parameter'].get_param('site.base.url')
return f'{base_url}/register?activation=token&token={self.activation_token}'
diff --git a/indoteknik_custom/models/user_company_request.py b/indoteknik_custom/models/user_company_request.py
index 40ac4446..8122c6a0 100644
--- a/indoteknik_custom/models/user_company_request.py
+++ b/indoteknik_custom/models/user_company_request.py
@@ -1,6 +1,6 @@
from odoo import models, fields
from odoo.exceptions import UserError
-
+from odoo.http import request
class UserCompanyRequest(models.Model):
_name = 'user.company.request'
@@ -15,6 +15,8 @@ class UserCompanyRequest(models.Model):
], string='Approval')
def write(self, vals):
+ user = self.get_user_by_email(self.user_id.email)
+ user.user_company_name = self.user_input
is_approve = vals.get('is_approve')
if self.is_approve and is_approve:
raise UserError('Tidak dapat mengubah approval yang sudah diisi')
@@ -34,11 +36,18 @@ class UserCompanyRequest(models.Model):
self.user_id.property_account_payable_id = self.user_company_id.property_account_payable_id
self.user_company_id.active = True
# tambahkan send email kalau bisnis berhsil di buat
+ user.send_company_request_approve_mail()
else:
new_company = self.env['res.partner'].create({
'name': self.user_input
})
self.user_id.parent_id = new_company.id
# tambahkan send email kalau bisnis ditolak di buat
+ user.send_company_request_reject_mail()
return super(UserCompanyRequest, self).write(vals)
- \ No newline at end of file
+
+ def get_user_by_email(self, email):
+ return request.env['res.users'].search([
+ ('login', '=', email),
+ ('active', 'in', [True, False])
+ ]) \ No newline at end of file