Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][ADD] Product Valuation #1141

Open
wants to merge 27 commits into
base: 15.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6a5ade5
Product Valuation
dhongu Dec 11, 2023
f21510b
Implement product valuation history and correct typos
dhongu Dec 18, 2023
44b811b
Add debit and credit fields to product valuation
dhongu Dec 18, 2023
0de53c9
Update product valuation with in/out quantities
dhongu Dec 18, 2023
79f6213
Merge branch '15.0' into 15.0-valuation
dhongu Dec 18, 2023
6ebb6fb
Add 'deltatech_valuation' to README.md
dhongu Dec 18, 2023
302bf26
Update product valuation view and model
dhongu Dec 18, 2023
7283578
Add initial and final fields & update historical calculations in prod…
dhongu Dec 20, 2023
3449cb5
Add uniqueness constraints and improve SQL queries
dhongu Dec 20, 2023
073e52c
Set 'date' field as required in product_valuation model
dhongu Dec 20, 2023
266092b
Add relativedelta to calculate end-of-month date
dhongu Dec 20, 2023
fa9b6d1
Refactor product valuation calculations in Deltatech module
dhongu Dec 20, 2023
d9669a4
Refactor and optimize SQL operations in product valuation
dhongu Dec 20, 2023
fdc27d8
Merge branch '15.0' into 15.0-valuation
dhongu Jan 2, 2024
fc0c8b1
update
dhongu Jan 3, 2024
2b49003
update
dhongu Jan 3, 2024
198b51e
fix
dhongu Jan 3, 2024
347964c
renuntare la coloanele de data si an
dhongu Jan 3, 2024
932e2ee
adaugare testscript
dhongu Jan 3, 2024
d36fd09
teste
dhongu Jan 3, 2024
4df077f
Merge branch '15.0' into 15.0-valuation
dhongu Jan 5, 2024
af4e1f4
update
dhongu Jan 11, 2024
9bc506f
update all
dhongu Jan 20, 2024
1064c2f
fix tests
dhongu Jan 20, 2024
480b665
fix
dhongu Jan 21, 2024
7bbb01f
fix
dhongu Jan 23, 2024
960ba45
fix
dhongu Jan 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ addon | version | maintainers | summary | price
[deltatech_stock_report](deltatech_stock_report/) | 15.0.1.0.1 | [![dhongu](https://github.com/dhongu.png?size=30px)](https://github.com/dhongu) | Report with positions from picking lists | Free
[deltatech_stock_reseller](deltatech_stock_reseller/) | 15.0.1.0.1 | [![dhongu](https://github.com/dhongu.png?size=30px)](https://github.com/dhongu) | Report report reseller | Free
[deltatech_stock_sn](deltatech_stock_sn/) | 15.0.1.0.0 | | Stock Serial Number | Free
[deltatech_stock_valuation](deltatech_stock_valuation/) | 15.0.0.0.1 | [![dhongu](https://github.com/dhongu.png?size=30px)](https://github.com/dhongu) | Product Stock Valuation | Free
[deltatech_test_system](deltatech_test_system/) | 15.0.0.0.3 | [![dhongu](https://github.com/dhongu.png?size=30px)](https://github.com/dhongu) | Utils | Free
[deltatech_tracking_2performant](deltatech_tracking_2performant/) | 15.0.1.0.0 | [![dhongu](https://github.com/dhongu.png?size=30px)](https://github.com/dhongu) | 2Performant tracking | Free
[deltatech_utils](deltatech_utils/) | 15.0.1.0.2 | [![dhongu](https://github.com/dhongu.png?size=30px)](https://github.com/dhongu) | Utils | Free
Expand Down
4 changes: 4 additions & 0 deletions deltatech_select_journal/tests/test_sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class TestSale(TransactionCase):
def setUp(self):
super().setUp()
self.partner_a = self.env["res.partner"].create({"name": "Test"})
currency_eur = self.env.ref("base.EUR")
currency_eur.write({"active": True})
currency_usd = self.env.ref("base.USD")
currency_usd.write({"active": True})

seller_ids = [(0, 0, {"name": self.partner_a.id})]
self.product_a = self.env["product.product"].create(
Expand Down
78 changes: 78 additions & 0 deletions deltatech_stock_valuation/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
=================
Product Valuation
=================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:33959730018c9387a7ec885775c0defca536f43dedde3733f43288f3066e2ffc
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/licence-OPL--1-blue.png
:target: https://www.odoo.com/documentation/master/legal/licenses.html
:alt: License: OPL-1
.. |badge3| image:: https://img.shields.io/badge/github-dhongu%2Fdeltatech-lightgray.png?logo=github
:target: https://github.com/dhongu/deltatech/tree/15.0/deltatech_stock_valuation
:alt: dhongu/deltatech

|badge1| |badge2| |badge3|

Features:



pentru inializare e necesar o actiune server cu urmatorul cod

.. code-block:: python

env["product.valuation"].recompute_all_amount()
env["product.valuation.history"].recompute_all_amount()

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/dhongu/deltatech/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/dhongu/deltatech/issues/new?body=module:%20deltatech_stock_valuation%0Aversion:%2015.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
~~~~~~~

* Terrabit
* Dorin Hongu

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

.. |maintainer-dhongu| image:: https://github.com/dhongu.png?size=40px
:target: https://github.com/dhongu
:alt: dhongu

Current maintainer:

|maintainer-dhongu|

This module is part of the `dhongu/deltatech <https://github.com/dhongu/deltatech/tree/15.0/deltatech_stock_valuation>`_ project on GitHub.

You are welcome to contribute.
6 changes: 6 additions & 0 deletions deltatech_stock_valuation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# © 2023 Deltatech
# Dorin Hongu <dhongu(@)gmail(.)com
# See README.rst file on addons root folder for license details


from . import models
27 changes: 27 additions & 0 deletions deltatech_stock_valuation/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# © 2023 Deltatech
# Dorin Hongu <dhongu(@)gmail(.)com
# See README.rst file on addons root folder for license details


{
"name": "Product Valuation",
"summary": "Product Stock Valuation",
"version": "15.0.0.0.1",
"author": "Terrabit, Dorin Hongu",
"website": "https://www.terrabit.ro",
"category": "Inventory/Inventory",
"depends": ["stock_account"],
"license": "OPL-1",
"data": [
"security/ir.model.access.csv",
"security/security.xml",
"views/valuation_area_view.xml",
"views/product_valuation_view.xml",
"views/account_account_view.xml",
"data/data.xml",
"views/res_config_settings_views.xml",
],
"images": ["static/description/main_screenshot.png"],
"development_status": "Alpha",
"maintainers": ["dhongu"],
}
15 changes: 15 additions & 0 deletions deltatech_stock_valuation/data/data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="action_product_valuation_history_recompute" model="ir.actions.server">
<field name="name">Recompute All Stock Valuation</field>
<field name="model_id" ref="base.model_ir_actions_server" />
<field name="state">code</field>
<field name="code">
env['product.valuation.history'].recompute_all_amount()
env['product.valuation'].recompute_all_amount()
</field>
</record>


</odoo>
17 changes: 17 additions & 0 deletions deltatech_stock_valuation/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# © 2023 Deltatech
# Dorin Hongu <dhongu(@)gmail(.)com
# See README.rst file on addons root folder for license details


from . import valuation_area
from . import product_valuation
from . import account
from . import account_move
from . import account_move_line
from . import res_company
from . import warehouse
from . import stock_location
from . import product_template


from . import res_config_settings
12 changes: 12 additions & 0 deletions deltatech_stock_valuation/models/account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# © 2023 Deltatech
# Dorin Hongu <dhongu(@)gmail(.)com
# See README.rst file on addons root folder for license details


from odoo import fields, models


class AccountAccount(models.Model):
_inherit = "account.account"

stock_valuation = fields.Boolean(string="Stock Valuation")
46 changes: 46 additions & 0 deletions deltatech_stock_valuation/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# © 2023 Deltatech
# Dorin Hongu <dhongu(@)gmail(.)com
# See README.rst file on addons root folder for license details


from odoo import models


class AccountMove(models.Model):
_inherit = "account.move"

def recompute_valuation(self):
for move in self:
for line in move.line_ids:
if line.product_id and line.account_id.stock_valuation:
if not line.valuation_area_id:
line.set_valuation_area_id()

valuation_area = line.valuation_area_id

valuation_history = self.env["product.valuation.history"].get_valuation(
line.product_id.id, valuation_area.id, line.account_id.id, move.date, line.company_id.id
)
valuation_history.recompute_amount()

valuation = self.env["product.valuation"].get_valuation(
line.product_id.id, valuation_area.id, line.account_id.id, line.company_id.id
)
valuation.recompute_amount()

# def _post(self, soft=True):
# res = super()._post(soft=soft)
# self.recompute_valuation()
# return res
#
# def button_draft(self):
# res = super().button_draft()
# self.recompute_valuation()
# return res

def write(self, vals):
res = super().write(vals)
if vals.get("state"):
self.invalidate_cache()
self.recompute_valuation()
return res
35 changes: 35 additions & 0 deletions deltatech_stock_valuation/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# © 2023 Deltatech
# Dorin Hongu <dhongu(@)gmail(.)com
# See README.rst file on addons root folder for license details


from odoo import fields, models


class AccountMoveLine(models.Model):
_inherit = "account.move.line"

valuation_area_id = fields.Many2one("valuation.area", string="Valuation Area")

def set_valuation_area_id(self):
for line in self:
stock_move = line.move_id.stock_move_id
if line.product_id and line.account_id.stock_valuation:
valuation_area_level = line.company_id.valuation_area_level
if valuation_area_level == "company":
valuation_area = line.company_id.valuation_area_id
elif valuation_area_level == "warehouse":
valuation_area = stock_move.warehouse_id.valuation_area_id
elif valuation_area_level == "location":
if line.credit:
valuation_area = (
stock_move.location_id.valuation_area_id or stock_move.location_dest_id.valuation_area_id
)
else:
valuation_area = (
stock_move.location_dest_id.valuation_area_id or stock_move.location_id.valuation_area_id
)
else:
valuation_area = False

line.write({"valuation_area_id": valuation_area.id})
30 changes: 30 additions & 0 deletions deltatech_stock_valuation/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# © 2023 Deltatech
# Dorin Hongu <dhongu(@)gmail(.)com
# See README.rst file on addons root folder for license detai

from odoo import fields, models


class ProductTemplate(models.Model):
_inherit = "product.template"

stock_valuation = fields.Boolean(string="Stock Valuation")

def recompute_valuation_amount(self):
valuations = self.env["product.valuation"]
for product in self:
for variant in product.product_variant_ids:
company = variant.company_id or self.env.company
account = variant.categ_id.property_stock_valuation_account_id
if not account:
continue

if not account.stock_valuation:
account.stock_valuation = True

valuation_area = company.valuation_area_id
valuations |= self.env["product.valuation"].get_valuation(
variant.id, valuation_area.id, account.id, company.id
)

valuations.recompute_amount()
Loading
Loading