diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2023-11-21 13:43:17 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2023-11-21 13:43:17 +0700 |
| commit | 9bee745fe999ae7feba61d23002bd88139048d80 (patch) | |
| tree | 9128bfb18f2d3c8dadfbe301ff521395df81de9b /indoteknik_custom/models | |
| parent | a155ccce0c0c59f1e41c11012cf81ea16812642d (diff) | |
| parent | 866a2f8dfc5b6628a5ddc5ed88de2a0586ba4761 (diff) | |
Merge branch 'production' of bitbucket.org:altafixco/indoteknik-addons into production
Diffstat (limited to 'indoteknik_custom/models')
| -rwxr-xr-x | indoteknik_custom/models/res_users.py | 33 | ||||
| -rw-r--r-- | indoteknik_custom/models/voucher.py | 3 |
2 files changed, 36 insertions, 0 deletions
diff --git a/indoteknik_custom/models/res_users.py b/indoteknik_custom/models/res_users.py index 7f94771f..09321fc6 100755 --- a/indoteknik_custom/models/res_users.py +++ b/indoteknik_custom/models/res_users.py @@ -1,4 +1,7 @@ from odoo import models, fields +from datetime import datetime +from pytz import UTC +import random, string class ResUsers(models.Model): @@ -6,3 +9,33 @@ class ResUsers(models.Model): reset_password_token = fields.Char(string="Reset Password Token") activation_token = fields.Char(string="Activation Token") + otp_code = fields.Char(string='OTP Code') + otp_create_date = fields.Datetime(string='OTP Create Date') + + def _generate_otp(self): + for user in self: + user.otp_code = '{:04d}'.format(random.randint(0, 9999)) + user.otp_create_date = fields.Datetime.now() + + def _generate_activation_token(self): + for user in self: + token_source = string.ascii_letters + string.digits + user.activation_token = ''.join(random.choice(token_source) for i in range(21)) + + def send_activation_mail(self): + template = self.env.ref('indoteknik_custom.mail_template_res_user_activation_request') + for user in self: + user._generate_otp() + user._generate_activation_token() + 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}' + + def get_voucher_code(self, type): + if type == 'activation': + vouchers = self.env['voucher'].get_active_voucher([('show_on_email', '=', 'user_activation')]) + if not vouchers: return None + return ', '.join(x.code for x in vouchers) + return None diff --git a/indoteknik_custom/models/voucher.py b/indoteknik_custom/models/voucher.py index 2eedc861..588e9ac5 100644 --- a/indoteknik_custom/models/voucher.py +++ b/indoteknik_custom/models/voucher.py @@ -55,6 +55,9 @@ class Voucher(models.Model): ('brand', "Selected product brand"), ]) count_order = fields.Integer(string='Count Order', compute='_compute_count_order') + show_on_email = fields.Selection([ + ('user_activation', 'User Activation') + ], 'Show on Email') @api.constrains('description') def _check_description_length(self): |
