-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
718f4c3
commit b7bb5c4
Showing
17 changed files
with
347 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../stock_move_value |
File renamed without changes.
1 change: 0 additions & 1 deletion
1
setup/stock_return_value_discrepancy/odoo/addons/stock_return_value_discrepancy
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
..._return_value_discrepancy/__manifest__.py → stock_move_value/__manifest__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * stock_move_value | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 16.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-07-13 10:23+0000\n" | ||
"PO-Revision-Date: 2024-07-13 10:23+0000\n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: stock_move_value | ||
#: model:ir.model.fields,help:stock_move_value.field_stock_move__move_origin_value | ||
msgid "" | ||
"Corresponding value of the origin move as of the the time move was done. " | ||
"Only updated for vendor returns." | ||
msgstr "" | ||
"在庫移動完了時点での元在庫移動の数量見合い評価額です。仕入返品のときのみ更新されます。" | ||
|
||
#. module: stock_move_value | ||
#: model:ir.model.fields,field_description:stock_move_value.field_stock_move__value_currency_id | ||
msgid "Currency" | ||
msgstr "通貨" | ||
|
||
#. module: stock_move_value | ||
#: model_terms:ir.ui.view,arch_db:stock_move_value.view_move_search_inherit | ||
msgid "Discrepancy Reviewed" | ||
msgstr "差額レビュー済" | ||
|
||
#. module: stock_move_value | ||
#: model:ir.model.fields,field_description:stock_move_value.field_stock_move__move_origin_value | ||
msgid "Move Origin Value" | ||
msgstr "元移動評価額" | ||
|
||
#. module: stock_move_value | ||
#: model:ir.model.fields,field_description:stock_move_value.field_stock_move__move_value | ||
msgid "Move Value" | ||
msgstr "移動評価額" | ||
|
||
#. module: stock_move_value | ||
#: model:ir.model.fields,help:stock_move_value.field_stock_move__value_discrepancy | ||
msgid "Move Value + Move Origin Value. Only updated for vendor returns." | ||
msgstr "移動評価額 + 元移動評価額。仕入返品のときのみ更新されます。" | ||
|
||
#. module: stock_move_value | ||
#: model_terms:ir.ui.view,arch_db:stock_move_value.view_move_search_inherit | ||
msgid "Return Value Discrepancy" | ||
msgstr "返品評価額差異" | ||
|
||
#. module: stock_move_value | ||
#: model:ir.model.fields,help:stock_move_value.field_stock_move__to_review_discrepancy | ||
msgid "" | ||
"Selected when Value Discrepancy is not zero. Users are expected to unselect " | ||
"it when review is done." | ||
msgstr "" | ||
"返品評価額差異があるときに選択されます。レビューが済みましたら選択を外してください。" | ||
|
||
#. module: stock_move_value | ||
#: model:ir.model,name:stock_move_value.model_stock_move | ||
msgid "Stock Move" | ||
msgstr "在庫移動" | ||
|
||
#. module: stock_move_value | ||
#: model_terms:ir.ui.view,arch_db:stock_move_value.view_move_tree | ||
#: model_terms:ir.ui.view,arch_db:stock_move_value.view_stock_move_form_inherit | ||
msgid "To Review" | ||
msgstr "要レビュー" | ||
|
||
#. module: stock_move_value | ||
#: model:ir.model.fields,field_description:stock_move_value.field_stock_move__to_review_discrepancy | ||
#: model_terms:ir.ui.view,arch_db:stock_move_value.view_move_search_inherit | ||
msgid "To Review Discrepancy" | ||
msgstr "要差異レビュー" | ||
|
||
#. module: stock_move_value | ||
#: model:ir.model.fields,field_description:stock_move_value.field_stock_move__value_discrepancy | ||
msgid "Value Discrepancy" | ||
msgstr "評価額差異" | ||
|
||
#. module: stock_move_value | ||
#: model:ir.model.fields,help:stock_move_value.field_stock_move__move_value | ||
msgid "" | ||
"Value of the move including related SVL values (i.e. price differences and " | ||
"landed costs)" | ||
msgstr "" | ||
"関連在庫評価レイヤー(価格差異や仕入諸掛によるもの)の金額を含む移動の評価額。" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Copyright 2024 Quartile (https://www.quartile.co) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from collections import defaultdict | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class StockMove(models.Model): | ||
_inherit = "stock.move" | ||
|
||
value_currency_id = fields.Many2one( | ||
"res.currency", related="company_id.currency_id" | ||
) | ||
move_value = fields.Monetary( | ||
compute="_compute_move_value", | ||
store=True, | ||
currency_field="value_currency_id", | ||
help="Value of the move including related SVL values (i.e. price differences " | ||
"and landed costs)", | ||
) | ||
move_origin_value = fields.Monetary( | ||
currency_field="value_currency_id", | ||
help="Corresponding value of the origin move as of the the time move was done. " | ||
"Only updated for vendor returns.", | ||
) | ||
value_discrepancy = fields.Monetary( | ||
currency_field="value_currency_id", | ||
help="Move Value + Move Origin Value. Only updated for vendor returns.", | ||
) | ||
to_review_discrepancy = fields.Boolean( | ||
help="Selected when Value Discrepancy is not zero. Users are expected to " | ||
"unselect it when review is done.", | ||
) | ||
|
||
@api.depends( | ||
"stock_valuation_layer_ids", | ||
"stock_valuation_layer_ids.stock_valuation_layer_ids", | ||
) | ||
def _compute_move_value(self): | ||
for move in self: | ||
# There can be multiple svls per move in case landed costs are entered | ||
move.move_value = sum(move.stock_valuation_layer_ids.mapped("value")) | ||
|
||
def _action_done(self, cancel_backorder=False): | ||
origin_values = defaultdict(dict) | ||
for move in self: | ||
if not move._is_out(): | ||
continue | ||
origin_move = move.origin_returned_move_id | ||
if not origin_move: | ||
continue | ||
# There should be only one record | ||
origin_svls = origin_move.stock_valuation_layer_ids.filtered( | ||
lambda r: r.quantity > 0 | ||
) | ||
origin_values[move.id] = { | ||
"remaining_qty": origin_svls.remaining_qty, | ||
"remaining_value": origin_svls.remaining_value, | ||
} | ||
moves = super()._action_done(cancel_backorder) | ||
for move in moves: | ||
move.move_value = sum(move.stock_valuation_layer_ids.mapped("value")) | ||
if not move._is_out() or not move.origin_returned_move_id: | ||
continue | ||
move.move_origin_value = ( | ||
origin_values[move.id]["remaining_value"] | ||
* move.product_qty | ||
/ origin_values[move.id]["remaining_qty"] | ||
) | ||
move.value_discrepancy = move.move_origin_value + move.move_value | ||
if move.value_discrepancy != 0.0: | ||
move.to_review_discrepancy = True | ||
return moves |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
This module adds value fields to the stock move model, to add visivility of how the move | ||
has affected the stock valuation. | ||
|
||
- **Move Value**: Value of the move including related SVL values (i.e. price differences | ||
and landed costs) | ||
- **Move Origin Value**: Corresponding value of the origin move as of the the time move | ||
was done. Only updated for vendor returns. | ||
- **Value Discrepancy**: Move Value + Move Origin Value. Only updated for vendor | ||
returns. | ||
- **To Review**: Selected when Value Discrepancy is not zero. Users are expected to | ||
unselect it when review is done. |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_stock_move_value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Copyright 2024 Quartile Limited | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
|
||
from odoo.tests.common import Form, TransactionCase | ||
|
||
|
||
class TestStockReturnValueDiscrepancy(TransactionCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
product_category = cls.env["product.category"].create( | ||
{ | ||
"name": "test category", | ||
"property_cost_method": "average", | ||
"property_valuation": "manual_periodic", | ||
} | ||
) | ||
cls.product = cls.env["product.product"].create( | ||
{"name": "test product", "categ_id": product_category.id} | ||
) | ||
cls.location_stock = cls.env.ref("stock.stock_location_stock") | ||
cls.location_vendor = cls.env.ref("stock.stock_location_suppliers") | ||
cls.picking_in = cls.env["stock.picking"].create( | ||
{ | ||
"picking_type_id": cls.env.ref("stock.picking_type_in").id, | ||
"location_id": cls.location_vendor.id, | ||
"location_dest_id": cls.location_stock.id, | ||
} | ||
) | ||
cls.move = cls.env["stock.move"].create( | ||
{ | ||
"name": cls.product.name, | ||
"product_id": cls.product.id, | ||
"product_uom": cls.product.uom_id.id, | ||
"location_id": cls.location_vendor.id, | ||
"location_dest_id": cls.location_stock.id, | ||
"picking_id": cls.picking_in.id, | ||
"product_uom_qty": 10, | ||
"quantity_done": 10, | ||
} | ||
) | ||
|
||
def create_return_picking(self, origin_pick, returned_qty): | ||
stock_return_picking_form = Form( | ||
self.env["stock.return.picking"].with_context( | ||
active_ids=origin_pick.ids, | ||
active_id=origin_pick.id, | ||
active_model="stock.picking", | ||
) | ||
) | ||
return_modal = stock_return_picking_form.save() | ||
return_modal.product_return_moves.quantity = returned_qty | ||
return_modal.location_id = self.location_vendor.id | ||
return_action = return_modal.create_returns() | ||
picking = self.env["stock.picking"].browse(return_action["res_id"]) | ||
picking.move_ids[0].quantity_done = returned_qty | ||
return picking | ||
|
||
def test_picking_return_to_vendor(self): | ||
self.product.standard_price = 10.0 | ||
self.picking_in._action_done() | ||
self.assertEqual(self.move.move_value, 100.0) | ||
self.assertEqual(self.move.move_origin_value, 0.0) | ||
self.assertEqual(self.move.value_discrepancy, 0.0) | ||
self.assertFalse(self.move.to_review_discrepancy) | ||
# Return with no value discrepancy | ||
return_pick_1 = self.create_return_picking(self.picking_in, 2.0) | ||
return_pick_1._action_done() | ||
return_move_1 = return_pick_1.move_ids[0] | ||
self.assertEqual(return_move_1.move_value, -20.0) | ||
self.assertEqual(return_move_1.move_origin_value, 20.0) | ||
self.assertEqual(return_move_1.value_discrepancy, 0.0) | ||
self.assertFalse(return_move_1.to_review_discrepancy) | ||
# Return with value discrepancy | ||
self.product.standard_price = 30.0 | ||
return_pick_2 = self.create_return_picking(self.picking_in, 5.0) | ||
return_pick_2._action_done() | ||
return_move_2 = return_pick_2.move_ids[0] | ||
self.assertEqual(return_move_2.move_value, -150.0) | ||
self.assertEqual(return_move_2.move_origin_value, 50.0) | ||
self.assertEqual(return_move_2.value_discrepancy, -100.0) | ||
self.assertTrue(return_move_2.to_review_discrepancy) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
<record id="view_stock_move_form_inherit" model="ir.ui.view"> | ||
<field name="name">stock.move.form.inherit</field> | ||
<field name="model">stock.move</field> | ||
<field name="inherit_id" ref="stock.view_move_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//group[@name='main_grp_col2']" position="inside"> | ||
<field name="move_value" groups="account.group_account_invoice" /> | ||
<field | ||
name="move_origin_value" | ||
groups="account.group_account_invoice" | ||
/> | ||
<field | ||
name="value_discrepancy" | ||
groups="account.group_account_invoice" | ||
/> | ||
<field name="value_currency_id" invisible="1" /> | ||
<field | ||
name="to_review_discrepancy" | ||
string="To Review" | ||
widget="boolean_toggle" | ||
groups="account.group_account_invoice" | ||
/> | ||
</xpath> | ||
</field> | ||
</record> | ||
<record id="view_move_tree" model="ir.ui.view"> | ||
<field name="name">stock.move.tree</field> | ||
<field name="model">stock.move</field> | ||
<field name="inherit_id" ref="stock.view_move_tree" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//field[@name='company_id']" position="before"> | ||
<field | ||
name="move_value" | ||
groups="account.group_account_invoice" | ||
optional="show" | ||
/> | ||
<field | ||
name="move_origin_value" | ||
groups="account.group_account_invoice" | ||
optional="show" | ||
/> | ||
<field | ||
name="value_discrepancy" | ||
groups="account.group_account_invoice" | ||
optional="show" | ||
/> | ||
<field name="value_currency_id" invisible="1" /> | ||
<field | ||
name="to_review_discrepancy" | ||
string="To Review" | ||
widget="boolean_toggle" | ||
groups="account.group_account_invoice" | ||
optional="show" | ||
/> | ||
</xpath> | ||
</field> | ||
</record> | ||
<record id="view_move_search_inherit" model="ir.ui.view"> | ||
<field name="name">stock.move.search.inherit</field> | ||
<field name="model">stock.move</field> | ||
<field name="inherit_id" ref="stock.view_move_search" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//filter[@name='inventory']" position="after"> | ||
<separator /> | ||
<filter | ||
name="has_return_value_discrepancy" | ||
string="Return Value Discrepancy" | ||
domain="[('value_discrepancy','!=',0.0)]" | ||
/> | ||
<filter | ||
name="to_review_discrepancy" | ||
string="To Review Discrepancy" | ||
domain="[('to_review_discrepancy','=',True)]" | ||
/> | ||
<filter | ||
name="discrepancy_reviewed" | ||
string="Discrepancy Reviewed" | ||
domain="[('value_discrepancy','!=',0.0),('to_review_discrepancy','=',False)]" | ||
/> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |
Oops, something went wrong.