mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
fixup! [REF] Split valuation accounts on locations
This commit is contained in:
@@ -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})
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
<field name="inherit_id" ref="stock.view_location_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//group[@name='localization']" position="after">
|
||||
<group name="internal_valuation" string="Accounting Information (internal)">
|
||||
<group name="internal_valuation" string="Accounting Information (internal)"
|
||||
attrs="{'invisible': [('usage', '!=', 'internal')]}">
|
||||
<field name="force_accounting_entries"/>
|
||||
<field name="valuation_in_internal_account_id"
|
||||
attrs="{'invisible': [('force_accounting_entries', '=', False)]}"/>
|
||||
|
||||
Reference in New Issue
Block a user