Skip to content

Commit

Permalink
Merge PR OCA#1352 into 13.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Feb 19, 2024
2 parents dcf3d83 + f7cf771 commit 59e747c
Show file tree
Hide file tree
Showing 32 changed files with 1,689 additions and 2 deletions.
5 changes: 3 additions & 2 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Do NOT update manually; changes here will be overwritten by Copier
_commit: v1.15.0
_commit: v1.17.1
_src_path: https://github.com/OCA/oca-addons-repo-template.git
ci: GitHub
dependency_installation_mode: PIP
Expand All @@ -15,7 +15,8 @@ odoo_test_flavor: Both
odoo_version: 13.0
org_name: Odoo Community Association (OCA)
org_slug: OCA
rebel_module_groups: []
rebel_module_groups:
- procurement_auto_create_group_carrier,stock_picking_group_by_partner_by_carrier,stock_picking_group_by_partner_by_carrier_by_date
repo_description: This project aims to deal with modules related to manage logistic
flows.
repo_name: Odoo Stock Logistic Workflow
Expand Down
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ globals:
odoo: readonly
openerp: readonly
owl: readonly
luxon: readonly

# Styling is handled by Prettier, so we only need to enable AST rules;
# see https://github.com/OCA/maintainer-quality-tools/pull/618#issuecomment-558576890
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ jobs:
run: pip install pre-commit
- name: Run pre-commit
run: pre-commit run --all-files --show-diff-on-failure --color=always
env:
# Consider valid a PR that changes README fragments but doesn't
# change the README.rst file itself. It's not really a problem
# because the bot will update it anyway after merge. This way, we
# lower the barrier for functional contributors that want to fix the
# readme fragments, while still letting developers get README
# auto-generated (which also helps functionals when using runboat).
# DOCS https://pre-commit.com/#temporarily-disabling-hooks
SKIP: oca-gen-addon-readme
- name: Check that all files generated by pre-commit are in git
run: |
newfiles="$(git ls-files --others --exclude-from=.gitignore)"
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,17 @@ jobs:
matrix:
include:
- container: ghcr.io/oca/oca-ci/py3.6-odoo13.0:latest
include: "procurement_auto_create_group_carrier,stock_picking_group_by_partner_by_carrier,stock_picking_group_by_partner_by_carrier_by_date"
name: test with Odoo
- container: ghcr.io/oca/oca-ci/py3.6-ocb13.0:latest
include: "procurement_auto_create_group_carrier,stock_picking_group_by_partner_by_carrier,stock_picking_group_by_partner_by_carrier_by_date"
name: test with OCB
makepot: "true"
- container: ghcr.io/oca/oca-ci/py3.6-odoo13.0:latest
exclude: "procurement_auto_create_group_carrier,stock_picking_group_by_partner_by_carrier,stock_picking_group_by_partner_by_carrier_by_date"
name: test with Odoo
- container: ghcr.io/oca/oca-ci/py3.6-ocb13.0:latest
exclude: "procurement_auto_create_group_carrier,stock_picking_group_by_partner_by_carrier,stock_picking_group_by_partner_by_carrier_by_date"
name: test with OCB
makepot: "true"
services:
Expand All @@ -49,6 +58,9 @@ jobs:
POSTGRES_DB: odoo
ports:
- 5432:5432
env:
INCLUDE: "${{ matrix.include }}"
EXCLUDE: "${{ matrix.exclude }}"
steps:
- uses: actions/checkout@v3
with:
Expand Down
81 changes: 81 additions & 0 deletions product_cost_price_avco_sync_mrp/README.rst
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.
1 change: 1 addition & 0 deletions product_cost_price_avco_sync_mrp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions product_cost_price_avco_sync_mrp/__manifest__.py
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"],
}
23 changes: 23 additions & 0 deletions product_cost_price_avco_sync_mrp/i18n/es.po
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"
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 ""
1 change: 1 addition & 0 deletions product_cost_price_avco_sync_mrp/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_valuation_layer
65 changes: 65 additions & 0 deletions product_cost_price_avco_sync_mrp/models/stock_valuation_layer.py
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)
4 changes: 4 additions & 0 deletions product_cost_price_avco_sync_mrp/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* `Tecnativa <https://www.tecnativa.com>`_

* Pedro M. Baeza
* Carlos Roca
3 changes: 3 additions & 0 deletions product_cost_price_avco_sync_mrp/readme/DESCRIPTION.rst
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.
Loading

0 comments on commit 59e747c

Please sign in to comment.