summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2022-08-31 15:17:40 +0700
committerIT Fixcomart <it@fixcomart.co.id>2022-08-31 15:17:40 +0700
commit57f87cc1da6243d17cba04f9d575f4ca4b836f26 (patch)
treeb3f8dab98d11c35b28a4ba2b280ff6df4d237f63
parent69b4bef9770aaaefd40361acb9ca2b3974e163d5 (diff)
Internal use to account.move (journal)
-rwxr-xr-xindoteknik_custom/__manifest__.py3
-rwxr-xr-xindoteknik_custom/models/__init__.py3
-rw-r--r--indoteknik_custom/models/stock_move.py176
-rw-r--r--indoteknik_custom/models/stock_picking.py24
-rw-r--r--indoteknik_custom/models/stock_picking_type.py6
-rw-r--r--indoteknik_custom/views/ir_sequence.xml12
-rw-r--r--indoteknik_custom/views/stock_location.xml8
-rw-r--r--indoteknik_custom/views/stock_picking.xml23
-rw-r--r--indoteknik_custom/views/stock_picking_type.xml29
9 files changed, 95 insertions, 189 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py
index c390a7a2..e590df34 100755
--- a/indoteknik_custom/__manifest__.py
+++ b/indoteknik_custom/__manifest__.py
@@ -32,6 +32,9 @@
'views/crm_lead.xml',
'views/sale_order.xml',
'views/account_asset_views.xml',
+ 'views/ir_sequence.xml',
+ 'views/stock_location.xml',
+ 'views/stock_picking.xml',
'views/stock_picking_type.xml',
'report/report.xml',
'report/report_banner_banner.xml',
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")
diff --git a/indoteknik_custom/views/ir_sequence.xml b/indoteknik_custom/views/ir_sequence.xml
new file mode 100644
index 00000000..9e057c0d
--- /dev/null
+++ b/indoteknik_custom/views/ir_sequence.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<odoo>
+ <record id="sequence_internal_use" model="ir.sequence">
+ <field name="name">Internal Use</field>
+ <field name="code">internal.use</field>
+ <field name="active">TRUE</field>
+ <field name="prefix">IU/%(year)s/</field>
+ <field name="padding">5</field>
+ <field name="number_next">1</field>
+ <field name="number_increment">1</field>
+ </record>
+</odoo> \ No newline at end of file
diff --git a/indoteknik_custom/views/stock_location.xml b/indoteknik_custom/views/stock_location.xml
new file mode 100644
index 00000000..82ab2bc5
--- /dev/null
+++ b/indoteknik_custom/views/stock_location.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<odoo>
+ <record id="stock_location_internal_use" model="stock.location">
+ <field name="name">Internal Use</field>
+ <field name="location_id">3</field>
+ <field name="usage">inventory</field>
+ </record>
+</odoo> \ No newline at end of file
diff --git a/indoteknik_custom/views/stock_picking.xml b/indoteknik_custom/views/stock_picking.xml
new file mode 100644
index 00000000..d2c1b26f
--- /dev/null
+++ b/indoteknik_custom/views/stock_picking.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<odoo>
+ <data>
+ <record id="stock_picking_form_view_inherit" model="ir.ui.view">
+ <field name="name">Stock Picking</field>
+ <field name="model">stock.picking</field>
+ <field name="inherit_id" ref="stock.view_picking_form"/>
+ <field name="arch" type="xml">
+ <field name="backorder_id" position="after">
+ <field name="is_internal_use"
+ string="Internal Use"
+ type="object"
+ attrs="{'readonly': True}"
+ force_save="1"
+ />
+ </field>
+ <field name="origin" position="after">
+ <field name="account_id"/>
+ </field>
+ </field>
+ </record>
+ </data>
+</odoo> \ No newline at end of file
diff --git a/indoteknik_custom/views/stock_picking_type.xml b/indoteknik_custom/views/stock_picking_type.xml
index dfc74cad..deb6d112 100644
--- a/indoteknik_custom/views/stock_picking_type.xml
+++ b/indoteknik_custom/views/stock_picking_type.xml
@@ -1,6 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<data>
+ <record id="internal_use_operation_type" model="stock.picking.type">
+ <field name="name">Internal Use</field>
+ <field name="sequence_id" ref="sequence_internal_use"/>
+ <field name="warehouse_id">2</field>
+ <field name="is_internal_use">TRUE</field>
+ <field name="code">outgoing</field>
+ <field name="show_operations">TRUE</field>
+ <field name="return_picking_type_id">10</field>
+ <field name="default_location_src_id">18</field>
+ <field name="default_location_dest_id" ref="stock_location_internal_use"/>
+ </record>
+
<record id="stock_picking_type_form_view_inherit" model="ir.ui.view">
<field name="name">Stock Picking Type</field>
<field name="model">stock.picking.type</field>
@@ -15,21 +27,4 @@
</field>
</record>
</data>
- <data>
- <record id="stock_picking_form_view_inherit" model="ir.ui.view">
- <field name="name">Stock Picking</field>
- <field name="model">stock.picking</field>
- <field name="inherit_id" ref="stock.view_picking_form"/>
- <field name="arch" type="xml">
- <field name="backorder_id" position="after">
- <field name="is_internal_use"
- string="Internal Use"
- type="object"
- attrs="{'readonly': True}"
- force_save="1"
- />
- </field>
- </field>
- </record>
- </data>
</odoo> \ No newline at end of file