Skip to content

Commit

Permalink
[ADD] stock_valuation_layer_total_value: add to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Juany Davila authored and ChrisOForgeFlow committed Nov 1, 2023
1 parent 75f49f2 commit 23e007f
Show file tree
Hide file tree
Showing 11 changed files with 269 additions and 0 deletions.
85 changes: 85 additions & 0 deletions stock_valuation_layer_total_value/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
====================
Stock Secondary Unit
====================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
:target: https://odoo-community.org/page/development-status
:alt: Production/Stable
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_secondary_unit
:alt: OCA/stock-logistics-warehouse
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-14-0/stock-logistics-warehouse-14-0-stock_secondary_unit
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/153/14.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

This module shows the value of the original valuation layer after doing
a landed cost.

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module you need to:

1.- Generate a stock valuation layer (ex: create a purchase of the product)
2.- Generate another valuation layer that is linked to the first one (This can be done using landed cost)
3.- Now you have on the original valuation the original cost and the updated cost (the one generated on the second valuation)


Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-warehouse/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_secondary_unit%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* ForgeFlow

Contributors
~~~~~~~~~~~~

* Jordi Ballester <[email protected]>
* Juany Davila <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_secondary_unit>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions stock_valuation_layer_total_value/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import models
18 changes: 18 additions & 0 deletions stock_valuation_layer_total_value/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2022 ForgeFlow
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Stock Valuation Layer Total Value",
"summary": "Show total value on tree and form view",
"version": "14.0.0.0.0",
"development_status": "Production/Stable",
"category": "stock",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"author": "Forgeflow, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["stock_account"],
"data": [
"views/stock_valuation_layer.xml",
],
}
2 changes: 2 additions & 0 deletions stock_valuation_layer_total_value/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import stock_valuation_layer
35 changes: 35 additions & 0 deletions stock_valuation_layer_total_value/models/stock_valuation_layer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2022 ForgeFlow
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models


class StockValuationLayer(models.Model):
_inherit = "stock.valuation.layer"

total_value_with_additional_costs = fields.Float(
string="Total value (with additional costs)",
compute="_compute_original_layer_values",
help="This is the sum of the total value's layer and total value of child layers",
store=True,
)
unit_price_with_extra_cost = fields.Float(
string="New unit price (with additional costs)",
compute="_compute_original_layer_values",
help="This is the unit cost after the additional costs are added",
store=True,
)

@api.depends("stock_valuation_layer_ids")
def _compute_original_layer_values(self):
for rec in self:
if len(rec.stock_valuation_layer_ids):
children_value = sum(rec.stock_valuation_layer_ids.mapped("value"))
total_value = rec.value + children_value
new_unit_price = (
(total_value / rec.quantity) if rec.quantity else rec.unit_cost
)
else:
total_value = rec.value
new_unit_price = rec.unit_cost
rec.total_value_with_additional_costs = total_value
rec.unit_price_with_extra_cost = new_unit_price
2 changes: 2 additions & 0 deletions stock_valuation_layer_total_value/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Jordi Ballester <[email protected]>
* Juany Davila <[email protected]>
2 changes: 2 additions & 0 deletions stock_valuation_layer_total_value/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module shows the value of the original valuation layer after doing
a landed cost.
5 changes: 5 additions & 0 deletions stock_valuation_layer_total_value/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
To use this module you need to:

1.- Generate a stock valuation layer (ex: create a purchase of the product)
2.- Generate another valuation layer that is linked to the first one (This can be done using landed cost)
3.- Now you have on the original valuation the original cost and the updated cost (the one generated on the second valuation)
1 change: 1 addition & 0 deletions stock_valuation_layer_total_value/test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_stock_valuation_layer_total_value
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Copyright 2022 ForgeFlow
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.addons.stock_account.tests.test_anglo_saxon_valuation_reconciliation_common import (
ValuationReconciliationTestCommon,
)


class TestValuationLayerTotalValue(ValuationReconciliationTestCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.stock_account_product_categ = cls.env["product.category"].create(
{
"name": "Test category",
"property_valuation": "real_time",
"property_cost_method": "fifo",
"property_stock_valuation_account_id": cls.company_data[
"default_account_stock_valuation"
].id,
"property_stock_account_input_categ_id": cls.company_data[
"default_account_stock_in"
].id,
"property_stock_account_output_categ_id": cls.company_data[
"default_account_stock_out"
].id,
}
)
cls.product1 = cls.env["product.product"].create(
{
"name": "product1",
"type": "product",
"categ_id": cls.stock_account_product_categ.id,
}
)

def _make_in_move(self, product, quantity, unit_cost=None, create_picking=False):
"""Helper to create and validate a receipt move."""
unit_cost = unit_cost or product.standard_price
in_move = self.env["stock.move"].create(
{
"name": "in %s units @ %s per unit" % (str(quantity), str(unit_cost)),
"product_id": product.id,
"location_id": self.env.ref("stock.stock_location_suppliers").id,
"location_dest_id": self.company_data[
"default_warehouse"
].lot_stock_id.id,
"product_uom": self.env.ref("uom.product_uom_unit").id,
"product_uom_qty": quantity,
"price_unit": unit_cost,
"picking_type_id": self.company_data["default_warehouse"].in_type_id.id,
}
)

if create_picking:
picking = self.env["stock.picking"].create(
{
"picking_type_id": in_move.picking_type_id.id,
"location_id": in_move.location_id.id,
"location_dest_id": in_move.location_dest_id.id,
}
)
in_move.write({"picking_id": picking.id})

in_move._action_confirm()
in_move._action_assign()
in_move.move_line_ids.qty_done = quantity
in_move._action_done()

return in_move.with_context(svl=True)

def test_valuation_layer_values(self):
move1 = self._make_in_move(self.product1, 10, unit_cost=10, create_picking=True)
move2 = self._make_in_move(self.product1, 5, unit_cost=15, create_picking=True)
original_svl = move1.stock_valuation_layer_ids
new_svl = move2.stock_valuation_layer_ids
original_svl.write({"stock_valuation_layer_ids": [(4, new_svl.id)]})
self.assertEqual(
original_svl.total_value_with_additional_costs,
original_svl.total_value_with_additional_costs + new_svl.value,
)
self.assertEqual(
original_svl.unit_price_with_extra_cost,
original_svl.total_value_with_additional_costs / original_svl.quantity,
)
33 changes: 33 additions & 0 deletions stock_valuation_layer_total_value/views/stock_valuation_layer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2022 ForgeFlow
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="stock_valuation_layer_form" model="ir.ui.view">
<field name="name">Stock Valuation Layer</field>
<field name="model">stock.valuation.layer</field>
<field name="inherit_id" ref="stock_account.stock_valuation_layer_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='remaining_qty']" position="after">
<field name="total_value_with_additional_costs" />
<field name="unit_price_with_extra_cost" />
</xpath>
<xpath expr="//page[@name='other_info']" position="after">
<page string="Child Layers" name="child_layers">
<field name="stock_valuation_layer_ids" />
</page>
</xpath>
</field>
</record>

<record id="stock_valuation_layer_tree" model="ir.ui.view">
<field name="name">Stock Valuation Layer</field>
<field name="model">stock.valuation.layer</field>
<field name="inherit_id" ref="stock_account.stock_valuation_layer_tree" />
<field name="arch" type="xml">
<xpath expr="//field[@name='value']" position="after">
<field name="total_value_with_additional_costs" optional="True" />
<field name="unit_price_with_extra_cost" optional="True" />
</xpath>
</field>
</record>
</odoo>

0 comments on commit 23e007f

Please sign in to comment.