diff --git a/stock_account_internal_move/models/stock_location.py b/stock_account_internal_move/models/stock_location.py
index 2e61b40a1..70b37ce6f 100644
--- a/stock_account_internal_move/models/stock_location.py
+++ b/stock_account_internal_move/models/stock_location.py
@@ -1,6 +1,6 @@
# Copyright (C) 2018 by Camptocamp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-from odoo import _, fields, models
+from odoo import _, api, fields, models
class StockLocation(models.Model):
@@ -18,6 +18,12 @@ class StockLocation(models.Model):
)""",
_('You must provide a valuation in/out accounts'
' in order to force accounting entries.')),
+ ('force_accounting_entries_internal_only',
+ """check(
+ NOT force_accounting_entries
+ OR force_accounting_entries
+ AND usage = 'internal')""",
+ _('You cannot force accounting entries on a non-internal locations.')),
]
force_accounting_entries = fields.Boolean(
@@ -32,3 +38,9 @@ class StockLocation(models.Model):
comodel_name='account.account',
string='Stock Valuation Account (outgoing)',
)
+
+ @api.onchange('usage')
+ def _onchange_usage(self):
+ for location in self:
+ if location.usage != 'internal':
+ location.update({'force_accounting_entries': False})
diff --git a/stock_account_internal_move/models/stock_move.py b/stock_account_internal_move/models/stock_move.py
index af2d8b688..77ef0dca4 100644
--- a/stock_account_internal_move/models/stock_move.py
+++ b/stock_account_internal_move/models/stock_move.py
@@ -27,26 +27,29 @@ class StockMove(models.Model):
# done in _get_accounting_data_for_valuation?
product_valuation_accounts \
= move.product_id.product_tmpl_id.get_product_accounts()
- stock_journal_id, __, __, __ \
- = move._get_accounting_data_for_valuation()
+ stock_valuation = product_valuation_accounts.get('stock_valuation')
+ stock_journal = product_valuation_accounts.get('stock_journal')
# calculate move cost
# TODO: recheck if this part respects product valuation method
move.value = float_round(
value=move.product_id.standard_price * move.quantity_done,
- precision_rounding=self.company_id.currency_id.rounding,
+ precision_rounding=move.company_id.currency_id.rounding,
)
- if location_from.force_accounting_entries:
+ if location_from.force_accounting_entries \
+ and location_to.force_accounting_entries:
move._create_account_move_line(
location_from.valuation_out_internal_account_id.id,
- product_valuation_accounts.get('stock_valuation').id,
- stock_journal_id)
-
- if location_to.force_accounting_entries:
+ location_to.valuation_in_internal_account_id.id,
+ stock_journal.id)
+ elif location_from.force_accounting_entries:
+ move._create_account_move_line(
+ location_from.valuation_out_internal_account_id.id,
+ stock_valuation.id, stock_journal.id)
+ elif location_to.force_accounting_entries:
move._create_account_move_line(
product_valuation_accounts.get('stock_valuation').id,
- location_to.valuation_in_internal_account_id.id,
- stock_journal_id)
+ stock_valuation.id, stock_journal.id)
return res
diff --git a/stock_account_internal_move/views/stock_location.xml b/stock_account_internal_move/views/stock_location.xml
index 326094be2..229a1f75c 100644
--- a/stock_account_internal_move/views/stock_location.xml
+++ b/stock_account_internal_move/views/stock_location.xml
@@ -7,7 +7,8 @@
-
+