diff --git a/purchase_specific_location/__init__.py b/purchase_specific_location/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/purchase_specific_location/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/purchase_specific_location/__manifest__.py b/purchase_specific_location/__manifest__.py new file mode 100644 index 000000000..5ada9272f --- /dev/null +++ b/purchase_specific_location/__manifest__.py @@ -0,0 +1,37 @@ +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2016 Akretion (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +{ + "name": "Purchase Specific Location", + "version": "16.0.1.0.0", + "author": "Akretion,Odoo Community Association (OCA)", + "website": "https://github.com/akretion/ak-odoo-incubator", + "summary": """ + Allow to create reception in a sublocation of the location's orderpoint + """, + "license": "AGPL-3", + "category": "Generic Modules/Others", + "depends": ["purchase_stock"], + "data": [ + "views/stock_orderpoint_view.xml", + "views/purchase_order_view.xml", + ], + "installable": True, +} diff --git a/purchase_specific_location/models/__init__.py b/purchase_specific_location/models/__init__.py new file mode 100644 index 000000000..5d3a0a6a8 --- /dev/null +++ b/purchase_specific_location/models/__init__.py @@ -0,0 +1,4 @@ +from . import stock_orderpoint +from . import stock_rule +from . import purchase_order +from . import procurement_group diff --git a/purchase_specific_location/models/procurement_group.py b/purchase_specific_location/models/procurement_group.py new file mode 100644 index 000000000..00ad38d41 --- /dev/null +++ b/purchase_specific_location/models/procurement_group.py @@ -0,0 +1,24 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + + +class ProcurementGroup(models.Model): + _inherit = "procurement.group" + + @api.model + def run(self, procurements, raise_user_error=True): + new_procurements = [] + for procurement in procurements: + orderpoint = procurement.values.get("orderpoint_id") + if ( + self.env.context.get("from_orderpoint") + and orderpoint.location_destination_id + and orderpoint.location_id == procurement.location_id + ): + new_procurements.append( + procurement._replace(location_id=orderpoint.location_destination_id) + ) + else: + new_procurements.append(procurement) + return super().run(new_procurements, raise_user_error=raise_user_error) diff --git a/purchase_specific_location/models/purchase_order.py b/purchase_specific_location/models/purchase_order.py new file mode 100644 index 000000000..05695e5e4 --- /dev/null +++ b/purchase_specific_location/models/purchase_order.py @@ -0,0 +1,31 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + specific_location_id = fields.Many2one( + "stock.location", + string="Specific Location", + compute="_compute_specific_location_id", + readonly=False, + store=True, + ) + default_location_dest_id = fields.Many2one( + related="picking_type_id.default_location_dest_id", string="Default Location" + ) + + def _get_destination_location(self): + self.ensure_one() + if self.specific_location_id: + return self.specific_location_id.id + else: + return super()._get_destination_location() + + @api.depends("picking_type_id") + def _compute_specific_location_id(self): + # reset in case the picking type changed + for po in self: + po.specific_location_id = False diff --git a/purchase_specific_location/models/stock_orderpoint.py b/purchase_specific_location/models/stock_orderpoint.py new file mode 100644 index 000000000..0f4a0b1e7 --- /dev/null +++ b/purchase_specific_location/models/stock_orderpoint.py @@ -0,0 +1,9 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class StockWarehouseOrderpoint(models.Model): + _inherit = "stock.warehouse.orderpoint" + + location_destination_id = fields.Many2one("stock.location", "Destination Location") diff --git a/purchase_specific_location/models/stock_rule.py b/purchase_specific_location/models/stock_rule.py new file mode 100644 index 000000000..95a897a16 --- /dev/null +++ b/purchase_specific_location/models/stock_rule.py @@ -0,0 +1,21 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class StockRule(models.Model): + _inherit = "stock.rule" + + def _make_po_get_domain(self, company_id, values, partner): + domain = super()._make_po_get_domain(company_id, values, partner) + orderpoint = values.get("orderpoint_id", False) + dest_location = orderpoint.location_destination_id.id or False + domain += (("specific_location_id", "=", dest_location),) + return domain + + def _prepare_purchase_order(self, company_id, origins, values): + vals = super()._prepare_purchase_order(company_id, origins, values) + values = values[0] + orderpoint = values.get("orderpoint_id", False) + vals["specific_location_id"] = orderpoint.location_destination_id.id or False + return vals diff --git a/purchase_specific_location/readme/CONTRIBUTORS.rst b/purchase_specific_location/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..0bddb053a --- /dev/null +++ b/purchase_specific_location/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Florian da Costa diff --git a/purchase_specific_location/readme/DESCRIPTION.rst b/purchase_specific_location/readme/DESCRIPTION.rst new file mode 100644 index 000000000..6f760da9a --- /dev/null +++ b/purchase_specific_location/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +This module add a destination location on orderpoint and purchase order. +It allows to check the minimum stock on some parent location, but generate a PO on a specific sublocation +It also allow to create a PO directly for a sublocation of the global location configured on the choosen picking type. diff --git a/purchase_specific_location/views/purchase_order_view.xml b/purchase_specific_location/views/purchase_order_view.xml new file mode 100644 index 000000000..f8cdf7c9e --- /dev/null +++ b/purchase_specific_location/views/purchase_order_view.xml @@ -0,0 +1,21 @@ + + + + + + purchase.order + + + + + + + + + + diff --git a/purchase_specific_location/views/stock_orderpoint_view.xml b/purchase_specific_location/views/stock_orderpoint_view.xml new file mode 100644 index 000000000..bbf3d1c01 --- /dev/null +++ b/purchase_specific_location/views/stock_orderpoint_view.xml @@ -0,0 +1,19 @@ + + + + + + stock.warehouse.orderpoint + + + + + + + + + diff --git a/setup/.setuptools-odoo-make-default-ignore b/setup/.setuptools-odoo-make-default-ignore new file mode 100644 index 000000000..207e61533 --- /dev/null +++ b/setup/.setuptools-odoo-make-default-ignore @@ -0,0 +1,2 @@ +# addons listed in this file are ignored by +# setuptools-odoo-make-default (one addon per line) diff --git a/setup/README b/setup/README new file mode 100644 index 000000000..a63d633e8 --- /dev/null +++ b/setup/README @@ -0,0 +1,2 @@ +To learn more about this directory, please visit +https://pypi.python.org/pypi/setuptools-odoo diff --git a/setup/purchase_specific_location/odoo/addons/purchase_specific_location b/setup/purchase_specific_location/odoo/addons/purchase_specific_location new file mode 120000 index 000000000..676d17765 --- /dev/null +++ b/setup/purchase_specific_location/odoo/addons/purchase_specific_location @@ -0,0 +1 @@ +../../../../purchase_specific_location \ No newline at end of file diff --git a/setup/purchase_specific_location/setup.py b/setup/purchase_specific_location/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/purchase_specific_location/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)