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

[17.0][MIG] mrp_subcontracting_skip_no_negative: Migration to 17.0 #1454

Open
wants to merge 16 commits into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
100 changes: 100 additions & 0 deletions mrp_subcontracting_skip_no_negative/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
===================================
MRP Subcontracting Skip No Negative
===================================

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

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |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%2Fmanufacture-lightgray.png?logo=github
:target: https://github.com/OCA/manufacture/tree/17.0/mrp_subcontracting_skip_no_negative
:alt: OCA/manufacture
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/manufacture-17-0/manufacture-17-0-mrp_subcontracting_skip_no_negative
: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/manufacture&target_branch=17.0
:alt: Try me on Runboat

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

This module skips the negative quantity check, provided by
stock_no_negative, for subcontracting receipts.

Background:
-----------

Odoo processes subcontracting receipt in the order of:

1. Transfer of the subcontracted product from the subcontractor location
to the internal location. 2. Production of the subcontracted product in
the subcontractor location.

This sequence does not represent the reality where production is done
before transfer, and therefore the above Step 1 would fail with negative
stock in the subcontractor location, when stock_no_negative is
installed, unless the product/location is configured to allow negative
stock.

ref. https://github.com/odoo/odoo/pull/75065

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/manufacture/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/manufacture/issues/new?body=module:%20mrp_subcontracting_skip_no_negative%0Aversion:%2017.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
-------

* Quartile Limited

Contributors
------------

- `Quartile <https://www.quartile.co>`__:

- Aung Ko Ko Lin

- `Tecnativa <https://www.tecnativa.com>`__:

- Víctor Martínez

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/manufacture <https://github.com/OCA/manufacture/tree/17.0/mrp_subcontracting_skip_no_negative>`_ 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 mrp_subcontracting_skip_no_negative/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
13 changes: 13 additions & 0 deletions mrp_subcontracting_skip_no_negative/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2023 Quartile Limited
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
{
"name": "MRP Subcontracting Skip No Negative",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"author": "Quartile Limited, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/manufacture",
"category": "Manufacturing",
"depends": ["mrp_subcontracting", "stock_no_negative"],
"installable": True,
"auto_install": True,
}
43 changes: 43 additions & 0 deletions mrp_subcontracting_skip_no_negative/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mrp_subcontracting_skip_no_negative
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-11-05 07:53+0000\n"
"PO-Revision-Date: 2024-11-05 08:53+0100\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: \n"
"X-Generator: Poedit 3.0.1\n"

#. module: mrp_subcontracting_skip_no_negative
#: model:ir.model,name:mrp_subcontracting_skip_no_negative.model_stock_move
msgid "Stock Move"
msgstr "Movimiento de existencias"

#. module: mrp_subcontracting_skip_no_negative
#: model:ir.model,name:mrp_subcontracting_skip_no_negative.model_stock_picking
msgid "Transfer"
msgstr "Transferencia"

#. module: mrp_subcontracting_skip_no_negative
#. odoo-python
#: code:addons/mrp_subcontracting_skip_no_negative/models/stock_move.py:0
#, python-format
msgid ""
"You cannot validate this stock operation because the stock level of the "
"component product '{name}' would become negative ({qty}) on the stock "
"location '{location}' and negative stock is not allowed for this product and/"
"or location."
msgstr ""
"No se puede validar esta operación de stock porque el nivel de stock del "
"producto componente '{name}' se volvería negativo ({qty}) en la ubicación de "
"stock '{location}' y no se permite stock negativo para este producto y/o "
"ubicación."
42 changes: 42 additions & 0 deletions mrp_subcontracting_skip_no_negative/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mrp_subcontracting_skip_no_negative
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2024-11-08 09:35+0000\n"
"Last-Translator: mymage <[email protected]>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 5.6.2\n"

#. module: mrp_subcontracting_skip_no_negative
#: model:ir.model,name:mrp_subcontracting_skip_no_negative.model_stock_move
msgid "Stock Move"
msgstr "Movimento di magazzino"

#. module: mrp_subcontracting_skip_no_negative
#: model:ir.model,name:mrp_subcontracting_skip_no_negative.model_stock_picking
msgid "Transfer"
msgstr "Trasferimento"

#. module: mrp_subcontracting_skip_no_negative
#. odoo-python
#: code:addons/mrp_subcontracting_skip_no_negative/models/stock_move.py:0
#, python-format
msgid ""
"You cannot validate this stock operation because the stock level of the "
"component product '{name}' would become negative ({qty}) on the stock "
"location '{location}' and negative stock is not allowed for this product and/"
"or location."
msgstr ""
"Non è possibile convalidare questa operazione di magazzino perché il livello "
"di magazzino del prodotto componente '{name}' diventerebbe negativo ({qty}) "
"nell'ubicazione di magazzino '{location}' e per questo prodotto e/o "
"posizione non è consentito un magazzino negativo."
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mrp_subcontracting_skip_no_negative
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \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: mrp_subcontracting_skip_no_negative
#: model:ir.model,name:mrp_subcontracting_skip_no_negative.model_stock_move
msgid "Stock Move"
msgstr ""

#. module: mrp_subcontracting_skip_no_negative
#: model:ir.model,name:mrp_subcontracting_skip_no_negative.model_stock_picking
msgid "Transfer"
msgstr ""

#. module: mrp_subcontracting_skip_no_negative
#. odoo-python
#: code:addons/mrp_subcontracting_skip_no_negative/models/stock_move.py:0
#, python-format
msgid ""
"You cannot validate this stock operation because the stock level of the "
"component product '{name}' would become negative ({qty}) on the stock "
"location '{location}' and negative stock is not allowed for this product "
"and/or location."
msgstr ""
2 changes: 2 additions & 0 deletions mrp_subcontracting_skip_no_negative/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import stock_move
from . import stock_picking
78 changes: 78 additions & 0 deletions mrp_subcontracting_skip_no_negative/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright 2023 Quartile Limited
# Copyright 2024 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from odoo import _, models
from odoo.exceptions import ValidationError
from odoo.tools import config, float_compare


class StockMove(models.Model):
_inherit = "stock.move"

def _action_done(self, cancel_backorder=False):
moves_with_no_check = self.filtered(lambda x: x.is_subcontract).with_context(
skip_negative_qty_check=True
)
# For rather unlikely occassions where linked production is not in the right
# state.
for move in moves_with_no_check:
production_moves = self.search(
[
("move_dest_ids", "=", move.id),
("state", "not in", ("done", "cancel")),
]
)
productions = production_moves.production_id
unassigned_productions = productions.filtered(
lambda p: p.reservation_state != "assigned"
)
unassigned_productions.action_assign()
if all(
state == "assigned"
for state in unassigned_productions.mapped("reservation_state")
):
continue
moves_with_no_check -= move
# If you have not been able to allocate previously it is because there is
# no stock, therefore it will leave the stock negative, we deduct the
# quantity checking the components and show the corresponding error.
test_condition = (
config["test_enable"] and self.env.context.get("test_stock_no_negative")
) or not config["test_enable"]
if not test_condition:
continue

Check warning on line 44 in mrp_subcontracting_skip_no_negative/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_subcontracting_skip_no_negative/models/stock_move.py#L44

Added line #L44 was not covered by tests
qty_precision = self.env["decimal.precision"].precision_get(
"Product Unit of Measure"
)
for p_move in unassigned_productions.move_raw_ids.filtered(
lambda x: x.state != "assigned"
and not x.product_id.allow_negative_stock
and not x.product_id.categ_id.allow_negative_stock
and not x.location_id.allow_negative_stock
):
product = p_move.product_id.sudo()
location = p_move.location_id
location_qty = product.with_context(location=location.id).free_qty
new_qty = location_qty - p_move.product_uom_qty

Check warning on line 57 in mrp_subcontracting_skip_no_negative/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_subcontracting_skip_no_negative/models/stock_move.py#L54-L57

Added lines #L54 - L57 were not covered by tests
if float_compare(new_qty, 0, precision_digits=qty_precision) == -1:
raise ValidationError(

Check warning on line 59 in mrp_subcontracting_skip_no_negative/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_subcontracting_skip_no_negative/models/stock_move.py#L59

Added line #L59 was not covered by tests
_(
"You cannot validate this stock operation because the "
"stock level of the component product '{name}' would become"
" negative ({qty}) on the stock location '{location}' and "
"negative stock is not allowed for this product and/or "
"location."
).format(
name=product.display_name,
qty=new_qty,
location=location.complete_name,
)
)
res = super(StockMove, self - moves_with_no_check)._action_done(
cancel_backorder=cancel_backorder
)
res += super(StockMove, moves_with_no_check)._action_done(
cancel_backorder=cancel_backorder
)
return res
22 changes: 22 additions & 0 deletions mrp_subcontracting_skip_no_negative/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2023 Quartile Limited
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from odoo import models


class StockPicking(models.Model):
_inherit = "stock.picking"

def _action_done(self):
res = super()._action_done()
self._check_negative_quants_after_process()
return res

def _check_negative_quants_after_process(self):
product_ids = self.mapped("move_ids.product_id.id")
quants = self.env["stock.quant"].search(
[
("product_id", "in", product_ids),
]
)
quants.check_negative_qty()
3 changes: 3 additions & 0 deletions mrp_subcontracting_skip_no_negative/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
4 changes: 4 additions & 0 deletions mrp_subcontracting_skip_no_negative/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- [Quartile](https://www.quartile.co):
- Aung Ko Ko Lin
- [Tecnativa](https://www.tecnativa.com):
- Víctor Martínez
18 changes: 18 additions & 0 deletions mrp_subcontracting_skip_no_negative/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
This module skips the negative quantity check, provided by
stock_no_negative, for subcontracting receipts.

## Background:

Odoo processes subcontracting receipt in the order of:

1\. Transfer of the subcontracted product from the subcontractor
location to the internal location. 2. Production of the subcontracted
product in the subcontractor location.

This sequence does not represent the reality where production is done
before transfer, and therefore the above Step 1 would fail with negative
stock in the subcontractor location, when stock_no_negative is
installed, unless the product/location is configured to allow negative
stock.

ref. <https://github.com/odoo/odoo/pull/75065>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading