summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2025-03-26 16:39:19 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2025-03-26 16:39:19 +0700
commit03d667e9a6f33531a41000eed335212abe79a5fb (patch)
tree03fa88756422cf8a8d652915fa648690956fad20 /indoteknik_custom/models
parent20cf871492e9de61669c577d31d2219d092796bf (diff)
parentcefc6ec6de52f2c79c1760cf88db3375f4956a31 (diff)
Merge branch 'cr/manzila-commision' into odoo-backup
# Conflicts: # indoteknik_custom/models/sale_order.py # indoteknik_custom/models/stock_picking.py
Diffstat (limited to 'indoteknik_custom/models')
-rw-r--r--indoteknik_custom/models/commision.py117
-rwxr-xr-xindoteknik_custom/models/sale_order.py16
2 files changed, 118 insertions, 15 deletions
diff --git a/indoteknik_custom/models/commision.py b/indoteknik_custom/models/commision.py
index 0d31e954..6d832b85 100644
--- a/indoteknik_custom/models/commision.py
+++ b/indoteknik_custom/models/commision.py
@@ -1,7 +1,8 @@
-from odoo import models, api, fields
+from odoo import models, api, fields, _
from odoo.exceptions import UserError
from datetime import datetime
import logging
+from terbilang import Terbilang
_logger = logging.getLogger(__name__)
@@ -121,6 +122,21 @@ class CustomerRebate(models.Model):
sum_dpp += invoice.price_subtotal
return sum_dpp
+class RejectReasonCommision(models.TransientModel):
+ _name = 'reject.reason.commision'
+ _description = 'Wizard for Reject Reason Customer Commision'
+
+ request_id = fields.Many2one('customer.commision', string='Request')
+ reason_reject = fields.Text(string='Reason for Rejection', required=True, tracking=True)
+
+ def confirm_reject(self):
+ commision = self.request_id
+ if commision:
+ commision.last_status = commision.status
+ commision.write({'reason_reject': self.reason_reject})
+ commision.status = 'reject'
+ return {'type': 'ir.actions.act_window_close'}
+
class CustomerCommision(models.Model):
_name = 'customer.commision'
@@ -136,37 +152,79 @@ class CustomerCommision(models.Model):
notification = fields.Char(string='Notification')
commision_lines = fields.One2many('customer.commision.line', 'customer_commision_id', string='Lines', auto_join=True)
status = fields.Selection([
- ('pengajuan1', 'Menunggu Approval Marketing'),
- ('pengajuan2', 'Menunggu Approval Pimpinan'),
- ('approved', 'Approved')
- ], string='Status', copy=False, readonly=True, tracking=3)
+ ('pengajuan1', 'Menunggu Approval Manager Sales'),
+ ('pengajuan2', 'Menunggu Approval Marketing'),
+ ('pengajuan3', 'Menunggu Approval Pimpinan'),
+ ('pengajuan4', 'Menunggu Approval Accounting'),
+ ('approved', 'Approved'),
+ ('reject', 'Rejected'),
+ ], string='Status', copy=False, readonly=True, tracking=3, index=True, track_visibility='onchange',default='draft')
+ last_status = fields.Selection([
+ ('pengajuan1', 'Menunggu Approval Manager Sales'),
+ ('pengajuan2', 'Menunggu Approval Marketing'),
+ ('pengajuan3', 'Menunggu Approval Pimpinan'),
+ ('pengajuan4', 'Menunggu Approval Accounting'),
+ ('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')
total_dpp = fields.Float(string='Total DPP', compute='_compute_total_dpp')
commision_type = fields.Selection([
('fee', 'Fee'),
('cashback', 'Cashback'),
('rebate', 'Rebate'),
], string='Commision Type', required=True)
- bank_name = fields.Char(string='Bank', tracking=3)
- account_name = fields.Char(string='Account Name', tracking=3)
- bank_account = fields.Char(string='Account No', tracking=3)
+ bank_name = fields.Char(string='Bank', tracking=3, required=True)
+ account_name = fields.Char(string='Account Name', tracking=3, required=True)
+ bank_account = fields.Char(string='Account No', tracking=3, required=True)
note_transfer = fields.Char(string='Keterangan')
brand_ids = fields.Many2many('x_manufactures', string='Brands')
payment_status = fields.Selection([
('pending', 'Pending'),
('payment', 'Payment'),
], string='Payment Status', copy=False, readonly=True, tracking=3, default='pending')
+ note_finnance = fields.Text('Notes Finnance')
+ reason_reject = fields.Char(string='Reason Reaject', tracking=True, track_visibility='onchange')
+ approved_by = fields.Char(string='Approved By', tracking=True, track_visibility='always')
+
grouped_so_number = fields.Char(string='Group SO Number', compute='_compute_grouped_numbers')
grouped_invoice_number = fields.Char(string='Group Invoice Number', compute='_compute_grouped_numbers')
+ sales_id = fields.Many2one('res.users', string="Sales", tracking=True)
+
+ date_approved_sales = fields.Datetime(string="Date Approved Sales", tracking=True)
+ date_approved_marketing = fields.Datetime(string="Date Approved Marketing", tracking=True)
+ date_approved_pimpinan = fields.Datetime(string="Date Approved Pimpinan", tracking=True)
+ date_approved_accounting = fields.Datetime(string="Date Approved Accounting", tracking=True)
+
+ position_sales = fields.Char(string="Position Sales", tracking=True)
+ position_marketing = fields.Char(string="Position Marketing", tracking=True)
+ position_pimpinan = fields.Char(string="Position Pimpinan", tracking=True)
+ position_accounting = fields.Char(string="Position Accounting", tracking=True)
+
+ def compute_delivery_amt_text(self):
+ tb = Terbilang()
+
+ for record in self:
+ res = ''
+
+ try:
+ if record.commision_amt > 0:
+ tb.parse(int(record.commision_amt))
+ res = tb.getresult().title()
+ record.commision_amt_text = res + ' Rupiah'
+ except:
+ record.commision_amt_text = res
+
def _compute_grouped_numbers(self):
for rec in self:
so_numbers = set()
invoice_numbers = set()
for line in rec.commision_lines:
- if line.invoice_id:
+ if line.invoice_id:
if line.invoice_id.sale_id:
so_numbers.add(line.invoice_id.sale_id.name)
invoice_numbers.add(line.invoice_id.name)
@@ -234,19 +292,50 @@ class CustomerCommision(models.Model):
result = super(CustomerCommision, self).create(vals)
return result
- def action_confirm_customer_commision(self):#add 2 step approval
- if not self.status:
+ def action_confirm_customer_commision(self):
+ now = datetime.utcnow()
+ if not self.status or self.status == 'draft':
self.status = 'pengajuan1'
- elif self.status == 'pengajuan1' and self.env.user.id == 19:
+ elif self.status == 'pengajuan1' and self.env.user.is_sales_manager:
self.status = 'pengajuan2'
- elif self.status == 'pengajuan2' and self.env.user.is_leader:
+ self.approved_by = (self.approved_by + ', ' if self.approved_by else '') + self.env.user.name
+ self.date_approved_sales = now
+ self.position_sales = 'Sales Manager'
+ elif self.status == 'pengajuan2' and self.env.user.id == 19:
+ self.status = 'pengajuan3'
+ self.approved_by = (self.approved_by + ', ' if self.approved_by else '') + self.env.user.name
+ self.date_approved_marketing = now
+ self.position_marketing = 'Marketing Manager'
+ elif self.status == 'pengajuan3' and self.env.user.is_leader:
+ self.status = 'pengajuan4'
+ self.approved_by = (self.approved_by + ', ' if self.approved_by else '') + self.env.user.name
+ self.date_approved_pimpinan = now
+ self.position_pimpinan = 'Pimpinan'
+ elif self.status == 'pengajuan4' and self.env.user.id == 1272:
for line in self.commision_lines:
line.invoice_id.is_customer_commision = True
self.status = 'approved'
+ self.approved_by = (self.approved_by + ', ' if self.approved_by else '') + self.env.user.name
+ self.date_approved_accounting = now
+ self.position_accounting = 'Accounting'
else:
raise UserError('Harus di approved oleh yang bersangkutan')
return
+ def action_reject(self):#add 2 step approval
+ return {
+ 'type': 'ir.actions.act_window',
+ 'name': _('Reject Reason'),
+ 'res_model': 'reject.reason.commision',
+ 'view_mode': 'form',
+ 'target': 'new',
+ 'context': {'default_request_id': self.id},
+ }
+
+ def button_draft(self):
+ for commision in self:
+ commision.status = commision.last_status if commision.last_status else 'draft'
+
def action_confirm_customer_payment(self):
if self.status != 'approved':
raise UserError('Commision harus di approve terlebih dahulu sebelum di konfirmasi pembayarannya')
@@ -351,7 +440,9 @@ class CustomerCommisionLine(models.Model):
tax = fields.Float(string='TaxAmt')
total = fields.Float(string='Total')
total_percent_margin = fields.Float('Total Margin', related='invoice_id.sale_id.total_percent_margin')
+ total_margin_excl_third_party = fields.Float('Before Margin', related='invoice_id.sale_id.total_margin_excl_third_party')
product_id = fields.Many2one('product.product', string='Product')
+ sale_order_id = fields.Many2one('sale.order', string='Sale Order', related='invoice_id.sale_id')
class AccountMove(models.Model):
_inherit = 'account.move'
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 1778536b..bee7d6a7 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -73,6 +73,7 @@ class SaleOrder(models.Model):
order_sales_match_line = fields.One2many('sales.order.purchase.match', 'sales_order_id', string='Purchase Match Lines', states={'cancel': [('readonly', True)], 'done': [('readonly', True)]}, copy=True)
total_margin = fields.Float('Total Margin', compute='_compute_total_margin', help="Total Margin in Sales Order Header")
total_percent_margin = fields.Float('Total Percent Margin', compute='_compute_total_percent_margin', help="Total % Margin in Sales Order Header")
+ total_margin_excl_third_party = fields.Float('Before Margin', help="Before Margin in Sales Order Header")
approval_status = fields.Selection([
('pengajuan1', 'Approval Manager'),
('pengajuan2', 'Approval Pimpinan'),
@@ -104,6 +105,7 @@ class SaleOrder(models.Model):
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",
help="Dipakai untuk alamat tempel", tracking=True)
fee_third_party = fields.Float('Fee Pihak Ketiga')
+ biaya_lain_lain = fields.Float('Biaya Lain Lain')
so_status = fields.Selection([
('terproses', 'Terproses'),
('sebagian', 'Sebagian Diproses'),
@@ -234,6 +236,12 @@ class SaleOrder(models.Model):
nomor_so_pengganti = fields.Char(string='Nomor SO Pengganti', copy=False, tracking=3)
shipping_option_id = fields.Many2one("shipping.option", string="Selected Shipping Option", domain="['|', ('sale_order_id', '=', False), ('sale_order_id', '=', id)]")
+ @api.constrains('fee_third_party', 'delivery_amt', 'biaya_lain_lain')
+ def _check_total_margin_excl_third_party(self):
+ for rec in self:
+ if rec.fee_third_party == 0:
+ rec.total_margin_excl_third_party = rec.total_percent_margin
+
@api.constrains('shipping_option_id')
def _check_shipping_option(self):
for rec in self:
@@ -453,7 +461,7 @@ class SaleOrder(models.Model):
delivery_amt = order.delivery_amt
else:
delivery_amt = 0
- order.percent_margin_after_delivery_purchase = round((order.margin_after_delivery_purchase / (order.amount_untaxed-delivery_amt-order.fee_third_party)) * 100, 2)
+ order.percent_margin_after_delivery_purchase = round((order.margin_after_delivery_purchase / (order.amount_untaxed-delivery_amt-order.fee_third_party-order.biaya_lain_lain)) * 100, 2)
def _compute_date_kirim(self):
for rec in self:
@@ -1427,7 +1435,7 @@ class SaleOrder(models.Model):
delivery_amt = 0
# order.total_percent_margin = round((order.total_margin / (order.amount_untaxed-delivery_amt-order.fee_third_party)) * 100, 2)
- order.total_percent_margin = round((order.total_margin / (order.amount_untaxed-order.fee_third_party)) * 100, 2)
+ order.total_percent_margin = round((order.total_margin / (order.amount_untaxed-order.fee_third_party-order.biaya_lain_lain)) * 100, 2)
# order.total_percent_margin = round((order.total_margin / (order.amount_untaxed)) * 100, 2)
@api.onchange('sales_tax_id')
@@ -1684,6 +1692,7 @@ class SaleOrder(models.Model):
order._compute_etrts_date()
order._validate_expected_ready_ship_date()
order._validate_delivery_amt()
+ order._check_total_margin_excl_third_party()
# order._update_partner_details()
return order
@@ -1727,6 +1736,9 @@ class SaleOrder(models.Model):
res = super(SaleOrder, self).write(vals)
self._validate_delivery_amt()
+ self._check_total_margin_excl_third_party()
if any(field in vals for field in ["order_line", "client_order_ref"]):
self._calculate_etrts_date()
+ if 'order_line' in vals:
+ self._compute_etrts_date()
return res \ No newline at end of file