diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-11-08 09:41:36 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-11-08 09:41:36 +0700 |
| commit | af160c1c287593d35089db337483ae472ae15875 (patch) | |
| tree | 87e4983cda8db06f97d3cd3dab49bad2aa3c5cd9 | |
| parent | 23c357465171e83e716c7a2619d4aa03041705b8 (diff) | |
| parent | 12492662cac198463233dec43952e43038611ada (diff) | |
Merge branch 'commision-window' into production
| -rwxr-xr-x | indoteknik_custom/__manifest__.py | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/commision.py | 223 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 5 | ||||
| -rw-r--r-- | indoteknik_custom/views/customer_commision.xml | 187 | ||||
| -rw-r--r-- | indoteknik_custom/views/ir_sequence.xml | 10 |
6 files changed, 426 insertions, 1 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index f2259c6a..bab86aab 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -101,6 +101,7 @@ 'views/product_monitoring.xml', 'views/account_bank_statement.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 87a4bc24..35f06f03 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -92,3 +92,4 @@ from . import quotation_so_multi_update from . import product_monitoring from . import account_bank_statement 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..0dbbce52 --- /dev/null +++ b/indoteknik_custom/models/commision.py @@ -0,0 +1,223 @@ +from odoo import models, api, fields +from odoo.exceptions import UserError +from datetime import datetime +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', 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): + _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) + 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) + 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') + 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): + 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): + vals['number'] = self.env['ir.sequence'].next_by_code('customer.commision') or '0' + result = super(CustomerCommision, self).create(vals) + return result + + def action_confirm_customer_commision(self): + 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) + + for partner in partners: + 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), + ] + 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): + _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') + +class AccountMove(models.Model): + _inherit = 'account.move' + is_customer_commision = fields.Boolean(string='Customer Commision Used') diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 7a074c71..ff467204 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -78,4 +78,7 @@ 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 +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 new file mode 100644 index 00000000..f067093b --- /dev/null +++ b/indoteknik_custom/views/customer_commision.xml @@ -0,0 +1,187 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<odoo> + <record id="customer_commision_tree" model="ir.ui.view"> + <field name="name">customer.commision.tree</field> + <field name="model">customer.commision</field> + <field name="arch" type="xml"> + <tree> + <field name="number"/> + <field name="date_from"/> + <field name="date_to"/> + <field name="partner_id"/> + <field name="description"/> + <field name="notification" readonly="1"/> + <field name="status" readonly="1"/> + </tree> + </field> + </record> + + <record id="customer_commision_line_tree" model="ir.ui.view"> + <field name="name">customer.commision.line.tree</field> + <field name="model">customer.commision.line</field> + <field name="arch" type="xml"> + <tree editable="top" create="false" delete="false"> + <field name="partner_id" readonly="1"/> + <field name="invoice_id" readonly="1"/> + <field name="state" readonly="1"/> + <field name="dpp" readonly="1"/> + <field name="tax" readonly="1"/> + <field name="total" readonly="1"/> + </tree> + </field> + </record> + + <record id="customer_commision_form" model="ir.ui.view"> + <field name="name">customer_commision_form</field> + <field name="model">customer.commision</field> + <field name="arch" type="xml"> + <form> + <header> + <button name="action_confirm_customer_commision" + string="Confirm" type="object" + options="{}"/> + </header> + <sheet string="Customer Commision"> + <div class="oe_button_box" name="button_box"/> + <group> + <group> + <field name="number"/> + <field name="date_from"/> + <field name="partner_id"/> + <field name="description"/> + <field name="commision_percent"/> + <field name="commision_amt"/> + </group> + <group> + <div> + <button name="generate_customer_commision" + string="Generate Line" + type="object" + class="mr-2 oe_highlight" + /> + </div> + <field name="date_to"/> + <field name="notification" readonly="1"/> + <field name="status" readonly="1"/> + <field name="total_dpp"/> + </group> + </group> + <notebook> + <page string="Lines"> + <field name="commision_lines"/> + </page> + </notebook> + </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_commision_action" model="ir.actions.act_window"> + <field name="name">Customer Commision</field> + <field name="type">ir.actions.act_window</field> + <field name="res_model">customer.commision</field> + <field name="view_mode">tree,form</field> + </record> + + <menuitem id="menu_customer_commision_acct" + name="Customer Commision" + action="customer_commision_action" + parent="account.menu_finance_entries" + sequence="113" + /> + + <menuitem id="menu_customer_commision_sales" + name="Customer Commision" + action="customer_commision_action" + 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 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 @@ <field name="number_next">1</field> <field name="number_increment">1</field> </record> + + <record id="sequence_commision_customer" model="ir.sequence"> + <field name="name">Customer Commision</field> + <field name="code">customer.commision</field> + <field name="active">TRUE</field> + <field name="prefix">CC/%(year)s/</field> + <field name="padding">5</field> + <field name="number_next">1</field> + <field name="number_increment">1</field> + </record> </data> </odoo>
\ No newline at end of file |
