from odoo import models, fields, api, _ from odoo.exceptions import UserError from odoo.http import request class RejectReasonWizardMerchant(models.TransientModel): _name = 'reject.reason.wizard.merchant' _description = 'Wizard for Reject Reason' request_id = fields.Many2one('user.merchant.request', string='Request') reason_reject = fields.Text(string='Reason for Rejection', required=True) def confirm_reject(self): merchant = self.request_id if merchant: merchant.write({'reason_reject': self.reason_reject}) merchant.state_merchant = 'reject' return {'type': 'ir.actions.act_window_close'} class ConfirmApprovalWizardMerchant(models.TransientModel): _name = 'confirm.approval.wizard.merchant' _description = 'Wizard Konfirmasi Approval' merchant_id = fields.Many2one('user.merchant.request', string='Merchant', required=True) def confirm_approval(self): merchant = self.merchant_id if merchant.state_merchant == 'draft': merchant.state_merchant = 'approved' class UserMerchantRequest(models.Model): _name = 'user.merchant.request' _inherit = ['mail.thread', 'mail.activity.mixin'] _rec_name = 'user_id' user_id = fields.Many2one('res.partner', string='User') merchant_id = fields.Many2one('user.form.merchant', string='Form Merchant') user_company_id = fields.Many2one('res.partner', string='Company') state_merchant = fields.Selection([ ('draft', 'Pengajuan Merchant'), ('approved', 'Approved Merchant'), ('reject', 'Rejected'), ], string='Status', readonly=True, copy=False, index=True, track_visibility='onchange', default='draft') reason_reject = fields.Char(string='Reaject Reason') def button_approve(self): for merchant in self: return { 'type': 'ir.actions.act_window', 'name': 'Konfirmasi Approve', 'res_model': 'confirm.approval.wizard.merchant', 'view_mode': 'form', 'target': 'new', 'context': { 'default_merchant_id': merchant.id, }} def button_reject(self): return { 'type': 'ir.actions.act_window', 'name': _('Reject Reason'), 'res_model': 'reject.reason.wizard.merchant', 'view_mode': 'form', 'target': 'new', 'context': {'default_request_id': self.id}, } def write(self, vals): is_approve = True if self.state_merchant == 'approved' or vals.get('state_merchant') == 'approved' else False if is_approve: self.user_company_id.name_merchant = self.merchant_id.name_merchant self.user_company_id.pic_merchant = self.merchant_id.pic_merchant self.user_company_id.address_merchant = self.merchant_id.address self.user_company_id.state_merchant = self.merchant_id.state self.user_company_id.city_merchant = self.merchant_id.city self.user_company_id.district_merchant = self.merchant_id.district self.user_company_id.subDistrict_merchant = self.merchant_id.subDistrict self.user_company_id.zip_merchant = self.merchant_id.zip self.user_company_id.bank_name_merchant = self.merchant_id.bank_name self.user_company_id.rekening_name_merchant = self.merchant_id.rekening_name self.user_company_id.account_number_merchant = self.merchant_id.account_number self.user_company_id.email_company_merchant = self.merchant_id.email_company self.user_company_id.email_sales_merchant = self.merchant_id.email_sales self.user_company_id.email_finance_merchant = self.merchant_id.email_finance self.user_company_id.phone_merchant = self.merchant_id.phone self.user_company_id.mobile_merchant = self.merchant_id.mobile self.user_company_id.harga_tayang = self.merchant_id.harga_tayang self.user_company_id.file_dokumenKtpDirut = self.merchant_id.file_dokumenKtpDirut self.user_company_id.file_kartuNama = self.merchant_id.file_kartuNama self.user_company_id.file_npwp = self.merchant_id.file_npwp self.user_company_id.file_sppkp = self.merchant_id.file_sppkp self.user_company_id.file_suratPernyataan = self.merchant_id.file_suratPernyataan self.user_company_id.file_fotoKantor = self.merchant_id.file_fotoKantor self.user_company_id.file_dataProduk = self.merchant_id.file_dataProduk self.user_company_id.file_pricelist = self.merchant_id.file_pricelist self.user_company_id.description = self.merchant_id.description return super(UserMerchantRequest, self).write(vals)