-
-
Notifications
You must be signed in to change notification settings - Fork 649
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
[14.0][ADD] sale_stock_mto_as_mts_orderpoint_mrp #1701
base: 14.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from . import product | ||
from . import product_template | ||
from . import product_product | ||
from . import sale_order | ||
from . import stock_move | ||
from . import stock_warehouse |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2020 Camptocamp SA | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
from odoo import models | ||
|
||
|
||
class ProductProduct(models.Model): | ||
|
||
_inherit = "product.product" | ||
|
||
def _is_mto(self): | ||
self.ensure_one() | ||
mto_route = self.env.ref("stock.route_warehouse0_mto") | ||
return mto_route in self.route_ids |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
====================================== | ||
Sale Stock Mto As Mts Orderpoint - BOM | ||
====================================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:b2f2392c6e84e861a129326d15b4231d6e05e156c713f590bc8e5d0b2ea30e60 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
||
.. |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-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/14.0/sale_stock_mto_as_mts_orderpoint_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-14-0/stock-logistics-workflow-14-0-sale_stock_mto_as_mts_orderpoint_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=14.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
Glue module between Sale Stock MTO as MTS Orderpoint and MRP. | ||
|
||
This allows to create orderpoints for Bills of Materials, and to set them as MTO. | ||
|
||
.. 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/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:%20sale_stock_mto_as_mts_orderpoint_mrp%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 | ||
~~~~~~~ | ||
|
||
* Camptocamp | ||
|
||
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. | ||
|
||
.. |maintainer-mmequignon| image:: https://github.com/mmequignon.png?size=40px | ||
:target: https://github.com/mmequignon | ||
:alt: mmequignon | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-mmequignon| | ||
|
||
This module is part of the `OCA/stock-logistics-workflow <https://github.com/OCA/stock-logistics-workflow/tree/14.0/sale_stock_mto_as_mts_orderpoint_mrp>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2024 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
{ | ||
"name": "Sale Stock Mto As Mts Orderpoint - BOM", | ||
"summary": "Integration module between sale_stock_mto_as_mts_orderpoint and mrp", | ||
"version": "14.0.1.0.0", | ||
"development_status": "Alpha", | ||
"category": "Operations/Inventory/Delivery", | ||
"website": "https://github.com/OCA/stock-logistics-workflow", | ||
"author": "Camptocamp, Odoo Community Association (OCA)", | ||
"maintainers": ["mmequignon"], | ||
"license": "AGPL-3", | ||
"installable": True, | ||
"depends": [ | ||
"sale_stock_mto_as_mts_orderpoint", | ||
"mrp", | ||
"mrp_bom_find_ignore", | ||
], | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from . import sale_order_line | ||
from . import stock_move | ||
from . import stock_warehouse_orderpoint |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2024 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
|
||
from odoo import api, models | ||
|
||
|
||
class SaleOrderLine(models.Model): | ||
_inherit = "sale.order.line" | ||
|
||
@api.model | ||
def _get_procurement_wiz_for_orderpoint_ids(self, context): | ||
context.update({"ignore_bom_find": True}) | ||
return super()._get_procurement_wiz_for_orderpoint_ids(context) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should point out, that this can only work for simple bom kits. (Where no component is a kit it self)
This can never order all of the necessary products. The move from bom 1 can not be reordered by mto because of this |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,48 @@ | ||||||
# Copyright 2024 Camptocamp SA | ||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||||||
|
||||||
from odoo import models | ||||||
from odoo.tools import groupby | ||||||
|
||||||
|
||||||
class StockMove(models.Model): | ||||||
_inherit = "stock.move" | ||||||
|
||||||
def all_moves_can_be_bought(self): | ||||||
for move in self: | ||||||
if not move.product_id.purchase_ok: | ||||||
return False | ||||||
return True | ||||||
jbaudoux marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
def _get_mto_as_mts_orderpoints(self, warehouse): | ||||||
orderpoints_to_procure = self.env["stock.warehouse.orderpoint"] | ||||||
mmequignon marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
if self.all_moves_can_be_bought(): | ||||||
return super()._get_mto_as_mts_orderpoints(warehouse) | ||||||
|
||||||
seen_moves = self.browse() | ||||||
for bom, bom_move_list in groupby(self, key=lambda m: m.bom_line_id.bom_id): | ||||||
bom_moves = self.browse([move.id for move in bom_move_list]) | ||||||
if not bom or not bom_moves: | ||||||
# In case a move doesn't have a bom, do nothing | ||||||
continue | ||||||
|
||||||
bom_product = bom.product_id | ||||||
bom_lines = bom.bom_line_ids | ||||||
move_bom_lines = bom_moves.bom_line_id | ||||||
if bom_lines != move_bom_lines: | ||||||
continue | ||||||
|
||||||
is_mto = bom_product._is_mto() or all(bom_moves.is_from_mto_route) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if not bom_moves.all_moves_can_be_bought() and is_mto: | ||||||
orderpoint = self._get_mto_orderpoint(warehouse, bom_product) | ||||||
if orderpoint.procure_recommended_qty: | ||||||
orderpoints_to_procure |= orderpoint | ||||||
# All bom_moves has been handled | ||||||
seen_moves |= bom_moves | ||||||
|
||||||
remaining_moves = self - seen_moves | ||||||
return ( | ||||||
super(StockMove, remaining_moves)._get_mto_as_mts_orderpoints(warehouse) | ||||||
| orderpoints_to_procure | ||||||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2024 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
from odoo import api, models | ||
|
||
|
||
class StockWarehouseOrderpoint(models.Model): | ||
_inherit = "stock.warehouse.orderpoint" | ||
|
||
@api.constrains("product_id") | ||
def check_product_is_not_kit(self): | ||
# Bypasses the check regarding having orderpoints for phantom bom products | ||
# in `mrp` | ||
return True | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Glue module between Sale Stock MTO as MTS Orderpoint and MRP. | ||
|
||
This allows to create orderpoints for Bills of Materials, and to set them as MTO. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved it to
product.product
and try to be close to v16 implementation https://github.com/OCA/stock-logistics-orderpoint/blob/16.0/stock_orderpoint_mto_as_mts/models/product_product.py#L26You could backport the content of product_product.py from v16.
The main difference in v16 is that the trigger is automatic and you don't need to call the wizard