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

[16.0][MIG]stock_orderpoint_origin_mrp_link: migration to 16.0 #22

Open
wants to merge 6 commits into
base: 16.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
6 changes: 6 additions & 0 deletions setup/stock_orderpoint_origin/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
6 changes: 6 additions & 0 deletions setup/stock_orderpoint_origin_mrp_link/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
97 changes: 97 additions & 0 deletions stock_orderpoint_origin/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
====================================================
Stock Orderpoint Replenishment demand origin details
====================================================

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

.. |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-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--orderpoint-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-orderpoint/tree/16.0/stock_orderpoint_origin
:alt: OCA/stock-logistics-orderpoint
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-orderpoint-16-0/stock-logistics-orderpoint-16-0-stock_orderpoint_origin
: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-orderpoint&target_branch=16.0
:alt: Try me on Runboat

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

The Inventory Replenishment menu alows to choose a route and create orders to
replenish the needed quantities of a Product.

However the Purchase Orders created do not have the information
about the documents that generated that demand.
The Purchase Order "Origin" field will only
identify the replenishment/reorder rule that generated it.

This feature updates the Purchase Order "Origin" field with the documents
that generated the demand, generating the demand, such as Sales Orders or Manufacturing Orders.
This is done based on the information provided by the Forecast report.

The source demand Sales Orders are added to the Purchase Order smart button,
allowing to navigate directly to them.

**Table of contents**

.. contents::
:local:

Usage
=====

- Create order from the Replenishment menu, for example, using the "Order Once" button.
- Verify the Origin field of the created orders. It should include the references to the
orders generating this demand at the time of replenishment creation.
- If demand was generated from Sales Orders, the "Sale" smart button should be available.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-orderpoint/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-orderpoint/issues/new?body=module:%20stock_orderpoint_origin%0Aversion:%2016.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
~~~~~~~

* Open Source Integrators

Contributors
~~~~~~~~~~~~

* Daniel Reis <[email protected]> `Open Source Integrators <https://opensourceintegrators.com>`_:

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-orderpoint <https://github.com/OCA/stock-logistics-orderpoint/tree/16.0/stock_orderpoint_origin>`_ 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 stock_orderpoint_origin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
13 changes: 13 additions & 0 deletions stock_orderpoint_origin/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2021 Open Source Integrators
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{
"name": "Stock Orderpoint Replenishment demand origin details",
"summary": "Link Purchase Orders to the replenishment demand Sales Orders",
"version": "16.0.1.0.0",
"license": "LGPL-3",
"website": "https://github.com/OCA/stock-logistics-orderpoint",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"category": "Warehouse",
"depends": ["purchase_stock", "sale_stock"],
"installable": True,
}
2 changes: 2 additions & 0 deletions stock_orderpoint_origin/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import procurement_group
from . import purchase_order
32 changes: 32 additions & 0 deletions stock_orderpoint_origin/models/procurement_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2021 Open Source Integrators
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import api, models


class ProcurementGroup(models.Model):
_inherit = "procurement.group"

@api.model
def run(self, procurements, raise_user_error=True):
# Store the reorder source Procurement Groups
# To be used for reference and link navigation
# Also updates the Origin field of the PO
Forecast = self.env["report.stock.report_product_product_replenishment"]
new_procurements = []
for procurement in procurements:
product = procurement.product_id
# TODO: set warehouse_id in context?
data = Forecast._get_report_data(product_variant_ids=[product.id])
source_docs = []
for line in data["lines"]:
if not line["document_in"] and line["document_out"]:
source_docs.append(line["document_out"])
if source_docs:
source_groups = [x.procurement_group_id for x in source_docs]
source_names = ", ".join([x.name for x in source_docs])
new_origin = "%s (from %s)" % (source_names, procurement.origin)
new_procurement = procurement._replace(origin=new_origin)
new_procurement.values["source_group_ids"] = source_groups
new_procurements.append(new_procurement)
return super().run(new_procurements, raise_user_error=True)
39 changes: 39 additions & 0 deletions stock_orderpoint_origin/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2021 Open Source Integrators
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import api, fields, models


class PurchaseOrder(models.Model):
_inherit = "purchase.order"

def _get_sale_orders(self):
# Used by action_view_sale_orders, for smart button
# return self.order_line.sale_order_id
res = super()._get_sale_orders()
res |= self.order_line.source_group_ids.sale_id
return res


class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"

source_group_ids = fields.Many2many(
comodel_name="procurement.group",
string="Procurements from Forecast Report",
copy=False,
)

@api.model
def _prepare_purchase_order_line_from_procurement(
self, product_id, product_qty, product_uom, company_id, values, po
):
vals = super()._prepare_purchase_order_line_from_procurement(
product_id, product_qty, product_uom, company_id, values, po
)
# Store the reorder source Procurement Groups
# To be used for reference and link navigation
groups = values.get("source_group_ids")
if groups:
vals["source_group_ids"] = [(4, o.id) for o in groups]
return vals
1 change: 1 addition & 0 deletions stock_orderpoint_origin/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Daniel Reis <[email protected]> `Open Source Integrators <https://opensourceintegrators.com>`_:
14 changes: 14 additions & 0 deletions stock_orderpoint_origin/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
The Inventory Replenishment menu alows to choose a route and create orders to
replenish the needed quantities of a Product.

However the Purchase Orders created do not have the information
about the documents that generated that demand.
The Purchase Order "Origin" field will only
identify the replenishment/reorder rule that generated it.

This feature updates the Purchase Order "Origin" field with the documents
that generated the demand, generating the demand, such as Sales Orders or Manufacturing Orders.
This is done based on the information provided by the Forecast report.

The source demand Sales Orders are added to the Purchase Order smart button,
allowing to navigate directly to them.
4 changes: 4 additions & 0 deletions stock_orderpoint_origin/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- Create order from the Replenishment menu, for example, using the "Order Once" button.
- Verify the Origin field of the created orders. It should include the references to the
orders generating this demand at the time of replenishment creation.
- If demand was generated from Sales Orders, the "Sale" smart button should be available.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading