From a4cd5ce9cd8d5ef38062732a16a61d6d5c094e30 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 3 Nov 2023 10:46:02 +0700 Subject: initial commit for new window of customer commision --- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/commision.py | 41 +++++++++++++ indoteknik_custom/security/ir.model.access.csv | 4 +- indoteknik_custom/views/customer_commision.xml | 82 ++++++++++++++++++++++++++ indoteknik_custom/views/ir_sequence.xml | 10 ++++ 6 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 indoteknik_custom/models/commision.py create mode 100644 indoteknik_custom/views/customer_commision.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 3bc4be60..a758d636 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -100,6 +100,7 @@ 'views/stock_move_line.xml', 'views/product_monitoring.xml', 'views/stock_warehouse_orderpoint.xml', + 'views/customer_commision.xml', 'report/report.xml', 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 6a5eac00..e842b511 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -91,3 +91,4 @@ from . import sale_orders_multi_update from . import quotation_so_multi_update from . import product_monitoring from . import stock_warehouse_orderpoint +from . import commision diff --git a/indoteknik_custom/models/commision.py b/indoteknik_custom/models/commision.py new file mode 100644 index 00000000..e39deb63 --- /dev/null +++ b/indoteknik_custom/models/commision.py @@ -0,0 +1,41 @@ +from odoo import models, api, fields +from odoo.exceptions import UserError +from datetime import datetime +import logging + +_logger = logging.getLogger(__name__) + + +class CustomerCommision(models.Model): + _name = 'customer.commision' + _order = 'id desc' + + number = fields.Char(string='Document No', index=True, copy=False, readonly=True) + date_from = fields.Date(string='Date From', required=True) + date_to = fields.Date(string='Date To', required=True) + partner_id = fields.Many2one('res.partner', String='Customer', required=True) + description = fields.Char(string='Description') + notification = fields.Char(string='Notification') + commision_lines = fields.One2many('customer.commision.line', 'customer_commision_id', string='Lines', auto_join=True) + + @api.model + def create(self, vals): + vals['number'] = self.env['ir.sequence'].next_by_code('customer.commision') or '0' + result = super(CustomerCommision, self).create(vals) + return result + + def generate_customer_commision(self): + print("masuk") + return + +class CustomerCommisionLine(models.Model): + _name = 'customer.commision.line' + _order = 'id' + + customer_commision_id = fields.Many2one('customer.commision', string='Ref', required=True, ondelete='cascade', copy=False) + invoice_id = fields.Many2one('account.move', string='Invoice') + partner_id = fields.Many2one('res.partner', string='Customer') + state = fields.Char(string='InvStatus') + dpp = fields.Float(string='DPP') + tax = fields.Float(string='TaxAmt') + total = fields.Float(string='Total') diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 7a074c71..ed8d4725 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -78,4 +78,6 @@ access_stock_scheduler_compute,access.stock.scheduler.compute,model_stock_schedu access_sale_order_promotion,access.sale.order.promotion,model_sale_order_promotion,,1,1,1,1 access_sale_orders_multi_update,access.sale.orders.multi_update,model_sale_orders_multi_update,,1,1,1,1 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 \ No newline at end of file +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 diff --git a/indoteknik_custom/views/customer_commision.xml b/indoteknik_custom/views/customer_commision.xml new file mode 100644 index 00000000..a714cb80 --- /dev/null +++ b/indoteknik_custom/views/customer_commision.xml @@ -0,0 +1,82 @@ + + + + customer.commision.tree + customer.commision + + + + + + + + + + + + + + customer.commision.line.tree + customer.commision.line + + + + + + + + + + + + + + customer_commision_form + customer.commision + +
+ +
+ + + + + + + + + + +
+
+
+
+ + + + + + + + + + + + Customer Commision + ir.actions.act_window + customer.commision + tree,form + + + + \ No newline at end of file diff --git a/indoteknik_custom/views/ir_sequence.xml b/indoteknik_custom/views/ir_sequence.xml index 6798e5b4..86259b12 100644 --- a/indoteknik_custom/views/ir_sequence.xml +++ b/indoteknik_custom/views/ir_sequence.xml @@ -60,5 +60,15 @@ 1 1 + + + Customer Commision + customer.commision + TRUE + CC/%(year)s/ + 5 + 1 + 1 + \ No newline at end of file -- cgit v1.2.3 From e12706c91da229ee1f556635968f8d9c42555af1 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 3 Nov 2023 11:30:41 +0700 Subject: add button confirm --- indoteknik_custom/models/commision.py | 28 +++++++++++++++++++++++++- indoteknik_custom/views/customer_commision.xml | 5 +++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/commision.py b/indoteknik_custom/models/commision.py index e39deb63..d6c0b0a5 100644 --- a/indoteknik_custom/models/commision.py +++ b/indoteknik_custom/models/commision.py @@ -24,8 +24,34 @@ class CustomerCommision(models.Model): result = super(CustomerCommision, self).create(vals) return result + def action_confirm_customer_commision(self): + print("a") + return + def generate_customer_commision(self): - print("masuk") + partners = [] + partners += self.partner_id.child_ids + partners.append(self.partner_id) + + for partner in partners: + where = [ + ('move_type', '=', 'out_invoice'), + ('state', '=', 'posted'), + ('partner_id.id', '=', partner.id), + ('invoice_date', '>=', self.date_from), + ('invoice_date', '<=', self.date_to), + ] + invoices = self.env['account.move'].search(where, order='id') + for invoice in invoices: + self.env['customer.commision.line'].create([{ + 'customer_commision_id': self.id, + 'partner_id': invoice.partner_id.id, + 'invoice_id': invoice.id, + 'state': invoice.state, + 'dpp': invoice.amount_untaxed_signed, + 'tax': invoice.amount_tax_signed, + 'total': invoice.amount_total_signed + }]) return class CustomerCommisionLine(models.Model): diff --git a/indoteknik_custom/views/customer_commision.xml b/indoteknik_custom/views/customer_commision.xml index a714cb80..b60cc1d9 100644 --- a/indoteknik_custom/views/customer_commision.xml +++ b/indoteknik_custom/views/customer_commision.xml @@ -35,6 +35,11 @@ customer.commision
+
+
-- cgit v1.2.3 From d445d93ab8688cd63a49ac6c128dca8eccb30fde Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Sat, 4 Nov 2023 11:56:57 +0700 Subject: change to dpp --- indoteknik_custom/models/commision.py | 43 +++++++++++++++++++++++++- indoteknik_custom/views/customer_commision.xml | 22 +++++++++++-- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/indoteknik_custom/models/commision.py b/indoteknik_custom/models/commision.py index d6c0b0a5..315e47f6 100644 --- a/indoteknik_custom/models/commision.py +++ b/indoteknik_custom/models/commision.py @@ -9,6 +9,8 @@ _logger = logging.getLogger(__name__) class CustomerCommision(models.Model): _name = 'customer.commision' _order = 'id desc' + _inherit = ['mail.thread'] + _rec_name = 'number' number = fields.Char(string='Document No', index=True, copy=False, readonly=True) date_from = fields.Date(string='Date From', required=True) @@ -17,6 +19,30 @@ class CustomerCommision(models.Model): description = fields.Char(string='Description') notification = fields.Char(string='Notification') commision_lines = fields.One2many('customer.commision.line', 'customer_commision_id', string='Lines', auto_join=True) + status = fields.Selection([ + ('pengajuan', 'Menunggu Approval'), + ('approved', 'Approved') + ], string='Status', copy=False, readonly=True, tracking=3) + commision_percent = fields.Float(string='Commision %', tracking=3) + commision_amt = fields.Float(string='Commision Amount', tracking=3) + total_dpp = fields.Float(string='Total DPP', compute='_compute_total_dpp') + + @api.constrains('commision_percent') + def _onchange_commision_percent(self): + print('masuk onchange commision percent') + self.commision_amt = self.commision_percent * self.total_dpp // 100 + + # @api.constrains('commision_amt') + # def _onchange_commision_amt(self): + # print('masuk onchange commision amt') + # self.commision_percent = (self.commision_amt / self.grand_total * 100) + + 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 @api.model def create(self, vals): @@ -25,10 +51,20 @@ class CustomerCommision(models.Model): return result def action_confirm_customer_commision(self): - print("a") + if not self.status: + self.status = 'pengajuan' + elif self.status == 'pengajuan' and self.env.user.is_leader: + for line in self.commision_lines: + line.invoice_id.is_customer_commision = True + self.status = 'approved' + else: + raise UserError('Harus di approved oleh Pimpinan') return def generate_customer_commision(self): + if self.commision_lines: + raise UserError('Line sudah ada, tidak bisa di generate ulang') + partners = [] partners += self.partner_id.child_ids partners.append(self.partner_id) @@ -37,6 +73,7 @@ class CustomerCommision(models.Model): where = [ ('move_type', '=', 'out_invoice'), ('state', '=', 'posted'), + ('is_customer_commision', '=', False), ('partner_id.id', '=', partner.id), ('invoice_date', '>=', self.date_from), ('invoice_date', '<=', self.date_to), @@ -65,3 +102,7 @@ class CustomerCommisionLine(models.Model): dpp = fields.Float(string='DPP') tax = fields.Float(string='TaxAmt') total = fields.Float(string='Total') + +class AccountMove(models.Model): + _inherit = 'account.move' + is_customer_commision = fields.Boolean(string='Customer Commision Used') diff --git a/indoteknik_custom/views/customer_commision.xml b/indoteknik_custom/views/customer_commision.xml index b60cc1d9..ccaa0727 100644 --- a/indoteknik_custom/views/customer_commision.xml +++ b/indoteknik_custom/views/customer_commision.xml @@ -11,6 +11,7 @@ + @@ -46,10 +47,10 @@ - - + +
@@ -59,6 +60,10 @@ class="mr-2 oe_highlight" />
+ + + +
@@ -67,6 +72,10 @@ +
+ + +
@@ -78,10 +87,17 @@ tree,form - + + \ No newline at end of file -- cgit v1.2.3 From efa51f6b1c5254996db90a90468241da303a7e21 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 6 Nov 2023 08:40:38 +0700 Subject: new table of partner commision --- indoteknik_custom/models/commision.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/indoteknik_custom/models/commision.py b/indoteknik_custom/models/commision.py index 315e47f6..6d61de4c 100644 --- a/indoteknik_custom/models/commision.py +++ b/indoteknik_custom/models/commision.py @@ -6,6 +6,17 @@ import logging _logger = logging.getLogger(__name__) +class CustomerRebate(models.Model): + _name = 'customer.rebate' + _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') + + class CustomerCommision(models.Model): _name = 'customer.commision' _order = 'id desc' @@ -26,6 +37,14 @@ class CustomerCommision(models.Model): commision_percent = fields.Float(string='Commision %', tracking=3) commision_amt = fields.Float(string='Commision Amount', tracking=3) total_dpp = fields.Float(string='Total DPP', compute='_compute_total_dpp') + commision_type = fields.Selection([ + ('fee', 'Fee'), + ('cashback', 'Cashback'), + ('rebate', 'Rebate'), + ], string='Commision Type') + + # add status for type of commision, fee, rebate / cashback + # include child or not? @api.constrains('commision_percent') def _onchange_commision_percent(self): -- cgit v1.2.3 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