From 12492662cac198463233dec43952e43038611ada Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 8 Nov 2023 08:59:13 +0700 Subject: add list customer rebate --- indoteknik_custom/models/commision.py | 104 ++++++++++++++++++++++++- indoteknik_custom/security/ir.model.access.csv | 3 +- indoteknik_custom/views/customer_commision.xml | 84 ++++++++++++++++++++ 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" /> + + + customer.rebate.tree + customer.rebate + + + + + + + + + + + + + + + + + + + + + + + + customer_rebate_form + customer.rebate + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + + + + Customer Rebate + ir.actions.act_window + customer.rebate + tree,form + + + + + \ No newline at end of file -- cgit v1.2.3