diff --git a/stock_orderpoint_purchase_link/README.rst b/stock_orderpoint_purchase_link/README.rst new file mode 100644 index 000000000..42fbcfef2 --- /dev/null +++ b/stock_orderpoint_purchase_link/README.rst @@ -0,0 +1,52 @@ +.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg + :target: https://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 + +============================== +Stock Orderpoint Purchase Link +============================== + +This module adds to purchase order lines a direct link to the reordering rules +that created them. In chained moves, the reordering rule is propagated +from stock moves to the purchase order line. + + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/153/11.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of +trouble, please check there if your issue has already been reported. If you +spotted it first, help us smash it by providing detailed and welcomed feedback. + + +Credits +======= + +Contributors +------------ + +* Jordi Ballester + + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/stock_orderpoint_purchase_link/__init__.py b/stock_orderpoint_purchase_link/__init__.py new file mode 100644 index 000000000..a9e337226 --- /dev/null +++ b/stock_orderpoint_purchase_link/__init__.py @@ -0,0 +1,2 @@ + +from . import models diff --git a/stock_orderpoint_purchase_link/__manifest__.py b/stock_orderpoint_purchase_link/__manifest__.py new file mode 100644 index 000000000..c0d2c0452 --- /dev/null +++ b/stock_orderpoint_purchase_link/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2017 Eficent Business and IT Consulting Services, S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Stock Orderpoint Purchase Link", + "summary": "Link Reordering rules to purchase orders", + "version": "11.0.1.0.0", + "license": "LGPL-3", + "website": "https://github.com/stock-logistics-warehouse", + "author": "Eficent, " + "Odoo Community Association (OCA)", + "category": "Warehouse Management", + "depends": [ + "stock_orderpoint_move_link", + "purchase", + ], + "data": [ + "views/purchase_order_views.xml", + ], + "installable": True, + 'auto_install': True, +} diff --git a/stock_orderpoint_purchase_link/models/__init__.py b/stock_orderpoint_purchase_link/models/__init__.py new file mode 100644 index 000000000..75fdf6149 --- /dev/null +++ b/stock_orderpoint_purchase_link/models/__init__.py @@ -0,0 +1,2 @@ +from . import purchase_order_line +from . import procurement_rule diff --git a/stock_orderpoint_purchase_link/models/procurement_rule.py b/stock_orderpoint_purchase_link/models/procurement_rule.py new file mode 100644 index 000000000..74291fb36 --- /dev/null +++ b/stock_orderpoint_purchase_link/models/procurement_rule.py @@ -0,0 +1,31 @@ +# Copyright 2017 Eficent Business and IT Consulting Services, S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import models + + +class ProcurementRule(models.Model): + _inherit = 'procurement.rule' + + def _prepare_purchase_order_line(self, product_id, product_qty, + product_uom, values, po, supplier): + vals = super(ProcurementRule, self)._prepare_purchase_order_line( + product_id, product_qty, product_uom, values, po, supplier) + # If the procurement was run directly by a reordering rule. + if 'orderpoint_id' in values: + vals['orderpoint_ids'] = [ + (4, values['orderpoint_id'].id)] + # If the procurement was run by a stock move. + elif 'orderpoint_ids' in values: + vals['orderpoint_ids'] = [(4, o.id) + for o in values['orderpoint_ids']] + return vals + + def _update_purchase_order_line(self, product_id, product_qty, product_uom, + values, line, partner): + vals = super(ProcurementRule, self)._update_purchase_order_line( + product_id, product_qty, product_uom, values, line, partner) + if 'orderpoint_id' in values: + vals['orderpoint_ids'] = [ + (4, values['orderpoint_id'].id)] + return vals diff --git a/stock_orderpoint_purchase_link/models/purchase_order_line.py b/stock_orderpoint_purchase_link/models/purchase_order_line.py new file mode 100644 index 000000000..ee747ba1b --- /dev/null +++ b/stock_orderpoint_purchase_link/models/purchase_order_line.py @@ -0,0 +1,12 @@ +# Copyright 2017 Eficent Business and IT Consulting Services, S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import api, fields, models + + +class PurchaseOrderLine(models.Model): + _inherit = 'purchase.order.line' + + orderpoint_ids = fields.Many2many( + comodel_name='stock.warehouse.orderpoint', + string='Orderpoints', copy=False) diff --git a/stock_orderpoint_purchase_link/static/description/icon.png b/stock_orderpoint_purchase_link/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/stock_orderpoint_purchase_link/static/description/icon.png differ diff --git a/stock_orderpoint_purchase_link/views/purchase_order_views.xml b/stock_orderpoint_purchase_link/views/purchase_order_views.xml new file mode 100644 index 000000000..1ebd4d8fb --- /dev/null +++ b/stock_orderpoint_purchase_link/views/purchase_order_views.xml @@ -0,0 +1,35 @@ + + + + + purchase.order.form + purchase.order + + + + + + + + + + + + + + + purchase.order.line.form2 + purchase.order.line + + + + + + + + + +