summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/commision.py
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2025-07-28 15:09:55 +0700
committerit-fixcomart <it@fixcomart.co.id>2025-07-28 15:09:55 +0700
commitd15ce4e186e2b77f01e8dfd03886298cc733d4c1 (patch)
tree1b32a4c29c4fcea85070fcecb5b77a7d55d30029 /indoteknik_custom/models/commision.py
parentdeba962d7368a5c4e30441b5a640102608e3dde6 (diff)
parent36a53535dbdc5777266fd9276b4c557259dab6be (diff)
<hafid> merging odoo-backup
Diffstat (limited to 'indoteknik_custom/models/commision.py')
-rw-r--r--indoteknik_custom/models/commision.py82
1 files changed, 68 insertions, 14 deletions
diff --git a/indoteknik_custom/models/commision.py b/indoteknik_custom/models/commision.py
index eeaa8efc..26b5df37 100644
--- a/indoteknik_custom/models/commision.py
+++ b/indoteknik_custom/models/commision.py
@@ -148,6 +148,7 @@ class CustomerCommision(models.Model):
_order = 'id desc'
_inherit = ['mail.thread']
_rec_name = 'number'
+ _description = 'Customer Benefits'
number = fields.Char(string='Document No', index=True, copy=False, readonly=True)
date_from = fields.Date(string='Date From', required=True)
@@ -175,10 +176,24 @@ class CustomerCommision(models.Model):
('approved', 'Approved'),
('reject', 'Rejected'),
], string='Status')
- commision_percent = fields.Float(string='Commision %', tracking=3)
- commision_amt = fields.Float(string='Commision Amount', tracking=3)
- commision_amt_text = fields.Char(string='Commision Amount Text', compute='compute_delivery_amt_text')
+
+ # commision_percent = fields.Float(string='Commision %', tracking=3)
+ commision_percent = fields.Float(string='Persentase (%)', tracking=3)
+
+ # commision_amt = fields.Float(string='Commision Amount', tracking=3)
+ commision_amt = fields.Float(string='Amount', tracking=3)
+
+ # cashback = fields.Float(string='Cashback', compute="compute_cashback")
+ cashback = fields.Float(string='PPh Cashback', compute="compute_cashback")
+
+ # total_commision = fields.Float(string='Total Commision', compute="compute_cashback")
+ total_commision = fields.Float(string='Cashback yang dibayarkan', compute="compute_cashback")
+
+ total_cashback = fields.Float(string='Total Cashback')
+ commision_amt_text = fields.Char(string='Amount Text', compute='compute_delivery_amt_text')
+ total_cashback_text = fields.Char(string='Cashback Text', compute='compute_total_cashback_text')
total_dpp = fields.Float(string='Total DPP', compute='_compute_total_dpp')
+ biaya_lain_lain = fields.Float(string='Biaya Lain-lain')
commision_type = fields.Selection([
('fee', 'Fee'),
('cashback', 'Cashback'),
@@ -268,6 +283,20 @@ class CustomerCommision(models.Model):
except:
record.commision_amt_text = res
+ def compute_total_cashback_text(self):
+ tb = Terbilang()
+
+ for record in self:
+ res = ''
+ try:
+ if record.total_commision > 0:
+ tb.parse(int(record.total_commision))
+ res = tb.getresult().title()
+ record.total_cashback_text = f"{res} Rupiah" if res else ""
+ except Exception as e:
+ record.total_cashback_text = ""
+ _logger.error("Error computing cashback text: %s", str(e))
+
def _compute_grouped_numbers(self):
for rec in self:
so_numbers = set()
@@ -328,23 +357,48 @@ class CustomerCommision(models.Model):
if self.total_dpp > 0 and self.commision_percent == 0:
self.commision_percent = (self.commision_amt / self.total_dpp) * 100
+ def compute_cashback(self):
+ if self.commision_type == 'cashback' and self.commision_amt > 0:
+ self.cashback = self.commision_amt * 0.15
+ self.total_commision = self.commision_amt * 0.85
+ else:
+ self.cashback = 0
+ self.total_commision = 0
+
def _compute_total_dpp(self):
for data in self:
total_dpp = 0
for line in data.commision_lines:
total_dpp = total_dpp + line.dpp
- data.total_dpp = total_dpp
+ data.total_dpp = total_dpp - data.biaya_lain_lain
@api.model
def create(self, vals):
- vals['number'] = self.env['ir.sequence'].next_by_code('customer.commision') or '0'
- # if vals['commision_amt'] > 0:
- # commision_amt = vals['commision_amt']
- # total_dpp = vals['total_dpp']
- # commision_percent = commision_amt / total_dpp * 100
- # vals['commision_percent'] = commision_percent
- result = super(CustomerCommision, self).create(vals)
- return result
+ commision_type = vals.get('commision_type')
+
+ if commision_type == 'cashback':
+ sequence_code = 'customer.commision.cashback'
+ elif commision_type == 'fee':
+ sequence_code = 'customer.commision.fee'
+ elif commision_type == 'rebate':
+ sequence_code = 'customer.commision.rebate'
+ else:
+ raise UserError('Tipe komisi tidak dikenal!')
+
+ vals['number'] = self.env['ir.sequence'].next_by_code(sequence_code) or '0'
+
+ return super(CustomerCommision, self).create(vals)
+
+ # @api.model
+ # def create(self, vals):
+ # vals['number'] = self.env['ir.sequence'].next_by_code('customer.commision') or '0'
+ # # if vals['commision_amt'] > 0:
+ # # commision_amt = vals['commision_amt']
+ # # total_dpp = vals['total_dpp']
+ # # commision_percent = commision_amt / total_dpp * 100
+ # # vals['commision_percent'] = commision_percent
+ # result = super(CustomerCommision, self).create(vals)
+ # return result
def action_confirm_customer_commision(self):
jakarta_tz = pytz.timezone('Asia/Jakarta')
@@ -354,12 +408,12 @@ class CustomerCommision(models.Model):
if not self.status or self.status == 'draft':
self.status = 'pengajuan1'
- elif self.status == 'pengajuan1' and self.env.user.is_sales_manager:
+ elif self.status == 'pengajuan1' and self.env.user.id == 19:
self.status = 'pengajuan2'
self.approved_by = (self.approved_by + ', ' if self.approved_by else '') + self.env.user.name
self.date_approved_sales = now_naive
self.position_sales = 'Sales Manager'
- elif self.status == 'pengajuan2' and self.env.user.id == 19:
+ elif self.status == 'pengajuan2' and self.env.user.id == 216:
self.status = 'pengajuan3'
self.approved_by = (self.approved_by + ', ' if self.approved_by else '') + self.env.user.name
self.date_approved_marketing = now_naive