summaryrefslogtreecommitdiff
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
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
-rw-r--r--indoteknik_custom/models/commision.py117
-rwxr-xr-xindoteknik_custom/models/sale_order.py16
-rwxr-xr-xindoteknik_custom/security/ir.model.access.csv1
-rw-r--r--indoteknik_custom/views/customer_commision.xml52
-rwxr-xr-xindoteknik_custom/views/sale_order.xml2
5 files changed, 170 insertions, 18 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
diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv
index 4d0e51eb..20b1c5b7 100755
--- a/indoteknik_custom/security/ir.model.access.csv
+++ b/indoteknik_custom/security/ir.model.access.csv
@@ -167,4 +167,5 @@ access_barcoding_product_line,access.barcoding.product.line,model_barcoding_prod
access_account_payment_register,access.account.payment.register,model_account_payment_register,,1,1,1,1
access_stock_inventory,access.stock.inventory,model_stock_inventory,,1,1,1,1
access_cancel_reason_order,cancel.reason.order,model_cancel_reason_order,,1,1,1,0
+access_reject_reason_commision,reject.reason.commision,model_reject_reason_commision,,1,1,1,0
access_shipping_option,shipping.option,model_shipping_option,,1,1,1,1
diff --git a/indoteknik_custom/views/customer_commision.xml b/indoteknik_custom/views/customer_commision.xml
index bb1628bc..5df494f3 100644
--- a/indoteknik_custom/views/customer_commision.xml
+++ b/indoteknik_custom/views/customer_commision.xml
@@ -11,7 +11,7 @@
<field name="partner_ids" widget="many2many_tags"/>
<field name="commision_percent"/>
<field name="commision_amt" readonly="1"/>
- <field name="status" readonly="1"/>
+ <field name="status" readonly="1" decoration-success="status == 'approved'" widget="badge" optional="show"/>
<field name="payment_status" readonly="1"
decoration-success="payment_status == 'payment'"
decoration-danger="payment_status == 'pending'"
@@ -30,10 +30,12 @@
<tree editable="top" create="false">
<field name="partner_id" readonly="1"/>
<field name="invoice_id" readonly="1"/>
+ <field name="sale_order_id" readonly="1"/>
<field name="state" readonly="1"/>
<field name="product_id" readonly="1" optional="hide"/>
<field name="dpp" readonly="1"/>
<field name="total_percent_margin" readonly="1"/>
+ <field name="total_margin_excl_third_party" readonly="1"/>
<field name="tax" readonly="1" optional="hide"/>
<field name="total" readonly="1" optional="hide"/>
</tree>
@@ -45,14 +47,27 @@
<field name="model">customer.commision</field>
<field name="arch" type="xml">
<form>
+<!-- attrs="{'invisible': [('status', 'in', ['draft','pengajuan1','pengajuan2','pengajuan3','pengajuan4'])]}"-->
<header>
- <button name="action_confirm_customer_commision"
+ <button name="action_confirm_customer_commision"
string="Confirm" type="object"
+ attrs="{'invisible': [('status', 'in', ['approved','reject'])]}"
options="{}"/>
+ <button name="action_reject"
+ string="Reject"
+ attrs="{'invisible': [('status', 'in', ['approved','reject'])]}"
+ type="object"/>
+ <button name="button_draft"
+ string="Reset to Draft"
+ attrs="{'invisible': [('status', '!=', 'reject')]}"
+ type="object"/>
<button name="action_confirm_customer_payment"
string="Konfirmasi Pembayaran" type="object"
options="{}"
attrs="{'invisible': [('payment_status', '==', 'payment')], 'readonly': [('payment_status', '=', 'payment')]}"/>
+ <field name="status" widget="statusbar"
+ statusbar_visible="draft,pengajuan1,pengajuan2,pengajuan3,pengajuan4,approved"
+ statusbar_colors='{"reject":"red"}'/>
</header>
<sheet string="Customer Commision">
<div class="oe_button_box" name="button_box"/>
@@ -64,8 +79,10 @@
<field name="description"/>
<field name="commision_percent"/>
<field name="commision_amt"/>
+ <field name="commision_amt_text"/>
<field name="grouped_so_number" readonly="1"/>
<field name="grouped_invoice_number" readonly="1"/>
+ <field name="approved_by" readonly="1"/>
</group>
<group>
<div>
@@ -79,7 +96,7 @@
<field name="commision_type"/>
<field name="brand_ids" widget="many2many_tags"/>
<field name="notification" readonly="1"/>
- <field name="status" readonly="1"/>
+<!-- <field name="status" readonly="1"/>-->
<field name="payment_status" readonly="1" />
<field name="total_dpp"/>
</group>
@@ -96,6 +113,11 @@
<field name="note_transfer"/>
</group>
</page>
+ <page string="Finance Notes">
+ <group>
+ <field name="note_finnance"/>
+ </group>
+ </page>
</notebook>
</sheet>
<div class="oe_chatter">
@@ -106,6 +128,30 @@
</field>
</record>
+ <!-- Wizard for Reject Reason -->
+ <record id="view_reject_reason_wizard_form" model="ir.ui.view">
+ <field name="name">reject.reason.commision.form</field>
+ <field name="model">reject.reason.commision</field>
+ <field name="arch" type="xml">
+ <form string="Reject Reason">
+ <group>
+ <field name="reason_reject" widget="text"/>
+ </group>
+ <footer>
+ <button string="Confirm" type="object" name="confirm_reject" class="btn-primary"/>
+ <button string="Cancel" class="btn-secondary" special="cancel"/>
+ </footer>
+ </form>
+ </field>
+ </record>
+
+ <record id="action_reject_reason_wizard" model="ir.actions.act_window">
+ <field name="name">Reject Reason</field>
+ <field name="res_model">reject.reason.commision</field>
+ <field name="view_mode">form</field>
+ <field name="target">new</field>
+ </record>
+
<record id="view_customer_commision_filter" model="ir.ui.view">
<field name="name">customer.commision.list.select</field>
<field name="model">customer.commision</field>
diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml
index 0d190f37..74730e06 100755
--- a/indoteknik_custom/views/sale_order.xml
+++ b/indoteknik_custom/views/sale_order.xml
@@ -31,7 +31,9 @@
<field name="shipping_paid_by" attrs="{'required': ['|', ('create_date', '&gt;', '2023-06-15'), ('create_date', '=', False)]}"/>
<field name="delivery_amt"/>
<field name="fee_third_party"/>
+ <field name="biaya_lain_lain"/>
<field name="total_percent_margin"/>
+ <field name="total_margin_excl_third_party" readonly="1"/>
<field name="type_promotion"/>
<label for="voucher_id"/>
<div class="o_row">