diff options
| author | Indoteknik . <it@fixcomart.co.id> | 2025-08-07 16:22:02 +0700 |
|---|---|---|
| committer | Indoteknik . <it@fixcomart.co.id> | 2025-08-07 16:22:02 +0700 |
| commit | 191674fade65d63c54807e30b569fc308688df9a (patch) | |
| tree | 5a12add9a79d82cf784f11e8c872a18287be5a02 | |
| parent | 757ad58d71344a48a6196296551dbfba68fa26d2 (diff) | |
(andri) rev approval
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 94cfdc39..6dc1b4a2 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -2159,7 +2159,9 @@ class SaleOrder(models.Model): # if order.validate_partner_invoice_due(): # return self._create_notification_action('Notification', # 'Terdapat invoice yang telah melewati batas waktu, mohon perbarui pada dokumen Due Extension') - + + if not order._is_request_to_own_team_leader(): + raise UserError("Anda hanya dapat mengonfirmasi SO dari anggota tim Anda sendiri.") if order._requires_approval_margin_leader(): order.approval_status = 'pengajuan2' return self._create_approval_notification('Pimpinan') @@ -2490,10 +2492,37 @@ class SaleOrder(models.Model): def _requires_approval_margin_leader(self): return self.total_percent_margin <= 15 and not self.env.user.is_leader - def _requires_approval_margin_manager(self): - return 15 < self.total_percent_margin <= 24 and not self.env.user.is_sales_manager and not self.env.user.id == 375 and not self.env.user.is_leader + # def _requires_approval_margin_manager(self): + # return 15 < self.total_percent_margin <= 24 and not self.env.user.is_sales_manager and not self.env.user.id == 375 and not self.env.user.is_leader # return self.total_percent_margin >= 15 and not self.env.user.is_leader and not self.env.user.is_sales_manager + def _requires_approval_margin_manager(self): + margin = self.total_percent_margin + user = self.env.user + user_id = user.id + + if margin <= 15 or margin > 24: # Di luar range margin manager approval + return False + if (user.is_leader or (margin >= 17 and user.is_sales_manager) or (margin >= 18 and user_id in [11, 9, 375])): + return False + + return True # Butuh approval manager + + def _is_request_to_own_team_leader(self): + approver_id = self.env.user.id + salesperson_id = self.user_id.id + team_map = { + 11: [10406], # Eko : Firman + 9: [11314, 6609], # Ade : Boy, Mario + 375: [9928, 10], # Putra : Aro, Putri + } + + for lead_id, members in team_map.items(): + if salesperson_id in members: + return approver_id == lead_id + + return True + def _create_approval_notification(self, approval_role): title = 'Warning' message = f'SO butuh approval {approval_role}' |
