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] purchase_specific_location #317

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
1 change: 1 addition & 0 deletions purchase_specific_location/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
37 changes: 37 additions & 0 deletions purchase_specific_location/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2016 Akretion (<http://www.akretion.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################

{
"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,
}
4 changes: 4 additions & 0 deletions purchase_specific_location/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import stock_orderpoint
from . import stock_rule
from . import purchase_order
from . import procurement_group
24 changes: 24 additions & 0 deletions purchase_specific_location/models/procurement_group.py
Original file line number Diff line number Diff line change
@@ -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)
31 changes: 31 additions & 0 deletions purchase_specific_location/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions purchase_specific_location/models/stock_orderpoint.py
Original file line number Diff line number Diff line change
@@ -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")
21 changes: 21 additions & 0 deletions purchase_specific_location/models/stock_rule.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions purchase_specific_location/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Florian da Costa <[email protected]>
3 changes: 3 additions & 0 deletions purchase_specific_location/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -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.
21 changes: 21 additions & 0 deletions purchase_specific_location/views/purchase_order_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>


<record id="purchase_order_specific_location_form_view" model="ir.ui.view">
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form" />
<field name="arch" type="xml">
<field name="picking_type_id" position="after">
<field name="default_location_dest_id" invisible="1" />
<field
name="specific_location_id"
attrs="{'invisible': [('picking_type_id', '=', False)]}"
domain="[('id', 'child_of', default_location_dest_id)]"
groups="stock.group_stock_multi_locations"
/>
</field>
</field>
</record>

</odoo>
19 changes: 19 additions & 0 deletions purchase_specific_location/views/stock_orderpoint_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>


<record id="stock_orderpoint_destination_location_form_view" model="ir.ui.view">
<field name="model">stock.warehouse.orderpoint</field>
<field name="inherit_id" ref="stock.view_warehouse_orderpoint_tree_editable" />
<field name="arch" type="xml">
<field name="location_id" position="after">
<field
name="location_destination_id"
domain="[('id', 'child_of', location_id)]"
groups="stock.group_stock_multi_locations"
/>
</field>
</field>
</record>

</odoo>
2 changes: 2 additions & 0 deletions setup/.setuptools-odoo-make-default-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# addons listed in this file are ignored by
# setuptools-odoo-make-default (one addon per line)
2 changes: 2 additions & 0 deletions setup/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
To learn more about this directory, please visit
https://pypi.python.org/pypi/setuptools-odoo
6 changes: 6 additions & 0 deletions setup/purchase_specific_location/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,
)
Loading