diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2026-02-02 14:30:25 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2026-02-02 14:30:25 +0700 |
| commit | 18f978648362e8d9d5ed447d89bf1e969894b237 (patch) | |
| tree | fb7b5fd158787e0ec8eb9655cba1f43df1366754 | |
| parent | 2086d9f4540d3453cb2179560253769491aa0153 (diff) | |
push
| -rwxr-xr-x | fixco_custom/models/__init__.py | 3 | ||||
| -rw-r--r-- | fixco_custom/models/account_asset.py | 130 | ||||
| -rwxr-xr-x | fixco_custom/models/stock_picking.py | 23 | ||||
| -rw-r--r-- | fixco_custom/models/update_depreciation_move_wizard.py | 42 | ||||
| -rwxr-xr-x | fixco_custom/views/res_partner.xml | 5 | ||||
| -rwxr-xr-x | fixco_custom/views/stock_picking.xml | 2 |
6 files changed, 190 insertions, 15 deletions
diff --git a/fixco_custom/models/__init__.py b/fixco_custom/models/__init__.py index f7559c8..94954eb 100755 --- a/fixco_custom/models/__init__.py +++ b/fixco_custom/models/__init__.py @@ -40,4 +40,5 @@ from . import product_supplierinfo from . import queue_job from . import purchase_order_multi_bills from . import account_payment -from . import stock_location
\ No newline at end of file +from . import stock_location +from . import account_asset diff --git a/fixco_custom/models/account_asset.py b/fixco_custom/models/account_asset.py new file mode 100644 index 0000000..fb62488 --- /dev/null +++ b/fixco_custom/models/account_asset.py @@ -0,0 +1,130 @@ +import calendar +from datetime import date, datetime + +from dateutil.relativedelta import relativedelta + +from odoo import api, fields, models, _ +from odoo.exceptions import UserError, ValidationError +from odoo.tools import DEFAULT_SERVER_DATE_FORMAT as DF +from odoo.tools import float_compare, float_is_zero + + +class AccountAssetCategory(models.Model): + _inherit = 'account.asset.category' + +class AccountAssetAsset(models.Model): + _inherit = 'account.asset.asset' + +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() + created_moves.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/fixco_custom/models/stock_picking.py b/fixco_custom/models/stock_picking.py index 222c344..0f34a05 100755 --- a/fixco_custom/models/stock_picking.py +++ b/fixco_custom/models/stock_picking.py @@ -16,6 +16,7 @@ import time import logging import re from hashlib import sha256 +from odoo.tools.float_utils import float_compare _logger = logging.getLogger(__name__) @@ -68,6 +69,28 @@ class StockPicking(models.Model): list_product = fields.Char(string='List Product') is_dispatched = fields.Boolean(string='Is Dispatched', default=False, compute='_compute_is_dispatched', readonly=True) date_canceled = fields.Datetime(string='Date Canceled', tracking=True) + full_reserved = fields.Boolean(string='Full Reserved', default=False) + + def check_qty_reserved(self): + pickings = self.env['stock.picking'].search([ + ('state', '=', 'assigned'), + ('picking_type_code', '=', 'outgoing'), + ('name', 'ilike', 'BU/OUT'), + ('origin', 'ilike', 'SO/'), + ]) + + for picking in pickings: + moves = picking.move_ids_without_package + + picking.full_reserved = bool(moves) and all( + float_compare( + line.product_uom_qty, + line.forecast_availability, + precision_rounding=line.product_uom.rounding + ) == 0 + for line in moves + ) + def action_cancel(self): for picking in self: diff --git a/fixco_custom/models/update_depreciation_move_wizard.py b/fixco_custom/models/update_depreciation_move_wizard.py index 094494b..7d465f1 100644 --- a/fixco_custom/models/update_depreciation_move_wizard.py +++ b/fixco_custom/models/update_depreciation_move_wizard.py @@ -7,26 +7,42 @@ class UpdateDepreciationMoveWizard(models.TransientModel): target_date = fields.Date(string="Tanggal Depresiasi", required=True) - def action_update_move_check(self): - lines = self.env['account.asset.depreciation.line'].search([ - ('depreciation_date', '=', self.target_date), - ]) - if not lines: - raise UserError("Tidak ada baris depresiasi dengan tanggal tersebut.") + # def action_update_move_check(self): + # lines = self.env['account.asset.depreciation.line'].search([ + # ('depreciation_date', '=', self.target_date), + # ]) + # if not lines: + # raise UserError("Tidak ada baris depresiasi dengan tanggal tersebut.") + + # updated_count = 0 + # for line in lines: + # if not line.move_check: + # line.move_check = True + # line.move_posted_check = True + # updated_count += 1 - updated_count = 0 - for line in lines: - if not line.move_check: - line.move_check = True - updated_count += 1 + # return { + # 'type': 'ir.actions.client', + # 'tag': 'display_notification', + # 'params': { + # 'title': 'Update Selesai', + # 'message': f'{updated_count} baris berhasil di-update.', + # 'type': 'success', + # 'sticky': False, + # } + # } + + def action_update_move_check(self): + assets = self.env['account.asset.asset'] + assets.compute_generated_entries(self.target_date) return { 'type': 'ir.actions.client', 'tag': 'display_notification', 'params': { 'title': 'Update Selesai', - 'message': f'{updated_count} baris berhasil di-update.', + 'message': 'Depresiasi berhasil di-update.', 'type': 'success', 'sticky': False, } - } + }
\ No newline at end of file diff --git a/fixco_custom/views/res_partner.xml b/fixco_custom/views/res_partner.xml index 1f11a50..dc36872 100755 --- a/fixco_custom/views/res_partner.xml +++ b/fixco_custom/views/res_partner.xml @@ -15,9 +15,12 @@ <field name="customer_type" required="1"/> </field> <field name="vat" position="after"> - <field name="sppkp"/> + <field name="sppkp" required="1"/> <field name="nitku"/> </field> + <field name="vat" position="attributes"> + <attribute name="required">1</attribute> + </field> <group name="purchase" position="inside"> <field name="tax_id" domain="[('type_tax_use','=','purchase')]"/> </group> diff --git a/fixco_custom/views/stock_picking.xml b/fixco_custom/views/stock_picking.xml index 11a2dc7..4ac76fe 100755 --- a/fixco_custom/views/stock_picking.xml +++ b/fixco_custom/views/stock_picking.xml @@ -16,6 +16,7 @@ <field name="shipment_group_id" optional="hide"/> <field name="is_dispatched" optional="hide"/> <field name="date_canceled" optional="hide"/> + <field name="full_reserved" optional="hide"/> </field> </field> </record> @@ -73,6 +74,7 @@ <field name="location_id" position="after"> <field name="carrier"/> + <field name="full_reserved"/> <field name="shipment_group_id"/> <field name="number_soo"/> <field name="type_sku"/> |
