diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2022-08-31 15:17:40 +0700 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2022-08-31 15:17:40 +0700 |
| commit | 57f87cc1da6243d17cba04f9d575f4ca4b836f26 (patch) | |
| tree | b3f8dab98d11c35b28a4ba2b280ff6df4d237f63 /indoteknik_custom/models | |
| parent | 69b4bef9770aaaefd40361acb9ca2b3974e163d5 (diff) | |
Internal use to account.move (journal)
Diffstat (limited to 'indoteknik_custom/models')
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 3 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_move.py | 176 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 24 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking_type.py | 6 |
4 files changed, 37 insertions, 172 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index a81306b6..c871a340 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -20,4 +20,5 @@ from . import sale_monitoring from . import account_move from . import account_asset from . import stock_move -from . import stock_picking
\ No newline at end of file +from . import stock_picking +from . import stock_picking_type diff --git a/indoteknik_custom/models/stock_move.py b/indoteknik_custom/models/stock_move.py index 3804198a..c2786762 100644 --- a/indoteknik_custom/models/stock_move.py +++ b/indoteknik_custom/models/stock_move.py @@ -1,155 +1,33 @@ -from odoo import fields, models, api -from odoo.exceptions import UserError +from odoo import fields, models class StockMove(models.Model): _inherit = 'stock.move' - def _account_entry_move(self, qty, description, svl_id, cost): - """ Accounting Valuation Entries """ + def _create_account_move_line(self, credit_account_id, debit_account_id, journal_id, qty, description, svl_id, cost): self.ensure_one() - if self.product_id.type != 'product': - # no stock valuation for consumable products - return False - if self.restrict_partner_id: - # if the move isn't owned by the company, we don't make any valuation - return False - - company_from = self._is_out() and self.mapped('move_line_ids.location_id.company_id') or False - company_to = self._is_in() and self.mapped('move_line_ids.location_dest_id.company_id') or False - - journal_id, acc_src, acc_dest, acc_valuation = self._get_accounting_data_for_valuation() - # Create Journal Entry for products arriving in the company; in case of routes making the link between several - # warehouse of the same company, the transit location belongs to this company, so we don't need to create accounting entries - if self._is_in(): - if self._is_returned(valued_type='in'): - self.with_company(company_to)._create_account_move_line(acc_dest, acc_valuation, journal_id, qty, - description, svl_id, cost) - else: - self.with_company(company_to)._create_account_move_line(acc_src, acc_valuation, journal_id, qty, - description, svl_id, cost) - - # Create Journal Entry for products leaving the company - if self._is_out(): - cost = -1 * cost - if self._is_returned(valued_type='out'): - self.with_company(company_from)._create_account_move_line(acc_valuation, acc_src, journal_id, qty, - description, svl_id, cost) - else: # custom here for ppn internal use, acc_dest = 538, acc_valuation = 400, charge from virtual location and persediaan - self.with_company(company_from)._create_account_move_line(acc_valuation, acc_dest, journal_id, qty, - description, svl_id, cost) - self.with_company(company_from)._create_account_move_line(440,538,journal_id,qty,description,svl_id,cost * (11 / 100)) - - if self.company_id.anglo_saxon_accounting: - # Creates an account entry from stock_input to stock_output on a dropship move. https://github.com/odoo/odoo/issues/12687 - if self._is_dropshipped(): - if cost > 0: - self.with_company(self.company_id)._create_account_move_line(acc_src, acc_valuation, journal_id, - qty, description, svl_id, cost) - else: - cost = -1 * cost - self.with_company(self.company_id)._create_account_move_line(acc_valuation, acc_dest, journal_id, - qty, description, svl_id, cost) - elif self._is_dropshipped_returned(): - if cost > 0: - self.with_company(self.company_id)._create_account_move_line(acc_valuation, acc_src, journal_id, - qty, description, svl_id, cost) - else: - cost = -1 * cost - self.with_company(self.company_id)._create_account_move_line(acc_dest, acc_valuation, journal_id, - qty, description, svl_id, cost) - - if self.company_id.anglo_saxon_accounting: - # Eventually reconcile together the invoice and valuation accounting entries on the stock interim accounts - self._get_related_invoices()._stock_account_anglo_saxon_reconcile_valuation(product=self.product_id) - - # def _create_account_move_line(self, credit_account_id, debit_account_id, journal_id, qty, description, svl_id, - # cost): - # self.ensure_one() - # AccountMove = self.env['account.move'].with_context(default_journal_id=journal_id) - # - # move_lines = self._prepare_account_move_line(qty, cost, credit_account_id, debit_account_id, description) - # if move_lines: - # date = self._context.get('force_period_date', fields.Date.context_today(self)) - # new_account_move = AccountMove.sudo().create({ - # 'journal_id': journal_id, - # 'line_ids': move_lines, - # 'date': date, - # 'ref': description, - # 'stock_move_id': self.id, - # 'stock_valuation_layer_ids': [(6, None, [svl_id])], - # 'move_type': 'entry', - # }) - # new_account_move._post() - # - # def _prepare_account_move_line(self, qty, cost, credit_account_id, debit_account_id, description): - # """ - # Generate the account.move.line values to post to track the stock valuation difference due to the - # processing of the given quant. - # """ - # self.ensure_one() - # - # # the standard_price of the product may be in another decimal precision, or not compatible with the coinage of - # # the company currency... so we need to use round() before creating the accounting entries. - # debit_value = self.company_id.currency_id.round(cost) - # credit_value = debit_value - # - # valuation_partner_id = self._get_partner_id_for_valuation_lines() - # res = [(0, 0, line_vals) for line_vals in - # self._generate_valuation_lines_data(valuation_partner_id, qty, debit_value, credit_value, - # debit_account_id, credit_account_id, description).values()] - # - # return res - # - # def _generate_valuation_lines_data(self, partner_id, qty, debit_value, credit_value, debit_account_id, - # credit_account_id, description): - # # This method returns a dictionary to provide an easy extension hook to modify the valuation lines (see purchase for an example) - # self.ensure_one() - # debit_line_vals = { - # 'name': description, - # 'product_id': self.product_id.id, - # 'quantity': qty, - # 'product_uom_id': self.product_id.uom_id.id, - # 'ref': description, - # 'partner_id': partner_id, - # 'debit': debit_value if debit_value > 0 else 0, - # 'credit': -debit_value if debit_value < 0 else 0, - # 'account_id': debit_account_id, - # } - # - # credit_line_vals = { - # 'name': description, - # 'product_id': self.product_id.id, - # 'quantity': qty, - # 'product_uom_id': self.product_id.uom_id.id, - # 'ref': description, - # 'partner_id': partner_id, - # 'credit': credit_value if credit_value > 0 else 0, - # 'debit': -credit_value if credit_value < 0 else 0, - # 'account_id': credit_account_id, - # } - # - # rslt = {'credit_line_vals': credit_line_vals, 'debit_line_vals': debit_line_vals} - # if credit_value != debit_value: - # # for supplier returns of product in average costing method, in anglo saxon mode - # diff_amount = debit_value - credit_value - # price_diff_account = self.product_id.property_account_creditor_price_difference - # - # if not price_diff_account: - # price_diff_account = self.product_id.categ_id.property_account_creditor_price_difference_categ - # if not price_diff_account: - # raise UserError( - # _('Configuration error. Please configure the price difference account on the product or its category to process this operation.')) - # - # rslt['price_diff_line_vals'] = { - # 'name': self.name, - # 'product_id': self.product_id.id, - # 'quantity': qty, - # 'product_uom_id': self.product_id.uom_id.id, - # 'ref': description, - # 'partner_id': partner_id, - # 'credit': diff_amount > 0 and diff_amount or 0, - # 'debit': diff_amount < 0 and -diff_amount or 0, - # 'account_id': price_diff_account.id, - # } - # return rslt + if self.picking_id.is_internal_use: + AccountMove = self.env['account.move'].with_context(default_journal_id=journal_id) + + # 538 is static id for "Biaya Umum Lain-Lain" on account.account model + # 440 is static id for "PPN Keluaran" on account.account model + debit_account_id = self.picking_id.account_id.id if self.picking_id.account_id.id else 538 + + tax = cost * (11 / 100) + move_lines = self._prepare_account_move_line(qty, cost, credit_account_id, debit_account_id, description) + move_lines += self._prepare_account_move_line(qty, tax, 440, debit_account_id, description) + + if move_lines: + date = self._context.get('force_period_date', fields.Date.context_today(self)) + new_account_move = AccountMove.sudo().create({ + 'journal_id': journal_id, + 'line_ids': move_lines, + 'date': date, + 'ref': description, + 'stock_move_id': self.id, + 'stock_valuation_layer_ids': [(6, None, [svl_id])], + 'move_type': 'entry', + }) + new_account_move._post() + return True + return super(StockMove, self)._create_account_move_line(credit_account_id, debit_account_id, journal_id, qty, description, svl_id, cost) diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 1d644090..9b5f0036 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -1,32 +1,12 @@ from odoo import fields, models, api -class StockPickingType(models.Model): - _inherit = 'stock.picking.type' - is_internal_use = fields.Boolean(string="Internal Use") - - class StockPicking(models.Model): _inherit = 'stock.picking' is_internal_use = fields.Boolean('Internal Use', help="flag which is internal use or not") + account_id = fields.Many2one('account.account', string="Account") @api.onchange('picking_type_id') def _onchange_operation_type(self): - test3 = self.picking_type_id.is_internal_use - self.is_internal_use = True + self.is_internal_use = self.picking_type_id.is_internal_use return - # for stock_picking in self: - # test = stock_picking.picking_type_id.is_internal_use - # stock_picking.is_internal_use = stock_picking.picking_type_id.is_internal_use - - # @api.model - # def create(self, vals): - # res = super(StockPicking, self).create(vals) - # test3 = self.picking_type_id.is_internal_use - # self.is_internal_use = True - # return res - - # def _compute_internal_use(self): - # for stock_picking in self: - # test = stock_picking.picking_type_id.is_internal_use - # stock_picking.is_internal_use = stock_picking.picking_type_id.is_internal_use diff --git a/indoteknik_custom/models/stock_picking_type.py b/indoteknik_custom/models/stock_picking_type.py new file mode 100644 index 00000000..064946ed --- /dev/null +++ b/indoteknik_custom/models/stock_picking_type.py @@ -0,0 +1,6 @@ +from odoo import fields, models + + +class StockPickingType(models.Model): + _inherit = 'stock.picking.type' + is_internal_use = fields.Boolean(string="Internal Use") |
