forked from OCA/stock-logistics-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by pedrobaeza
- Loading branch information
Showing
32 changed files
with
1,689 additions
and
2 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
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
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,81 @@ | ||
==================================== | ||
Product cost price avco sync for mrp | ||
==================================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:4fb205ca85bef4b0eecda30b16531b4d2650e2dc17581a633f9fa93b3305c8d4 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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--workflow-lightgray.png?logo=github | ||
:target: https://github.com/OCA/stock-logistics-workflow/tree/13.0/product_cost_price_avco_sync_mrp | ||
:alt: OCA/stock-logistics-workflow | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/stock-logistics-workflow-13-0/stock-logistics-workflow-13-0-product_cost_price_avco_sync_mrp | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-workflow&target_branch=13.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module extends the product_cost_price_avco_sync module to allow a change in the | ||
cost of materials involved in a production run to be propagated to the cost of the | ||
product produced. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-workflow/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/OCA/stock-logistics-workflow/issues/new?body=module:%20product_cost_price_avco_sync_mrp%0Aversion:%2013.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 | ||
~~~~~~~ | ||
|
||
* Tecnativa | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* `Tecnativa <https://www.tecnativa.com>`_ | ||
|
||
* Pedro M. Baeza | ||
* Carlos Roca | ||
|
||
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-workflow <https://github.com/OCA/stock-logistics-workflow/tree/13.0/product_cost_price_avco_sync_mrp>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
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 models |
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,14 @@ | ||
# Copyright 2023 Tecnativa - Carlos Roca | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Product cost price avco sync for mrp", | ||
"summary": "Set product cost price from updated moves that implies productions", | ||
"version": "13.0.1.0.0", | ||
"development_status": "Production/Stable", | ||
"category": "Stock", | ||
"website": "https://github.com/OCA/stock-logistics-workflow", | ||
"author": "Tecnativa, Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"installable": True, | ||
"depends": ["product_cost_price_avco_sync", "mrp_account"], | ||
} |
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,23 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * product_cost_price_avco_sync_mrp | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 13.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2023-08-11 05:53+0000\n" | ||
"PO-Revision-Date: 2023-08-11 07:53+0200\n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"Language: es\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Plural-Forms: nplurals=2; plural=(n != 1);\n" | ||
"X-Generator: Poedit 3.3.2\n" | ||
|
||
#. module: product_cost_price_avco_sync_mrp | ||
#: model:ir.model,name:product_cost_price_avco_sync_mrp.model_stock_valuation_layer | ||
msgid "Stock Valuation Layer" | ||
msgstr "Capa de valoración de stock" |
21 changes: 21 additions & 0 deletions
21
product_cost_price_avco_sync_mrp/i18n/product_cost_price_avco_sync_mrp.pot
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,21 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * product_cost_price_avco_sync_mrp | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 13.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2023-08-11 05:53+0000\n" | ||
"PO-Revision-Date: 2023-08-11 05:53+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: product_cost_price_avco_sync_mrp | ||
#: model:ir.model,name:product_cost_price_avco_sync_mrp.model_stock_valuation_layer | ||
msgid "Stock Valuation Layer" | ||
msgstr "" |
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 stock_valuation_layer |
65 changes: 65 additions & 0 deletions
65
product_cost_price_avco_sync_mrp/models/stock_valuation_layer.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright 2023 Tecnativa - Carlos Roca | ||
# Copyright 2023 Tecnativa - Pedro M. Baeza | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, models | ||
|
||
|
||
class StockValuationLayer(models.Model): | ||
_inherit = "stock.valuation.layer" | ||
|
||
@api.model | ||
def _cal_price_mrp(self, quantity, svls_dic): | ||
"""Get the cost price for the production order linked to this SVL. | ||
NOTE: This is adaptation of the method _cal_price in mrp_account. | ||
""" | ||
finished_move = self.stock_move_id | ||
production = finished_move.production_id | ||
cost = 0 | ||
for cons_move in finished_move.move_line_ids.consume_line_ids.move_id: | ||
svl = cons_move.stock_valuation_layer_ids[:1] | ||
cost -= svls_dic.get(svl, {"value": svl.value})["value"] | ||
work_center_cost = 0 | ||
for work_order in production.workorder_ids: | ||
time_lines = work_order.time_ids.filtered( | ||
lambda x: x.date_end and not x.cost_already_recorded | ||
) | ||
duration = sum(time_lines.mapped("duration")) | ||
work_center_cost += (duration / 60.0) * work_order.workcenter_id.costs_hour | ||
svl = finished_move.stock_valuation_layer_ids[:1] | ||
currency = svl.currency_id | ||
qty_done = finished_move.product_uom._compute_quantity( | ||
quantity, finished_move.product_id.uom_id | ||
) | ||
extra_cost = production.extra_cost * qty_done | ||
return currency.round((cost + work_center_cost + extra_cost) / qty_done) | ||
|
||
def _postprocess_rest_svl_to_sync(self, svls_dic, postprocess_svl_dic): | ||
"""If this SVL is the consumption of a raw material, we should affect the cost | ||
of the finished products for such production order. | ||
""" | ||
if self.stock_move_id.raw_material_production_id: | ||
production = self.stock_move_id.raw_material_production_id | ||
for move in production.move_finished_ids.filtered( | ||
lambda x: x.state == "done" | ||
and x.quantity_done > 0 | ||
and x.product_id.cost_method == "average" | ||
): | ||
svl = move.stock_valuation_layer_ids[:1] | ||
unit_cost = svl._cal_price_mrp(svl.quantity, svls_dic) | ||
postprocess_svl_dic[svl] = { | ||
"unit_cost": unit_cost, | ||
"value": unit_cost * svl.quantity, | ||
} | ||
return True | ||
return super()._postprocess_rest_svl_to_sync(svls_dic, postprocess_svl_dic) | ||
|
||
def _preprocess_rest_svl_to_sync(self, svls_dic, preprocess_svl_dic): | ||
"""If this SVL is coming from a move of a production order, we get the unit cost | ||
from the consumed materials, not doing anything more with it. | ||
""" | ||
if self.stock_move_id.production_id: | ||
svl_dic = svls_dic[self] | ||
svl_dic["unit_cost"] = self._cal_price_mrp(svl_dic["quantity"], svls_dic) | ||
return True | ||
return super()._preprocess_rest_svl_to_sync(svls_dic, preprocess_svl_dic) |
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,4 @@ | ||
* `Tecnativa <https://www.tecnativa.com>`_ | ||
|
||
* Pedro M. Baeza | ||
* Carlos Roca |
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,3 @@ | ||
This module extends the product_cost_price_avco_sync module to allow a change in the | ||
cost of materials involved in a production run to be propagated to the cost of the | ||
product produced. |
Oops, something went wrong.