diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2025-11-08 11:00:09 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2025-11-08 11:00:09 +0700 |
| commit | bb7121ab8a7dbdfb104eefbeddc9fb6d4383054b (patch) | |
| tree | 185cc7030e973a82f7d6915b18aca13ca84f7cad | |
| parent | c37c06f2fa054e225a11972a0afbaf178f0ea8d0 (diff) | |
initial commit for branch feature/komisi-sales-internal
| -rwxr-xr-x | indoteknik_custom/__manifest__.py | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 3 | ||||
| -rw-r--r-- | indoteknik_custom/models/commission_internal.py | 129 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 2 | ||||
| -rw-r--r-- | indoteknik_custom/views/commission_internal.xml | 105 |
5 files changed, 239 insertions, 1 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index cf4d4ce3..66962a24 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -192,6 +192,7 @@ 'views/close_tempo_mail_template.xml', 'views/domain_apo.xml', 'views/uom_uom.xml', + 'views/commission_internal.xml' ], 'demo': [], 'css': [], diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 6e1ef2e0..a14c766e 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -163,4 +163,5 @@ from . import letter_receivable from . import sj_tele from . import partial_delivery from . import domain_apo -from . import uom_uom
\ No newline at end of file +from . import uom_uom +from . import commission_internal diff --git a/indoteknik_custom/models/commission_internal.py b/indoteknik_custom/models/commission_internal.py new file mode 100644 index 00000000..8a333bda --- /dev/null +++ b/indoteknik_custom/models/commission_internal.py @@ -0,0 +1,129 @@ +from odoo import models, api, fields +from odoo.exceptions import AccessError, UserError, ValidationError +from datetime import timedelta, date +import logging + +_logger = logging.getLogger(__name__) + + +class CommissionInternal(models.Model): + _name = 'commission.internal' + _description = 'Commission Internal' + _order = 'date_doc, id desc' + _inherit = ['mail.thread'] + _rec_name = 'number' + + number = fields.Char(string='Document No', index=True, copy=False, readonly=True) + date_doc = fields.Date(string='Document Date', required=True) + month = fields.Selection([ + ('01', 'January'), ('02', 'February'), ('03', 'March'), + ('04', 'April'), ('05', 'May'), ('06', 'June'), + ('07', 'July'), ('08', 'August'), ('09', 'September'), + ('10', 'October'), ('11', 'November'), ('12', 'December') + ], string="Commission Month") + year = fields.Selection([(str(y), str(y)) for y in range(2025, 2036)], string="Commission Year") + description = fields.Char(string='Description') + comment = fields.Char(string='Comment') + commission_internal_line = fields.One2many('commission.internal.line', 'commission_internal_id', string='Lines', + auto_join=True, order='account_move_id asc') + + @api.model + def create(self, vals): + vals['number'] = self.env['ir.sequence'].next_by_code('commission.internal') or '0' + result = super(CommissionInternal, self).create(vals) + return result + + def _get_commission_internal_bank_account_ids(self): + bank_ids = self.env['ir.config_parameter'].sudo().get_param('commission.internal.bank.account.id') + if not bank_ids: + return [] + return [int(x.strip()) for x in bank_ids.split(',') if x.strip().isdigit()] + + def _get_period_range(self, period_year, period_month): + """Return (date_start, date_end) using separate year and month fields.""" + self.ensure_one() # make sure it's called on a single record + + year_str = period_year or '' + month_str = period_month or '' + + # Validate both fields exist + if not (year_str.isdigit() and month_str.isdigit()): + return None, None + + year = int(year_str) + month = int(month_str) + + # First day of this month + dt_start = date(year, month, 1) + + # Compute first day of next month + if month == 12: + next_month = date(year + 1, 1, 1) + else: + next_month = date(year, month + 1, 1) + + # Last day = one day before next month's first day + dt_end = next_month - timedelta(days=1) + + return dt_start, dt_end + + def generate_commission_from_generate_ledger(self): + if self.commission_internal_line: + raise UserError('Harus hapus semua line jika ingin generate ulang') + if not self.month: + raise UserError('Commission Month harus diisi') + if not self.year: + raise UserError('Commission Year harus diisi') + + dt_start, dt_end = self._get_period_range(self.year, self.month) + + account_bank_ids = self._get_commission_internal_bank_account_ids() + query = [ + ('move_id.state', '=', 'posted'), + ('account_id', 'in', account_bank_ids), + ('date', '>=', dt_start), + ('date', '<=', dt_end) + ] + ledgers = self.env['account.move.line'].search(query) + count = 0 + for ledger in ledgers: + _logger.info("Read General Ledger Account Move Line %s" % ledger.id) + self.env['commission.internal.line'].create([{ + 'commission_internal_id': self.id, + 'date': ledger.date, + 'number': ledger.move_id.name, + 'account_move_id': ledger.move_id.id, + 'account_move_line_id': ledger.id, + 'account_id': ledger.account_id.id, + 'label': ledger.name, + 'debit': ledger.debit, + 'credit': ledger.credit, + 'balance': ledger.balance + }]) + count += 1 + _logger.info("Commission Internal Line generated %s" % count) + + +class CommissionInternalLine(models.Model): + _name = 'commission.internal.line' + _description = 'Line' + _order = 'number asc, id' + + commission_internal_id = fields.Many2one('commission.internal', string='Internal Ref', required=True, + ondelete='cascade', index=True, copy=False) + date = fields.Date(string='Date') + number = fields.Char(string='Number') + account_move_id = fields.Many2one('account.move', string='Account Move') + account_move_line_id = fields.Many2one('account.move.line', string='Account Move Line') + account_id = fields.Many2one('account.account', string='Account') + label = fields.Char(string='Label') + debit = fields.Float(string='Debit') + credit = fields.Float(string='Credit') + balance = fields.Float(string='Balance') + ongkir = fields.Float(string='Ongkir') + refund = fields.Float(string='Refund') + pph = fields.Float(string='PPh23') + others = fields.Float(string='Others') + linenetamt = fields.Float(string='Net Amount') + dpp = fields.Float(string='DPP') + status = fields.Char(string='Status') diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index c01271d3..1a799d01 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -164,6 +164,8 @@ access_purchase_order_unlock_wizard,access.purchase.order.unlock.wizard,model_pu access_sales_order_koli,access.sales.order.koli,model_sales_order_koli,,1,1,1,1 access_stock_backorder_confirmation,access.stock.backorder.confirmation,model_stock_backorder_confirmation,,1,1,1,1 access_warning_modal_wizard,access.warning.modal.wizard,model_warning_modal_wizard,,1,1,1,1 +access_commission_internal,access.commission.internal,model_commission_internal,,1,1,1,1 +access_commission_internal_line,access.commission.internal.line,model_commission_internal_line,,1,1,1,1 access_User_pengajuan_tempo_line,access.user.pengajuan.tempo.line,model_user_pengajuan_tempo_line,,1,1,1,1 access_user_pengajuan_tempo,access.user.pengajuan.tempo,model_user_pengajuan_tempo,,1,1,1,1 diff --git a/indoteknik_custom/views/commission_internal.xml b/indoteknik_custom/views/commission_internal.xml new file mode 100644 index 00000000..1489a83b --- /dev/null +++ b/indoteknik_custom/views/commission_internal.xml @@ -0,0 +1,105 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<odoo> + <record id="commission_internal_tree" model="ir.ui.view"> + <field name="name">commission.internal.tree</field> + <field name="model">commission.internal</field> + <field name="arch" type="xml"> + <tree> + <field name="number"/> + <field name="date_doc"/> + <field name="month"/> + <field name="year"/> + <field name="description"/> + <field name="comment"/> + </tree> + </field> + </record> + + <record id="commission_internal_form" model="ir.ui.view"> + <field name="name">commission.internal.form</field> + <field name="model">commission.internal</field> + <field name="arch" type="xml"> + <form> + <sheet string="Header"> + <div class="oe_button_box" name="button_box"/> + <group> + <group> + <field name="number"/> + <field name="date_doc"/> + <field name="description"/> + <field name="comment" readonly="1"/> + </group> + <group> + <field name="month"/> + <field name="year"/> + <div> + <button name="generate_commission_from_generate_ledger" + string="Copy GL" + type="object" + /> + </div> + </group> + </group> + <notebook> + <page id="commission_internal_line_tab" string="Lines"> + <field name="commission_internal_line"/> + </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="commission_internal_line_tree" model="ir.ui.view"> + <field name="name">commission.internal.line.tree</field> + <field name="model">commission.internal.line</field> + <field name="arch" type="xml"> + <tree> + <field name="date"/> + <field name="number"/> + <field name="account_move_id" optional="hide"/> + <field name="account_move_line_id" optional="hide"/> + <field name="label"/> + <field name="debit"/> + <field name="credit"/> + <field name="balance"/> + <field name="ongkir"/> + <field name="refund"/> + <field name="pph"/> + <field name="others"/> + <field name="linenetamt"/> + <field name="dpp"/> + <field name="status"/> + </tree> + </field> + </record> + + <record id="view_commission_internal_filter" model="ir.ui.view"> + <field name="name">commission.internal.list.select</field> + <field name="model">commission.internal</field> + <field name="priority" eval="15"/> + <field name="arch" type="xml"> + <search string="Search Commission Internal"> + <field name="number"/> + </search> + </field> + </record> + + <record id="commission_internal_action" model="ir.actions.act_window"> + <field name="name">Commission Internal</field> + <field name="type">ir.actions.act_window</field> + <field name="res_model">commission.internal</field> + <field name="search_view_id" ref="view_commission_internal_filter"/> + <field name="view_mode">tree,form</field> + </record> + + <menuitem id="menu_commission_internal" + name="Commission Internal" + action="commission_internal_action" + parent="account.menu_finance_reports" + sequence="251"/> +</odoo>
\ No newline at end of file |
