summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-10-02 11:48:15 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-10-02 11:48:15 +0700
commit795af0a07c28d5d407070734ef94b4838d05f793 (patch)
tree9ac058fa105777a946da851dd79aba5be5ac4f13
parent705f51eed8a817fe6ea3ef514402786d25f7c356 (diff)
<iman> update switch account
-rw-r--r--indoteknik_api/controllers/api_v1/user.py226
-rw-r--r--indoteknik_api/models/res_users.py1
-rwxr-xr-xindoteknik_custom/models/res_users.py5
-rw-r--r--indoteknik_custom/views/res_users.xml61
4 files changed, 201 insertions, 92 deletions
diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py
index bcced998..26c0b4fe 100644
--- a/indoteknik_api/controllers/api_v1/user.py
+++ b/indoteknik_api/controllers/api_v1/user.py
@@ -448,97 +448,20 @@ class User(controller.Controller):
('name', 'ilike', business_name)
]
if parent_id:
- parameter = (('id', '=', parent_id))
- match_company = request.env['res.partner'].search(parameter, limit=1)
- match_ratio = 0
- if match_company:
- match_ratio = SequenceMatcher(None, match_company.name, business_name).ratio()
- if match_ratio > 0.8:
- if user.parent_id :
- new_data = {
- 'email': email_partner,
- 'customer_type': 'pkp' if is_pkp == 'true' else 'nonpkp',
- 'name': business_name if business_name else business_name,
- 'company_type_id': company_type_id if company_type_id else False,
- 'industry_id': industry_id,
- 'npwp': npwp if is_pkp == 'true' else (npwp if npwp else '00.000.000.0-000.000'),
- 'sppkp': sppkp if is_pkp == 'true' else (sppkp if sppkp else '-'),
- 'nama_wajib_pajak': nama_wajib_pajak,
- 'alamat_lengkap_text': alamat_wajib_pajak,
- 'street': alamat_bisnis,
- }
- match_company.write(new_data)
-
- if npwp_document != ' ':
- npwp_mimetype, _ = mimetypes.guess_type(npwp_filename)
- npwp_mimetype = npwp_mimetype or 'application/octet-stream'
- pdf_data = base64.b64decode(npwp_document)
- npwp_attachment = request.env['ir.attachment'].create({
- 'name': 'NPWP Document',
- 'type': 'binary',
- 'datas': base64.b64encode(pdf_data),
- 'res_model': 'res.partner',
- 'res_id': match_company.id,
- 'mimetype': npwp_mimetype
- })
- match_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id])
-
- if sppkp_document != ' ':
- sppkp_mimetype, _ = mimetypes.guess_type(sppkp_filename)
- sppkp_mimetype = sppkp_mimetype or 'application/octet-stream'
- pdf_data = base64.b64decode(sppkp_document)
- sppkp_attachment = request.env['ir.attachment'].create({
- 'name': 'SPPKP Document',
- 'type': 'binary',
- 'datas': base64.b64encode(pdf_data),
- 'res_model': 'res.partner',
- 'res_id': match_company.id,
- 'mimetype': sppkp_mimetype
- })
- match_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id])
- else:
- # Create a user company request
- request.env['user.company.request'].create({
- 'user_id': user.id,
- 'user_company_id': match_company.id,
- 'user_input': business_name
- })
- else:
- if not nama_wajib_pajak and is_pkp == 'false':
- nama_wajib_pajak = business_name
-
- if not alamat_wajib_pajak and is_pkp == 'false':
- alamat_wajib_pajak = alamat_bisnis
-
- new_company_data = {
+ match_company = request.env['res.partner'].search([('id', '=', parent_id)], limit=1)
+ new_data = {
+ 'email': email_partner,
+ 'customer_type': 'pkp' if is_pkp == 'true' else 'nonpkp',
'name': business_name if business_name else business_name,
'company_type_id': company_type_id if company_type_id else False,
'industry_id': industry_id,
- 'customer_type': 'pkp' if is_pkp == 'true' else 'nonpkp',
'npwp': npwp if is_pkp == 'true' else (npwp if npwp else '00.000.000.0-000.000'),
'sppkp': sppkp if is_pkp == 'true' else (sppkp if sppkp else '-'),
'nama_wajib_pajak': nama_wajib_pajak,
'alamat_lengkap_text': alamat_wajib_pajak,
- 'email': email_partner,
'street': alamat_bisnis,
- 'company_type': 'company',
- 'user_id': 3222,
- 'property_account_receivable_id': 395,
- 'property_account_payable_id': 438,
- 'active': False,
}
- new_company = request.env['res.partner'].create(new_company_data)
- request.env['user.company.request'].create({
- 'user_id': user.id,
- 'user_company_id': new_company.id,
- 'user_input': business_name
- })
- # user.partner_id.parent_id = new_company.id
- # user.partner_id.customer_type = new_company.customer_type
- # user.partner_id.npwp = new_company.npwp
- # user.partner_id.sppkp = new_company.sppkp
- # user.partner_id.nama_wajib_pajak = new_company.nama_wajib_pajak
- # user.partner_id.alamat_lengkap_text = new_company.alamat_lengkap_text
+ match_company.write(new_data)
if npwp_document != ' ':
npwp_mimetype, _ = mimetypes.guess_type(npwp_filename)
@@ -549,13 +472,10 @@ class User(controller.Controller):
'type': 'binary',
'datas': base64.b64encode(pdf_data),
'res_model': 'res.partner',
- 'res_id': new_company.id,
+ 'res_id': match_company.id,
'mimetype': npwp_mimetype
})
- if user.parent_id:
- match_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id])
- else:
- new_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id])
+ match_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id])
if sppkp_document != ' ':
sppkp_mimetype, _ = mimetypes.guess_type(sppkp_filename)
@@ -566,17 +486,139 @@ class User(controller.Controller):
'type': 'binary',
'datas': base64.b64encode(pdf_data),
'res_model': 'res.partner',
- 'res_id': new_company.id,
+ 'res_id': match_company.id,
'mimetype': sppkp_mimetype
})
- if user.parent_id:
- match_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id])
+ match_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id])
+ else:
+ match_company = request.env['res.partner'].search(parameter, limit=1)
+ match_ratio = 0
+ if match_company:
+ match_ratio = SequenceMatcher(None, match_company.name, business_name).ratio()
+ if match_ratio > 0.8:
+ if user.parent_id :
+ new_data = {
+ 'email': email_partner,
+ 'customer_type': 'pkp' if is_pkp == 'true' else 'nonpkp',
+ 'name': business_name if business_name else business_name,
+ 'company_type_id': company_type_id if company_type_id else False,
+ 'industry_id': industry_id,
+ 'npwp': npwp if is_pkp == 'true' else (npwp if npwp else '00.000.000.0-000.000'),
+ 'sppkp': sppkp if is_pkp == 'true' else (sppkp if sppkp else '-'),
+ 'nama_wajib_pajak': nama_wajib_pajak,
+ 'alamat_lengkap_text': alamat_wajib_pajak,
+ 'street': alamat_bisnis,
+ }
+ match_company.write(new_data)
+
+ if npwp_document != ' ':
+ npwp_mimetype, _ = mimetypes.guess_type(npwp_filename)
+ npwp_mimetype = npwp_mimetype or 'application/octet-stream'
+ pdf_data = base64.b64decode(npwp_document)
+ npwp_attachment = request.env['ir.attachment'].create({
+ 'name': 'NPWP Document',
+ 'type': 'binary',
+ 'datas': base64.b64encode(pdf_data),
+ 'res_model': 'res.partner',
+ 'res_id': match_company.id,
+ 'mimetype': npwp_mimetype
+ })
+ match_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id])
+
+ if sppkp_document != ' ':
+ sppkp_mimetype, _ = mimetypes.guess_type(sppkp_filename)
+ sppkp_mimetype = sppkp_mimetype or 'application/octet-stream'
+ pdf_data = base64.b64decode(sppkp_document)
+ sppkp_attachment = request.env['ir.attachment'].create({
+ 'name': 'SPPKP Document',
+ 'type': 'binary',
+ 'datas': base64.b64encode(pdf_data),
+ 'res_model': 'res.partner',
+ 'res_id': match_company.id,
+ 'mimetype': sppkp_mimetype
+ })
+ match_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id])
else:
- new_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id])
+ # Create a user company request
+ request.env['user.company.request'].create({
+ 'user_id': user.id,
+ 'user_company_id': match_company.id,
+ 'user_input': business_name
+ })
+ else:
+ if not nama_wajib_pajak and is_pkp == 'false':
+ nama_wajib_pajak = business_name
+
+ if not alamat_wajib_pajak and is_pkp == 'false':
+ alamat_wajib_pajak = alamat_bisnis
+
+ new_company_data = {
+ 'name': business_name if business_name else business_name,
+ 'company_type_id': company_type_id if company_type_id else False,
+ 'industry_id': industry_id,
+ 'customer_type': 'pkp' if is_pkp == 'true' else 'nonpkp',
+ 'npwp': npwp if is_pkp == 'true' else (npwp if npwp else '00.000.000.0-000.000'),
+ 'sppkp': sppkp if is_pkp == 'true' else (sppkp if sppkp else '-'),
+ 'nama_wajib_pajak': nama_wajib_pajak,
+ 'alamat_lengkap_text': alamat_wajib_pajak,
+ 'email': email_partner,
+ 'street': alamat_bisnis,
+ 'company_type': 'company',
+ 'user_id': 3222,
+ 'property_account_receivable_id': 395,
+ 'property_account_payable_id': 438,
+ 'active': False,
+ }
+ new_company = request.env['res.partner'].create(new_company_data)
+ request.env['user.company.request'].create({
+ 'user_id': user.id,
+ 'user_company_id': new_company.id,
+ 'user_input': business_name
+ })
+ # user.partner_id.parent_id = new_company.id
+ # user.partner_id.customer_type = new_company.customer_type
+ # user.partner_id.npwp = new_company.npwp
+ # user.partner_id.sppkp = new_company.sppkp
+ # user.partner_id.nama_wajib_pajak = new_company.nama_wajib_pajak
+ # user.partner_id.alamat_lengkap_text = new_company.alamat_lengkap_text
+
+ if npwp_document != ' ':
+ npwp_mimetype, _ = mimetypes.guess_type(npwp_filename)
+ npwp_mimetype = npwp_mimetype or 'application/octet-stream'
+ pdf_data = base64.b64decode(npwp_document)
+ npwp_attachment = request.env['ir.attachment'].create({
+ 'name': 'NPWP Document',
+ 'type': 'binary',
+ 'datas': base64.b64encode(pdf_data),
+ 'res_model': 'res.partner',
+ 'res_id': new_company.id,
+ 'mimetype': npwp_mimetype
+ })
+ if user.parent_id:
+ match_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id])
+ else:
+ new_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id])
+
+ if sppkp_document != ' ':
+ sppkp_mimetype, _ = mimetypes.guess_type(sppkp_filename)
+ sppkp_mimetype = sppkp_mimetype or 'application/octet-stream'
+ pdf_data = base64.b64decode(sppkp_document)
+ sppkp_attachment = request.env['ir.attachment'].create({
+ 'name': 'SPPKP Document',
+ 'type': 'binary',
+ 'datas': base64.b64encode(pdf_data),
+ 'res_model': 'res.partner',
+ 'res_id': new_company.id,
+ 'mimetype': sppkp_mimetype
+ })
+ if user.parent_id:
+ match_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id])
+ else:
+ new_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id])
request_company = self.get_user_by_email(user.email)
request_company.parent_name = business_name
if user.parent_id:
- request_company.send_company_request_approve_mail()
+ request_company.send_company_switch_approve_mail()
else:
request_company.send_company_request_mail()
diff --git a/indoteknik_api/models/res_users.py b/indoteknik_api/models/res_users.py
index 0a302be9..195d786f 100644
--- a/indoteknik_api/models/res_users.py
+++ b/indoteknik_api/models/res_users.py
@@ -55,6 +55,7 @@ class ResUsers(models.Model):
'industry_id': user.industry_id.id or '',
'tax_name': user.nama_wajib_pajak or '',
'npwp': user.npwp or '',
+ 'sppkp': user.sppkp or '',
'rajaongkir_city_id': user.kecamatan_id.rajaongkir_id or 0,
'alamat_wajib_pajak': user.alamat_lengkap_text or '',
'alamat_bisnis': user.street or '',
diff --git a/indoteknik_custom/models/res_users.py b/indoteknik_custom/models/res_users.py
index 5e16aad1..16f94b37 100755
--- a/indoteknik_custom/models/res_users.py
+++ b/indoteknik_custom/models/res_users.py
@@ -41,6 +41,11 @@ class ResUsers(models.Model):
for user in self:
template.send_mail(user.id, force_send=True)
+ def send_company_switch_approve_mail(self):
+ template = self.env.ref('indoteknik_custom.mail_template_res_user_company_switch_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:
diff --git a/indoteknik_custom/views/res_users.xml b/indoteknik_custom/views/res_users.xml
index 41c74d72..b93ae012 100644
--- a/indoteknik_custom/views/res_users.xml
+++ b/indoteknik_custom/views/res_users.xml
@@ -181,6 +181,67 @@
</table>
</field>
</record>
+ <record id="mail_template_res_user_company_switch_approve" model="mail.template">
+ <field name="name">Users: Switch Account Success</field>
+ <field name="model_id" ref="base.model_res_users"/>
+ <field name="subject">Email Switch Account Berhasil</field>
+ <field name="email_from">"Indoteknik.com" &lt;noreply@indoteknik.com&gt;</field>
+ <field name="reply_to">sales@indoteknik.com</field>
+ <field name="email_to">${object.login | safe}</field>
+ <field name="body_html" type="html">
+ <table border="0" cellpadding="0" cellspacing="0" style="padding-top: 16px; background-color: #F1F1F1; font-family:Inter, Helvetica, Verdana, Arial,sans-serif; line-height: 24px; color: #454748; width: 100%; border-collapse:separate;">
+ <tr><td align="center">
+ <table border="0" cellpadding="0" cellspacing="0" width="590" style="font-size: 13px; padding: 16px; background-color: white; color: #454748; border-collapse:separate;">
+ <!-- HEADER -->
+ <tbody>
+ <tr>
+ <td align="center" style="min-width: 590px;">
+ <table border="0" cellpadding="0" cellspacing="0" width="590" style="min-width: 590px; background-color: white; padding: 0px 8px 0px 8px; border-collapse:separate;">
+ <tr>
+ <td valign="middle">
+ <span></span>
+ </td>
+ </tr>
+
+ <tr>
+ <td colspan="2" style="text-align:center;">
+ <hr width="100%" style="background-color:rgb(204,204,204);border:medium none;clear:both;display:block;font-size:0px;min-height:1px;line-height:0; margin: 16px 0px 16px 0px;" />
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <!-- CONTENT -->
+ <tr>
+ <td align="center" style="min-width: 590px;">
+ <table border="0" cellpadding="0" cellspacing="0" width="590" style="min-width: 590px; background-color: white; padding: 0px 8px 0px 8px; border-collapse:separate;">
+ <tr><td style="padding-bottom: 24px;"><b>Yth. ${object.parent_name},</b></td></tr>
+
+ <tr><td style="padding-bottom: 16px;">Selamat! Perpindahan akun bisnis Anda menjadi PKP di indoteknik.com telah <b>berhasil</b> kini anda dapat menikmati berbagai kemudahan dalam berbelanja, antara lain:</td></tr>
+ <tr><td style="padding-bottom: 16px;"><b>Fitur Faktur Pajak &amp; Invoice:</b> Dengan mudah download faktur pajak &amp; Invoice Anda secara digital.</td></tr>
+ <tr><td style="padding-bottom: 16px;"><b>Pembayaran Lengkap:</b> Pilih metode pembayaran yang sesuai dengan kebutuhan Anda, baik transfer bank, VA, kartu kredit, atau pembayaran tempo.</td></tr>
+ <tr><td style="padding-bottom: 16px;"><b>Pelacakan Pengiriman:</b> Lacak status pengiriman pesanan Anda secara real-time.</td></tr>
+ <tr><td style="padding-bottom: 16px;">Untuk memulai transaksi, silakan login Kembali menggunakan akun Anda di <a href="https://indoteknik.com/login">Indoteknik.com</a></td></tr>
+ <tr><td style="padding-bottom: 16px;">Kami sangat senang dapat melayani Anda. Jika ada pertanyaan atau membutuhkan bantuan, jangan ragu untuk menghubungi tim layanan Customer kami di Whatsapp <a href="https://wa.me/6281717181922">0817-1718-1922</a> atau <a href="mailto:sales@indoteknik.com">sales@indoteknik.com</a></td></tr>
+
+ <tr><td style="padding-bottom: 2px;"><b>Hormat kami,</b></td></tr>
+ <tr><td style="padding-bottom: 2px;">Indoteknik.com</td></tr>
+ <tr>
+ <td style="text-align:center;">
+ <hr width="100%"
+ style="background-color:rgb(204,204,204);border:medium none;clear:both;display:block;font-size:0px;min-height:1px;line-height:0; margin: 16px 0px 16px 0px;" />
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <!-- CONTENT -->
+ </tbody>
+ </table>
+ </td></tr>
+ </table>
+ </field>
+ </record>
<record id="mail_template_res_user_company_request_reject" model="mail.template">
<field name="name">Users: Company Request Reject</field>
<field name="model_id" ref="base.model_res_users"/>