summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-11-08 08:59:13 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-11-08 08:59:13 +0700
commit12492662cac198463233dec43952e43038611ada (patch)
treeb378add34bcc626adac46ac31738b0b87524da68
parentaab2132ec791085ec02c57a9bba20d46ea48e7f7 (diff)
add list customer rebate
-rw-r--r--indoteknik_custom/models/commision.py104
-rwxr-xr-xindoteknik_custom/security/ir.model.access.csv3
-rw-r--r--indoteknik_custom/views/customer_commision.xml84
3 files changed, 186 insertions, 5 deletions
diff --git a/indoteknik_custom/models/commision.py b/indoteknik_custom/models/commision.py
index 6d61de4c..0dbbce52 100644
--- a/indoteknik_custom/models/commision.py
+++ b/indoteknik_custom/models/commision.py
@@ -11,10 +11,106 @@ class CustomerRebate(models.Model):
_order = 'id desc'
_inherit = ['mail.thread']
- partner_id = fields.Many2one('res.partner', string='Customer')
- date_from = fields.Date(string='Date From', required=True)
- date_to = fields.Date(string='Date To', required=True)
- target_quarter = fields.Float(string='Target/Quarter')
+ partner_id = fields.Many2one('res.partner', string='Customer', required=True)
+ date_from = fields.Date(string='Date From', required=True, help="Pastikan tanggal 1 januari, jika tidak, code akan break")
+ date_to = fields.Date(string='Date To', required=True, help="Pastikan tanggal 31 desember, jika tidak, code akan break")
+ description = fields.Char(string='Description')
+ target_1st = fields.Float(string='Target/Quarter 1st')
+ target_2nd = fields.Float(string='Target/Quarter 2nd')
+ achieve_1 = fields.Float(string='Achieve 1 %')
+ achieve_2 = fields.Float(string='Achieve 2 %')
+ dpp_q1 = fields.Float(string='DPP Q1', compute='_compute_current_dpp')
+ dpp_q2 = fields.Float(string='DPP Q2', compute='_compute_current_dpp')
+ dpp_q3 = fields.Float(string='DPP Q3', compute='_compute_current_dpp')
+ dpp_q4 = fields.Float(string='DPP Q4', compute='_compute_current_dpp')
+ status_q1 = fields.Char(string='Status Q1', compute='_compute_achievement')
+ status_q2 = fields.Char(string='Status Q2', compute='_compute_achievement')
+ status_q3 = fields.Char(string='Status Q3', compute='_compute_achievement')
+ status_q4 = fields.Char(string='Status Q4', compute='_compute_achievement')
+
+ def _compute_current_dpp(self):
+ for line in self:
+ line.dpp_q1 = line._get_current_dpp_q1(line)
+ line.dpp_q2 = line._get_current_dpp_q2(line)
+ line.dpp_q3 = line._get_current_dpp_q3(line)
+ line.dpp_q4 = line._get_current_dpp_q4(line)
+
+ def _compute_achievement(self):
+ for line in self:
+ line.status_q1 = line._check_achievement(line.target_1st, line.target_2nd, line.dpp_q1)
+ line.status_q2 = line._check_achievement(line.target_1st, line.target_2nd, line.dpp_q2)
+ line.status_q3 = line._check_achievement(line.target_1st, line.target_2nd, line.dpp_q3)
+ line.status_q4 = line._check_achievement(line.target_1st, line.target_2nd, line.dpp_q4)
+
+ def _check_achievement(self, target_1st, target_2nd, dpp):
+ status = 'not achieve'
+ if dpp >= target_1st:
+ status = '1st'
+ elif dpp >= target_2nd:
+ status = '2nd'
+ else:
+ status = 'not achieve'
+ return status
+
+ def _get_current_dpp_q1(self, line):
+ sum_dpp = 0
+ where = [
+ ('move_type', '=', 'out_invoice'),
+ ('state', '=', 'posted'),
+ ('is_customer_commision', '=', False),
+ ('partner_id.id', '=', line.partner_id.id),
+ ('invoice_date', '>=', line.date_from),
+ ('invoice_date', '<=', '2023-03-31'),
+ ]
+ invoices = self.env['account.move'].search(where, order='id')
+ for invoice in invoices:
+ sum_dpp += invoice.amount_untaxed_signed
+ return sum_dpp
+
+ def _get_current_dpp_q2(self, line):
+ sum_dpp = 0
+ where = [
+ ('move_type', '=', 'out_invoice'),
+ ('state', '=', 'posted'),
+ ('is_customer_commision', '=', False),
+ ('partner_id.id', '=', line.partner_id.id),
+ ('invoice_date', '>=', '2023-04-01'),
+ ('invoice_date', '<=', '2023-06-30'),
+ ]
+ invoices = self.env['account.move'].search(where, order='id')
+ for invoice in invoices:
+ sum_dpp += invoice.amount_untaxed_signed
+ return sum_dpp
+
+ def _get_current_dpp_q3(self, line):
+ sum_dpp = 0
+ where = [
+ ('move_type', '=', 'out_invoice'),
+ ('state', '=', 'posted'),
+ ('is_customer_commision', '=', False),
+ ('partner_id.id', '=', line.partner_id.id),
+ ('invoice_date', '>=', '2023-07-01'),
+ ('invoice_date', '<=', '2023-09-30'),
+ ]
+ invoices = self.env['account.move'].search(where, order='id')
+ for invoice in invoices:
+ sum_dpp += invoice.amount_untaxed_signed
+ return sum_dpp
+
+ def _get_current_dpp_q4(self, line):
+ sum_dpp = 0
+ where = [
+ ('move_type', '=', 'out_invoice'),
+ ('state', '=', 'posted'),
+ ('is_customer_commision', '=', False),
+ ('partner_id.id', '=', line.partner_id.id),
+ ('invoice_date', '>=', '2023-10-01'),
+ ('invoice_date', '<=', line.date_to),
+ ]
+ invoices = self.env['account.move'].search(where, order='id')
+ for invoice in invoices:
+ sum_dpp += invoice.amount_untaxed_signed
+ return sum_dpp
class CustomerCommision(models.Model):
diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv
index ed8d4725..ff467204 100755
--- a/indoteknik_custom/security/ir.model.access.csv
+++ b/indoteknik_custom/security/ir.model.access.csv
@@ -80,4 +80,5 @@ access_sale_orders_multi_update,access.sale.orders.multi_update,model_sale_order
access_quotation_so_multi_update,access.quotation.so.multi_update,model_quotation_so_multi_update,,1,1,1,1
access_product_monitoring,access.product.monitoring,model_product_monitoring,,1,1,1,1
access_customer_commision,access.customer.commision,model_customer_commision,,1,1,1,1
-access_customer_commision_line,access.customer.commision.line,model_customer_commision_line,,1,1,1,1 \ No newline at end of file
+access_customer_commision_line,access.customer.commision.line,model_customer_commision_line,,1,1,1,1
+access_customer_rebate,access.customer.rebate,model_customer_rebate,,1,1,1,1 \ No newline at end of file
diff --git a/indoteknik_custom/views/customer_commision.xml b/indoteknik_custom/views/customer_commision.xml
index ccaa0727..f067093b 100644
--- a/indoteknik_custom/views/customer_commision.xml
+++ b/indoteknik_custom/views/customer_commision.xml
@@ -100,4 +100,88 @@
parent="sale.product_menu_catalog"
sequence="101"
/>
+
+ <record id="customer_rebate_tree" model="ir.ui.view">
+ <field name="name">customer.rebate.tree</field>
+ <field name="model">customer.rebate</field>
+ <field name="arch" type="xml">
+ <tree>
+ <field name="partner_id"/>
+ <field name="date_from"/>
+ <field name="date_to"/>
+ <field name="description"/>
+ <field name="target_1st"/>
+ <field name="target_2nd"/>
+ <field name="achieve_1"/>
+ <field name="achieve_2"/>
+ <field name="dpp_q1" optional="hide"/>
+ <field name="dpp_q2" optional="hide"/>
+ <field name="dpp_q3" optional="hide"/>
+ <field name="dpp_q4" optional="hide"/>
+ <field name="status_q1" optional="hide"/>
+ <field name="status_q2" optional="hide"/>
+ <field name="status_q3" optional="hide"/>
+ <field name="status_q4" optional="hide"/>
+ </tree>
+ </field>
+ </record>
+
+ <record id="customer_rebate_form" model="ir.ui.view">
+ <field name="name">customer_rebate_form</field>
+ <field name="model">customer.rebate</field>
+ <field name="arch" type="xml">
+ <form>
+ <sheet string="Customer Rebate">
+ <div class="oe_button_box" name="button_box"/>
+ <group>
+ <group>
+ <field name="date_from"/>
+ <field name="partner_id"/>
+ <field name="target_1st"/>
+ <field name="target_2nd"/>
+ <field name="dpp_q1"/>
+ <field name="dpp_q2"/>
+ <field name="dpp_q3"/>
+ <field name="dpp_q4"/>
+ </group>
+ <group>
+ <field name="date_to"/>
+ <field name="description"/>
+ <field name="achieve_1"/>
+ <field name="achieve_2"/>
+ <field name="status_q1"/>
+ <field name="status_q2"/>
+ <field name="status_q3"/>
+ <field name="status_q4"/>
+ </group>
+ </group>
+ </sheet>
+ <div class="oe_chatter">
+ <field name="message_follower_ids" widget="mail_followers"/>
+ <field name="message_ids" widget="mail_thread"/>
+ </div>
+ </form>
+ </field>
+ </record>
+
+ <record id="customer_rebate_action" model="ir.actions.act_window">
+ <field name="name">Customer Rebate</field>
+ <field name="type">ir.actions.act_window</field>
+ <field name="res_model">customer.rebate</field>
+ <field name="view_mode">tree,form</field>
+ </record>
+
+ <menuitem id="menu_customer_rebate_acct"
+ name="Customer Rebate"
+ action="customer_rebate_action"
+ parent="account.menu_finance_entries"
+ sequence="114"
+ />
+
+ <menuitem id="menu_customer_rebate_sales"
+ name="Customer Rebate"
+ action="customer_rebate_action"
+ parent="sale.product_menu_catalog"
+ sequence="102"
+ />
</odoo> \ No newline at end of file