diff options
| author | HafidBuroiroh <hafidburoiroh09@gmail.com> | 2026-03-09 09:12:11 +0700 |
|---|---|---|
| committer | HafidBuroiroh <hafidburoiroh09@gmail.com> | 2026-03-09 09:12:11 +0700 |
| commit | d91af3da1edea3c6b8074726e5306ea42a7c0a4b (patch) | |
| tree | a6151be9861950b004851db6cc69159b3a101a93 /indoteknik_custom/models | |
| parent | f687d197ead268040d7f396eb26ea0035a6dac35 (diff) | |
| parent | a637972fca56a9f2e62636f7639cf27de033b248 (diff) | |
Merge branch 'odoo-backup' of https://bitbucket.org/altafixco/indoteknik-addons into CR/Sourcing-Job
Diffstat (limited to 'indoteknik_custom/models')
| -rw-r--r-- | indoteknik_custom/models/account_asset.py | 119 | ||||
| -rw-r--r-- | indoteknik_custom/models/account_move.py | 49 | ||||
| -rw-r--r-- | indoteknik_custom/models/commision.py | 2 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_order.py | 6 | ||||
| -rw-r--r-- | indoteknik_custom/models/refund_sale_order.py | 14 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 44 | ||||
| -rw-r--r-- | indoteknik_custom/models/tukar_guling_po.py | 2 |
7 files changed, 210 insertions, 26 deletions
diff --git a/indoteknik_custom/models/account_asset.py b/indoteknik_custom/models/account_asset.py index 211ab229..dbcb6ba4 100644 --- a/indoteknik_custom/models/account_asset.py +++ b/indoteknik_custom/models/account_asset.py @@ -1,5 +1,7 @@ from odoo import fields, models, api, _ from odoo.exceptions import AccessError, UserError, ValidationError +from odoo.tools import DEFAULT_SERVER_DATE_FORMAT as DF +from odoo.tools import float_compare, float_is_zero class AccountAsset(models.Model): @@ -14,3 +16,120 @@ class AccountAsset(models.Model): if asset.value > 0: raise UserError("Asset masih mempunyai Value") asset.state = 'close' + + +class AccountAssetDepreciationLine(models.Model): + _inherit = 'account.asset.depreciation.line' + + def create_move(self, post_move=True): + created_moves = self.env['account.move'] + prec = self.env['decimal.precision'].precision_get('Account') + if self.mapped('move_id'): + raise UserError(_( + 'This depreciation is already linked to a journal entry! Please post or delete it.')) + for line in self: + category_id = line.asset_id.category_id + depreciation_date = self.env.context.get( + 'depreciation_date') or line.depreciation_date or fields.Date.context_today( + self) + company_currency = line.asset_id.company_id.currency_id + current_currency = line.asset_id.currency_id + amount = current_currency.with_context( + date=depreciation_date).compute(line.amount, company_currency) + asset_name = line.asset_id.name + ' (%s/%s)' % ( + line.sequence, len(line.asset_id.depreciation_line_ids)) + partner = self.env['res.partner']._find_accounting_partner( + line.asset_id.partner_id) + move_line_1 = { + 'name': asset_name, + 'account_id': category_id.account_depreciation_id.id, + 'debit': 0.0 if float_compare(amount, 0.0, + precision_digits=prec) > 0 else -amount, + 'credit': amount if float_compare(amount, 0.0, + precision_digits=prec) > 0 else 0.0, + 'journal_id': category_id.journal_id.id, + 'partner_id': partner.id, + 'analytic_account_id': category_id.account_analytic_id.id if category_id.type == 'sale' else False, + 'currency_id': company_currency != current_currency and current_currency.id or False, + 'amount_currency': company_currency != current_currency and - 1.0 * line.amount or 0.0, + } + move_line_2 = { + 'name': asset_name, + 'account_id': category_id.account_depreciation_expense_id.id, + 'credit': 0.0 if float_compare(amount, 0.0, + precision_digits=prec) > 0 else -amount, + 'debit': amount if float_compare(amount, 0.0, + precision_digits=prec) > 0 else 0.0, + 'journal_id': category_id.journal_id.id, + 'partner_id': partner.id, + 'analytic_account_id': category_id.account_analytic_id.id if category_id.type == 'purchase' else False, + 'currency_id': company_currency != current_currency and current_currency.id or False, + 'amount_currency': company_currency != current_currency and line.amount or 0.0, + } + move_vals = { + 'ref': line.asset_id.code, + 'date': depreciation_date or False, + 'journal_id': category_id.journal_id.id, + 'line_ids': [(0, 0, move_line_1), (0, 0, move_line_2)], + } + move = self.env['account.move'].create(move_vals) + line.write({'move_id': move.id, 'move_check': True}) + created_moves |= move + + if post_move and created_moves: + created_moves.filtered(lambda m: any( + m.asset_depreciation_ids.mapped( + 'asset_id.category_id.open_asset'))).post() + + for move in created_moves: + move.action_post() + return [x.id for x in created_moves] + + def create_grouped_move(self, post_move=True): + if not self.exists(): + return [] + + created_moves = self.env['account.move'] + category_id = self[ + 0].asset_id.category_id # we can suppose that all lines have the same category + depreciation_date = self.env.context.get( + 'depreciation_date') or fields.Date.context_today(self) + amount = 0.0 + for line in self: + # Sum amount of all depreciation lines + company_currency = line.asset_id.company_id.currency_id + current_currency = line.asset_id.currency_id + amount += current_currency.compute(line.amount, company_currency) + + name = category_id.name + _(' (grouped)') + move_line_1 = { + 'name': name, + 'account_id': category_id.account_depreciation_id.id, + 'debit': 0.0, + 'credit': amount, + 'journal_id': category_id.journal_id.id, + 'analytic_account_id': category_id.account_analytic_id.id if category_id.type == 'sale' else False, + } + move_line_2 = { + 'name': name, + 'account_id': category_id.account_depreciation_expense_id.id, + 'credit': 0.0, + 'debit': amount, + 'journal_id': category_id.journal_id.id, + 'analytic_account_id': category_id.account_analytic_id.id if category_id.type == 'purchase' else False, + } + move_vals = { + 'ref': category_id.name, + 'date': depreciation_date or False, + 'journal_id': category_id.journal_id.id, + 'line_ids': [(0, 0, move_line_1), (0, 0, move_line_2)], + } + move = self.env['account.move'].create(move_vals) + self.write({'move_id': move.id, 'move_check': True}) + created_moves |= move + + if post_move and created_moves: + self.post_lines_and_close_asset() + created_moves.post() + created_moves.action_post() + return [x.id for x in created_moves]
\ No newline at end of file diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 42467b78..723f225c 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -601,6 +601,7 @@ class AccountMove(models.Model): template.send_mail(record.id, email_values=email_values, force_send=True) elif record.partner_id.id in special_partner_ids: + cust_ref = record.sale_id.client_order_ref if record.sale_id and record.sale_id.client_order_ref else '' attachment = self.generate_attachment(record) email_list = [record.partner_id.email] if record.partner_id.email else [] if record.real_invoice_id and record.real_invoice_id.email: @@ -610,7 +611,7 @@ class AccountMove(models.Model): 'email_to': ",".join(set(email_list)), 'attachment_ids': [(4, attachment.id)] } - template.send_mail(record.id, email_values=email_values, force_send=True) + template.with_context(cust_ref=cust_ref).send_mail(record.id, email_values=email_values, force_send=True) # @api.model # def create(self, vals): @@ -785,6 +786,24 @@ class AccountMove(models.Model): if rec.statement_line_id and not rec.statement_line_id.statement_id.is_edit and rec.statement_line_id.statement_id.state == 'confirm': raise UserError('Bank Statement di Lock, Minta admin reconcile untuk unlock') return res + + def action_open_change_date_wizard(self): + if not self.env.user.is_accounting: + raise UserError('Hanya Accounting yang bisa edit tanggal journal entry') + non_draft = self.filtered(lambda m: m.state != 'draft') + if non_draft: + raise UserError('Hanya invoice dengan status draft yang bisa diubah tanggalnya. Mohon reset ke draft terlebih dahulu.') + return{ + 'name': 'Change Date Journal Entry', + 'type': 'ir.actions.act_window', + 'view_mode': 'form', + 'res_model': 'account.move.change.date.wizard', + 'target': 'new', + 'context':{ + 'active_ids': self.ids, + 'active_model': self._name, + } + } def action_post(self): if self._name != 'account.move': @@ -996,3 +1015,31 @@ class SyncPromiseDateWizardLine(models.TransientModel): date_terima_tukar_faktur = fields.Date(related="invoice_id.date_terima_tukar_faktur", string="Tanggal Terima Tukar Faktur", readonly=True) amount_total = fields.Monetary(related="invoice_id.amount_total", string="Total", readonly=True) currency_id = fields.Many2one(related="invoice_id.currency_id", readonly=True) + +class AccountMoveChangeDateWizard(models.TransientModel): + _name = "account.move.change.date.wizard" + _description = "Account Move Change Date Wizard" + + # move_id = fields.Many2one('account.move', string="Journal Entry", required=True) + new_date = fields.Date(string="New Date", required=True) + + def action_change_date(self): + if not self.env.user.is_accounting: + raise UserError('Hanya Accounting yang bisa ubah tanggal') + + active_ids = self.env.context.get('active_ids', []) + moves = self.env['account.move'].browse(active_ids) + + if not moves: + raise UserError("Tidak ada journal entry yang dipilih.") + + non_draft_moves = moves.filtered(lambda m: m.state != 'draft') + if non_draft_moves: + raise UserError("Hanya journal entry dengan status 'Draft' yang dapat diubah tanggalnya.") + + for move in moves: + move.write({'date': self.new_date}) + move.message_post(body="Tanggal berhasil diubah") + + return {'type': 'ir.actions.act_window_close'} +
\ No newline at end of file diff --git a/indoteknik_custom/models/commision.py b/indoteknik_custom/models/commision.py index 983c07fe..afd36bc7 100644 --- a/indoteknik_custom/models/commision.py +++ b/indoteknik_custom/models/commision.py @@ -443,7 +443,7 @@ class CustomerCommision(models.Model): self.approved_by = (self.approved_by + ', ' if self.approved_by else '') + self.env.user.name self.date_approved_pimpinan = now_naive self.position_pimpinan = 'Pimpinan' - elif self.status == 'pengajuan4' and (self.env.user.id == 1272 or self.env.user.has_group('indoteknik_custom.group_role_it')): + elif self.status == 'pengajuan4' and (self.env.user.id in [1272,14075,571] or self.env.user.has_group('indoteknik_custom.group_role_it')): for line in self.commision_lines: line.invoice_id.is_customer_commision = True if self.commision_type == 'fee': diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index a345b96b..244575ae 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -1446,8 +1446,8 @@ class PurchaseOrder(models.Model): send_email = True break - if self.partner_id.id == 5571 and not self.revisi_po: - self.action_create_order_altama() + # if self.partner_id.id == 5571 and not self.revisi_po: + # self.action_create_order_altama() if send_email: if self.is_local_env(): @@ -1484,6 +1484,8 @@ class PurchaseOrder(models.Model): # if len(self) == 1: # _logger.info("Redirecting ke BU") # return self.action_view_related_bu() + if self.partner_id.id == 5571 and not self.revisi_po: + self.action_create_order_altama() return res diff --git a/indoteknik_custom/models/refund_sale_order.py b/indoteknik_custom/models/refund_sale_order.py index 4c3ca52e..6acd0b59 100644 --- a/indoteknik_custom/models/refund_sale_order.py +++ b/indoteknik_custom/models/refund_sale_order.py @@ -680,6 +680,20 @@ class RefundSaleOrder(models.Model): ('journal_id', '=', 13), ('state', '=', 'posted'), ]) + if rec.sale_order_ids: + so_records = rec.sale_order_ids + so_names = so_records.mapped('name') + domain = [ + ('journal_id', '=', 13), + ('state', '=', 'posted'), + ('sale_id', '=', False), + ('ref', 'ilike', 'selisih'), + ] + domain += ['|'] * (len(so_names) - 1) + for name in so_names: + domain.append(('ref', 'ilike', name)) + + misc = self.env['account.move'].search(domain) moves_ongkir = self.env['account.move'] if rec.sale_order_ids: diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 92efa3bd..031007ae 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -156,7 +156,7 @@ class SaleOrder(models.Model): total_margin_excl_third_party = fields.Float('Before Margin', help="Before Margin in Sales Order Header") approval_status = fields.Selection([ - ('pengajuan0', 'Approval Team Sales'), + ('pengajuan0', 'Approval Leader Team Sales'), ('pengajuan1', 'Approval Manager'), ('pengajuan2', 'Approval Pimpinan'), ('approved', 'Approved'), @@ -2391,12 +2391,15 @@ class SaleOrder(models.Model): self.check_credit_limit() self.check_limit_so_to_invoice() order.approval_status = 'pengajuan0' - order.message_post(body="Mengajukan approval ke Team Sales_") + order.message_post(body="Mengajukan approval ke Leader Team Sales_") + return self._create_approval_notification('Team Sales') + elif order._requires_approval_team_sales(): + self.check_product_bom() + self.check_credit_limit() + self.check_limit_so_to_invoice() + order.approval_status = 'pengajuan0' + order.message_post(body="Mengajukan approval ke Leader Team Sales") return self._create_approval_notification('Team Sales') - elif order._requires_approval_margin_leader(): - order.approval_status = 'pengajuan2' - order.message_post(body="Mengajukan approval ke Pimpinan") - return self._create_approval_notification('Pimpinan') elif order._requires_approval_margin_manager(): self.check_product_bom() self.check_credit_limit() @@ -2404,13 +2407,11 @@ class SaleOrder(models.Model): order.approval_status = 'pengajuan1' order.message_post(body="Mengajukan approval ke Sales Manager") return self._create_approval_notification('Sales Manager') - elif order._requires_approval_team_sales(): - self.check_product_bom() - self.check_credit_limit() - self.check_limit_so_to_invoice() - order.approval_status = 'pengajuan0' - order.message_post(body="Mengajukan approval ke Team Sales") - return self._create_approval_notification('Team Sales') + elif order._requires_approval_margin_leader(): + order.approval_status = 'pengajuan2' + order.message_post(body="Mengajukan approval ke Pimpinan") + return self._create_approval_notification('Pimpinan') + # elif value_trigger: # self.check_product_bom() # self.check_credit_limit() @@ -2685,18 +2686,19 @@ class SaleOrder(models.Model): value_trigger = order._requires_approval_by_value() if value_trigger: order.approval_status = 'pengajuan0' - order.message_post(body="Mengajukan approval ke Team Sales") + order.message_post(body="Mengajukan approval ke Leader Team Sales") return self._create_approval_notification('Team Sales') - elif order._requires_approval_margin_leader(): - order.approval_status = 'pengajuan2' - return self._create_approval_notification('Pimpinan') - elif order._requires_approval_margin_manager(): - order.approval_status = 'pengajuan1' - return self._create_approval_notification('Sales Manager') elif value_trigger or order._requires_approval_team_sales(): order.approval_status = 'pengajuan0' - order.message_post(body="Mengajukan approval ke Team Sales") + order.message_post(body="Mengajukan approval ke Leader Team Sales") return self._create_approval_notification('Team Sales') + elif order._requires_approval_margin_manager(): + order.approval_status = 'pengajuan1' + return self._create_approval_notification('Sales Manager') + elif order._requires_approval_margin_leader(): + order.approval_status = 'pengajuan2' + return self._create_approval_notification('Pimpinan') + # elif value_trigger: # order.approval_status = 'pengajuan0' # order.message_post(body="Mengajukan approval ke Team Sales (Total SO > 50jt)") diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py index 1ee10679..9038dd28 100644 --- a/indoteknik_custom/models/tukar_guling_po.py +++ b/indoteknik_custom/models/tukar_guling_po.py @@ -533,7 +533,7 @@ class TukarGulingPO(models.Model): ('state', '=', 'done'), ('picking_type_id.id', '=', 75) ]) - if self.state == 'aproved' and total_put > 0 and put == total_put: + if self.state == 'approved' and total_put > 0 and put == total_put: self.state = 'done' |
