diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-02-25 11:53:29 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-02-25 11:53:29 +0700 |
| commit | 13c90b5a95391d797b89c39b90c1430400ed29b7 (patch) | |
| tree | 1df668fee68e72a76cbcc5255e5d533b3721d190 /indoteknik_custom/models/user_company_request.py | |
| parent | 0f7f7fa273295fadde403c4ff9333b3bbe14489a (diff) | |
| parent | 029e8fce907060de2a2514b5abc731f4cd9da96e (diff) | |
Merge branch 'staging' into release
Diffstat (limited to 'indoteknik_custom/models/user_company_request.py')
| -rw-r--r-- | indoteknik_custom/models/user_company_request.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/indoteknik_custom/models/user_company_request.py b/indoteknik_custom/models/user_company_request.py new file mode 100644 index 00000000..2467261a --- /dev/null +++ b/indoteknik_custom/models/user_company_request.py @@ -0,0 +1,31 @@ +from odoo import models, fields +from odoo.exceptions import UserError + + +class UserCompanyRequest(models.Model): + _name = 'user.company.request' + _rec_name = 'user_id' + + user_id = fields.Many2one('res.partner', string='User') + user_company_id = fields.Many2one('res.partner', string='Company') + user_input = fields.Char(string='User Input') + is_approve = fields.Selection([ + ('approved', 'Approve'), + ('rejected', 'Reject'), + ], string='Approval') + + def write(self, vals): + is_approve = vals.get('is_approve') + if self.is_approve and is_approve: + raise UserError('Tidak dapat mengubah approval yang sudah diisi') + + if not self.is_approve and is_approve: + if is_approve == 'approved': + self.user_id.parent_id = self.user_company_id.id + else: + new_company = self.env['res.partner'].create({ + 'name': self.user_input + }) + self.user_id.parent_id = new_company.id + return super(UserCompanyRequest, self).write(vals) +
\ No newline at end of file |
