mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
@@ -0,0 +1 @@
|
||||
../../../../stock_location_orderpoint
|
||||
6
setup/stock_location_orderpoint/setup.py
Normal file
6
setup/stock_location_orderpoint/setup.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import setuptools
|
||||
|
||||
setuptools.setup(
|
||||
setup_requires=['setuptools-odoo'],
|
||||
odoo_addon=True,
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
../../../../stock_location_orderpoint_source_relocate
|
||||
6
setup/stock_location_orderpoint_source_relocate/setup.py
Normal file
6
setup/stock_location_orderpoint_source_relocate/setup.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import setuptools
|
||||
|
||||
setuptools.setup(
|
||||
setup_requires=['setuptools-odoo'],
|
||||
odoo_addon=True,
|
||||
)
|
||||
84
stock_location_orderpoint/README.rst
Normal file
84
stock_location_orderpoint/README.rst
Normal file
@@ -0,0 +1,84 @@
|
||||
=========================
|
||||
stock_location_orderpoint
|
||||
=========================
|
||||
|
||||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
.. |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-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--warehouse-lightgray.png?logo=github
|
||||
:target: https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_location_orderpoint
|
||||
:alt: OCA/stock-logistics-warehouse
|
||||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
|
||||
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-14-0/stock-logistics-warehouse-14-0-stock_location_orderpoint
|
||||
:alt: Translate me on Weblate
|
||||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
|
||||
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/stock-logistics-warehouse&target_branch=14.0
|
||||
:alt: Try me on Runboat
|
||||
|
||||
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||
|
||||
Declare orderpoint on a location allowing to replenish any product with the same criteria.
|
||||
This is for an internal warehouse replenishment currently not compatible with the purchase buy route.
|
||||
|
||||
**Table of contents**
|
||||
|
||||
.. contents::
|
||||
:local:
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-warehouse/issues>`_.
|
||||
In case of trouble, please check there if your issue has already been reported.
|
||||
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
||||
`feedback <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_location_orderpoint%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
|
||||
~~~~~~~
|
||||
|
||||
* MT Software
|
||||
* BCIM
|
||||
|
||||
Contributors
|
||||
~~~~~~~~~~~~
|
||||
|
||||
* Michael Tietz (MT Software) <mtietz@mt-software.de>
|
||||
* Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
|
||||
|
||||
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-mt-software-de| image:: https://github.com/mt-software-de.png?size=40px
|
||||
:target: https://github.com/mt-software-de
|
||||
:alt: mt-software-de
|
||||
|
||||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
|
||||
|
||||
|maintainer-mt-software-de|
|
||||
|
||||
This module is part of the `OCA/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_location_orderpoint>`_ project on GitHub.
|
||||
|
||||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
||||
1
stock_location_orderpoint/__init__.py
Normal file
1
stock_location_orderpoint/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
||||
31
stock_location_orderpoint/__manifest__.py
Normal file
31
stock_location_orderpoint/__manifest__.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
"name": "stock_location_orderpoint",
|
||||
"author": "MT Software, BCIM, Odoo Community Association (OCA)",
|
||||
"summary": "Declare orderpoint on a location "
|
||||
"allowing to replenish any product with the same criteria.",
|
||||
"version": "14.0.1.0.0",
|
||||
"data": [
|
||||
"security/ir.model.access.csv",
|
||||
"data/ir_cron.xml",
|
||||
"data/ir_sequence.xml",
|
||||
"data/queue_job_channel.xml",
|
||||
"data/queue_job_function.xml",
|
||||
"views/stock_location_orderpoint_views.xml",
|
||||
"views/stock_location.xml",
|
||||
"views/menu.xml",
|
||||
"demo/stock_location.xml",
|
||||
"demo/stock_picking_type.xml",
|
||||
"demo/stock_route.xml",
|
||||
"demo/stock_location_orderpoint.xml",
|
||||
],
|
||||
"depends": [
|
||||
"stock_helper",
|
||||
"queue_job",
|
||||
],
|
||||
"license": "AGPL-3",
|
||||
"maintainers": ["mt-software-de"],
|
||||
"website": "https://github.com/OCA/stock-logistics-warehouse",
|
||||
}
|
||||
19
stock_location_orderpoint/data/ir_cron.xml
Normal file
19
stock_location_orderpoint/data/ir_cron.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<data noupdate="1">
|
||||
<record forcecreate="True" id="ir_cron_location_replenishment" model="ir.cron">
|
||||
<field name="name">Procurement: run location replenishment</field>
|
||||
<field name="model_id" ref="model_stock_location_orderpoint" />
|
||||
<field name="state">code</field>
|
||||
<field name="code">
|
||||
model.run_cron_replenishment()
|
||||
</field>
|
||||
<field eval="False" name="active" />
|
||||
<field name="user_id" ref="base.user_root" />
|
||||
<field name="interval_number">10</field>
|
||||
<field name="interval_type">minutes</field>
|
||||
<field name="numbercall">-1</field>
|
||||
<field eval="False" name="doall" />
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
11
stock_location_orderpoint/data/ir_sequence.xml
Normal file
11
stock_location_orderpoint/data/ir_sequence.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<record id="sequence_location_orderpoint" model="ir.sequence">
|
||||
<field name="name">Stock locaation orderpoint</field>
|
||||
<field name="code">stock.location.orderpoint</field>
|
||||
<field name="prefix">LOP/</field>
|
||||
<field name="padding">5</field>
|
||||
<field name="number_next">1</field>
|
||||
<field name="number_increment">1</field>
|
||||
</record>
|
||||
</odoo>
|
||||
10
stock_location_orderpoint/data/queue_job_channel.xml
Normal file
10
stock_location_orderpoint/data/queue_job_channel.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo noupdate="1">
|
||||
<record
|
||||
id="channel_stock_location_orderpoint_auto_replenishment"
|
||||
model="queue.job.channel"
|
||||
>
|
||||
<field name="name">stock_location_orderpoint_auto_replenishment</field>
|
||||
<field name="parent_id" ref="queue_job.channel_root" />
|
||||
</record>
|
||||
</odoo>
|
||||
15
stock_location_orderpoint/data/queue_job_function.xml
Normal file
15
stock_location_orderpoint/data/queue_job_function.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo noupdate="1">
|
||||
<record
|
||||
id="job_function_stock_location_orderpoint_moves_auto_replenish"
|
||||
model="queue.job.function"
|
||||
>
|
||||
<field name="model_id" ref="model_stock_location_orderpoint" />
|
||||
<field name="method">moves_auto_replenish</field>
|
||||
<field
|
||||
name="channel_id"
|
||||
ref="channel_stock_location_orderpoint_auto_replenishment"
|
||||
/>
|
||||
<field name="retry_pattern" eval="{1: 1, 5: 5, 10: 10, 15: 30}" />
|
||||
</record>
|
||||
</odoo>
|
||||
17
stock_location_orderpoint/demo/stock_location.xml
Normal file
17
stock_location_orderpoint/demo/stock_location.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2023 ACSONE SA/NV
|
||||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
|
||||
<odoo noupdate="1">
|
||||
<record id="stock_location_replenish_view" model="stock.location">
|
||||
<field name="name">Replenishment Zone</field>
|
||||
<field
|
||||
name="location_id"
|
||||
model="stock.location"
|
||||
eval="obj().env.ref('stock.stock_location_stock').location_id"
|
||||
/>
|
||||
</record>
|
||||
<record id="stock_location_replenish" model="stock.location">
|
||||
<field name="name">Replenishment Stock</field>
|
||||
<field name="location_id" ref="stock_location_replenish_view" />
|
||||
</record>
|
||||
</odoo>
|
||||
11
stock_location_orderpoint/demo/stock_location_orderpoint.xml
Normal file
11
stock_location_orderpoint/demo/stock_location_orderpoint.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2023 ACSONE SA/NV
|
||||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
|
||||
<odoo noupdate="1">
|
||||
<record id="stock_location_orderpoint_1" model="stock.location.orderpoint">
|
||||
<field name="location_id" ref="stock.stock_location_stock" />
|
||||
<field name="route_id" ref="stock_route_replenish" />
|
||||
<field name="trigger">auto</field>
|
||||
<field name="replenish_method">fill_up</field>
|
||||
</record>
|
||||
</odoo>
|
||||
16
stock_location_orderpoint/demo/stock_picking_type.xml
Normal file
16
stock_location_orderpoint/demo/stock_picking_type.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2023 ACSONE SA/NV
|
||||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
|
||||
<odoo noupdate="1">
|
||||
<record id="stock_picking_type_replenish" model="stock.picking.type">
|
||||
<field name="name">Replenishments</field>
|
||||
<field name="code">internal</field>
|
||||
<field name="default_location_dest_id" ref="stock.stock_location_stock" />
|
||||
<field
|
||||
name="default_location_src_id"
|
||||
ref="stock_location_orderpoint.stock_location_replenish"
|
||||
/>
|
||||
<field name="warehouse_id" ref="stock.warehouse0" />
|
||||
<field name="sequence_code">SRE</field>
|
||||
</record>
|
||||
</odoo>
|
||||
24
stock_location_orderpoint/demo/stock_route.xml
Normal file
24
stock_location_orderpoint/demo/stock_route.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2023 ACSONE SA/NV
|
||||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
|
||||
<odoo noupdate="1">
|
||||
<record id="stock_route_replenish" model="stock.location.route">
|
||||
<field name="name">Replenishment Route</field>
|
||||
<field name="product_selectable" eval="False" />
|
||||
</record>
|
||||
|
||||
<record id="stock_rule_replenish" model="stock.rule">
|
||||
<field name="name">Replenishment Rule</field>
|
||||
<field
|
||||
name="location_src_id"
|
||||
ref="stock_location_orderpoint.stock_location_replenish"
|
||||
/>
|
||||
<field name="location_id" ref="stock.stock_location_stock" />
|
||||
<field name="route_id" ref="stock_location_orderpoint.stock_route_replenish" />
|
||||
<field
|
||||
name="picking_type_id"
|
||||
ref="stock_location_orderpoint.stock_picking_type_replenish"
|
||||
/>
|
||||
<field name="action">pull</field>
|
||||
</record>
|
||||
</odoo>
|
||||
4
stock_location_orderpoint/models/__init__.py
Normal file
4
stock_location_orderpoint/models/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from . import stock_location_orderpoint
|
||||
from . import stock_rule
|
||||
from . import stock_move
|
||||
from . import stock_location
|
||||
42
stock_location_orderpoint/models/stock_location.py
Normal file
42
stock_location_orderpoint/models/stock_location.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# Copyright 2023 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import fields, models
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
|
||||
|
||||
class StockLocation(models.Model):
|
||||
_inherit = "stock.location"
|
||||
|
||||
location_orderpoint_ids = fields.One2many(
|
||||
comodel_name="stock.location.orderpoint",
|
||||
inverse_name="location_id",
|
||||
string="Location Orderpoints",
|
||||
help="Location Orderpoints. Rules that allows this location to be replenished.",
|
||||
)
|
||||
location_orderpoint_count = fields.Integer(
|
||||
compute="_compute_location_orderpoint_count",
|
||||
)
|
||||
|
||||
def _compute_location_orderpoint_count(self):
|
||||
groups = self.env["stock.location.orderpoint"].read_group(
|
||||
[("location_id", "in", self.ids)], ["location_id"], ["location_id"]
|
||||
)
|
||||
result = {
|
||||
data["location_id"][0]: (data["location_id_count"]) for data in groups
|
||||
}
|
||||
for location in self:
|
||||
location.location_orderpoint_count = result.get(location.id, 0)
|
||||
|
||||
def action_open_location_orderpoints(self):
|
||||
action = self.env["ir.actions.act_window"]._for_xml_id(
|
||||
"stock_location_orderpoint.action_stock_location_orderpoint"
|
||||
)
|
||||
action["domain"] = [("location_id", "in", self.ids)]
|
||||
if len(self.ids) == 1:
|
||||
if "context" in action:
|
||||
context = safe_eval(action["context"])
|
||||
context.update({"default_location_id": self.id})
|
||||
action["context"] = str(context)
|
||||
else:
|
||||
action["context"] = str({"default_location_id": self.id})
|
||||
return action
|
||||
413
stock_location_orderpoint/models/stock_location_orderpoint.py
Normal file
413
stock_location_orderpoint/models/stock_location_orderpoint.py
Normal file
@@ -0,0 +1,413 @@
|
||||
# Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from collections import defaultdict
|
||||
from copy import copy
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.osv import expression
|
||||
from odoo.tools import float_compare, split_every
|
||||
|
||||
from odoo.addons.stock.models.stock_move import PROCUREMENT_PRIORITIES
|
||||
|
||||
|
||||
class StockLocationOrderpoint(models.Model):
|
||||
_name = "stock.location.orderpoint"
|
||||
_description = "Stock location orderpoint"
|
||||
_order = "priority desc, sequence"
|
||||
|
||||
name = fields.Char(
|
||||
"Name",
|
||||
copy=False,
|
||||
required=True,
|
||||
readonly=True,
|
||||
default=lambda self: self.env["ir.sequence"].next_by_code(
|
||||
"stock.location.orderpoint"
|
||||
),
|
||||
)
|
||||
company_id = fields.Many2one(
|
||||
"res.company",
|
||||
"Company",
|
||||
required=True,
|
||||
default=lambda self: self.env.company,
|
||||
)
|
||||
location_id = fields.Many2one(
|
||||
"stock.location",
|
||||
"Location",
|
||||
ondelete="cascade",
|
||||
required=True,
|
||||
check_company=True,
|
||||
domain='[("company_id", "=", company_id)]',
|
||||
)
|
||||
trigger = fields.Selection(
|
||||
[("auto", "Auto/realtime"), ("manual", "Manual"), ("cron", "Scheduled")],
|
||||
"Trigger",
|
||||
default="auto",
|
||||
required=True,
|
||||
help="Auto/realtime orderpoints are triggered on new moves\n"
|
||||
"Manual orderpoints are triggered via the orderpoints' view\n"
|
||||
"Scheduled orderpoints are triggered via scheduled actions per location",
|
||||
)
|
||||
replenish_method = fields.Selection(
|
||||
[("fill_up", "Fill up")],
|
||||
default="fill_up",
|
||||
required=True,
|
||||
help="Defines how the qty to replenish gets computed\n"
|
||||
"Fill up = The replenishment will be triggered when a move is waiting availability "
|
||||
"and forecast quantity is negative at the location (i.e. min=0). "
|
||||
"The replenished quantity will bring back the forecast quantity to 0 (i.e. max=0) "
|
||||
"but will be limited to what is available at the source location "
|
||||
"to plan only reservable replenishment moves",
|
||||
)
|
||||
sequence = fields.Integer("Sequence", default=10)
|
||||
route_id = fields.Many2one(
|
||||
"stock.location.route",
|
||||
string="Preferred Route",
|
||||
domain="[('rule_ids.location_id', 'in', [location_id])]",
|
||||
)
|
||||
group_id = fields.Many2one(
|
||||
"procurement.group",
|
||||
"Procurement Group",
|
||||
copy=False,
|
||||
help="Moves created through this orderpoint "
|
||||
"will be put in this procurement group. "
|
||||
"If none is given, the moves generated by stock rules "
|
||||
"will be grouped into one big picking.",
|
||||
)
|
||||
location_src_id = fields.Many2one(
|
||||
"stock.location", compute="_compute_location_src_id", store=True
|
||||
)
|
||||
active = fields.Boolean("Active", default=True)
|
||||
priority = fields.Selection(
|
||||
PROCUREMENT_PRIORITIES,
|
||||
"Priority",
|
||||
default="0",
|
||||
)
|
||||
|
||||
_sql_constraints = [
|
||||
(
|
||||
"location_route_unique",
|
||||
"unique(location_id, route_id)",
|
||||
"The combination of Company, Location and Route must be unique",
|
||||
)
|
||||
]
|
||||
|
||||
@api.constrains("location_id", "route_id")
|
||||
def _check_location_id_route_id(self):
|
||||
for orderpoint in self:
|
||||
if (
|
||||
not orderpoint.route_id
|
||||
or orderpoint.location_id in orderpoint.route_id.rule_ids.location_id
|
||||
):
|
||||
continue
|
||||
raise ValidationError(
|
||||
_(
|
||||
"The selected route {} must contain "
|
||||
"a rule where the Destination Location is {}"
|
||||
).format(
|
||||
orderpoint.route_id.display_name,
|
||||
orderpoint.location_id.display_name,
|
||||
)
|
||||
)
|
||||
|
||||
@api.depends("location_id", "route_id")
|
||||
def _compute_location_src_id(self):
|
||||
for orderpoint in self:
|
||||
location = False
|
||||
if orderpoint.location_id and orderpoint.route_id:
|
||||
location = orderpoint.location_id._get_source_location_from_route(
|
||||
orderpoint.route_id,
|
||||
"make_to_stock",
|
||||
)
|
||||
orderpoint.location_src_id = location
|
||||
|
||||
def _prepare_procurement(self, product, qty, date_planned, proc_vals):
|
||||
self.ensure_one()
|
||||
proc_vals = copy(proc_vals)
|
||||
proc_vals.update(
|
||||
{
|
||||
"date_planned": date_planned or fields.Datetime.now(),
|
||||
}
|
||||
)
|
||||
return self.env["procurement.group"].Procurement(
|
||||
product,
|
||||
qty,
|
||||
product.uom_id,
|
||||
self.location_id,
|
||||
self.name,
|
||||
self.name,
|
||||
self.company_id,
|
||||
proc_vals,
|
||||
)
|
||||
|
||||
def _prepare_procurement_values(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
"route_ids": self.route_id,
|
||||
"date_deadline": False,
|
||||
"warehouse_id": self.location_id.get_closest_warehouse(),
|
||||
"group_id": self.group_id,
|
||||
"priority": self.priority or "0",
|
||||
"location_orderpoint_id": self.id,
|
||||
}
|
||||
|
||||
def _get_waiting_move_domain(self):
|
||||
"""
|
||||
Returns a domain which selects waiting moves
|
||||
which should be replenished by given orderpoints
|
||||
"""
|
||||
domain = [
|
||||
("state", "in", ["confirmed", "partially_available"]),
|
||||
("move_orig_ids", "=", False),
|
||||
("procure_method", "=", "make_to_stock"),
|
||||
]
|
||||
location_domains = []
|
||||
for orderpoint in self:
|
||||
location_domains.append(
|
||||
[
|
||||
("location_id", "child_of", orderpoint.location_id.ids),
|
||||
"!",
|
||||
("location_dest_id", "child_of", orderpoint.location_id.ids),
|
||||
]
|
||||
)
|
||||
if location_domains:
|
||||
domain = expression.AND([domain, expression.OR(location_domains)])
|
||||
return domain
|
||||
|
||||
def _find_potential_moves_to_replenish_by_location(self, products=False):
|
||||
"""Return a dictionary of products per location that potentially require a replenishment
|
||||
based on the fact there are moves not reserved for those products.
|
||||
This reduces the list of products for which the quantity will be computed"""
|
||||
domain = self._get_waiting_move_domain()
|
||||
if products:
|
||||
domain = expression.AND([domain, [("product_id", "in", products.ids)]])
|
||||
moves_grouped = self.env["stock.move"].read_group(
|
||||
domain,
|
||||
["ids:array_agg(id)", "location_id"],
|
||||
"location_id",
|
||||
)
|
||||
return {
|
||||
self.env["stock.location"]
|
||||
.browse(res["location_id"][0]): self.env["stock.move"]
|
||||
.browse(res["ids"])
|
||||
for res in moves_grouped
|
||||
}
|
||||
|
||||
def _sort_orderpoints(self):
|
||||
return self.sorted()
|
||||
|
||||
@api.model
|
||||
def _compute_quantities_dict(self, locations, products):
|
||||
qties = {}
|
||||
for location in locations:
|
||||
qties_on_location = qties.setdefault(location, {})
|
||||
products = products.with_context(location=location.id)
|
||||
for product_id, qties_dict in products._product_available().items():
|
||||
product = products.browse(product_id)
|
||||
qties_on_location[product] = qties_dict
|
||||
return qties
|
||||
|
||||
def _get_qty_to_replenish(
|
||||
self, product, qties_on_locations, qty_already_replenished=0
|
||||
):
|
||||
"""
|
||||
Returns a qty to replenish for a given orderpoint and product
|
||||
"""
|
||||
self.ensure_one()
|
||||
product.ensure_one()
|
||||
|
||||
if self.replenish_method == "fill_up":
|
||||
return self._get_qty_to_replenish_fill_up(
|
||||
product, qties_on_locations, qty_already_replenished
|
||||
)
|
||||
return 0
|
||||
|
||||
def _get_qty_to_replenish_fill_up(
|
||||
self, product, qties_on_locations, qty_already_replenished=0
|
||||
):
|
||||
if not self.location_src_id:
|
||||
return 0
|
||||
|
||||
qties_on_dest = qties_on_locations[self.location_id][product]
|
||||
virtual_available_on_dest = qties_on_dest["virtual_available"]
|
||||
if (
|
||||
float_compare(
|
||||
virtual_available_on_dest, 0, precision_rounding=product.uom_id.rounding
|
||||
)
|
||||
>= 0
|
||||
):
|
||||
return 0
|
||||
|
||||
virtual_available_on_dest = abs(virtual_available_on_dest)
|
||||
qties_on_src = qties_on_locations[self.location_src_id][product]
|
||||
virtual_available_on_src = (
|
||||
qties_on_src["virtual_available"] - qties_on_src["incoming_qty"]
|
||||
)
|
||||
if (
|
||||
float_compare(
|
||||
virtual_available_on_src,
|
||||
0,
|
||||
precision_rounding=product.uom_id.rounding,
|
||||
)
|
||||
<= 0
|
||||
):
|
||||
return 0
|
||||
|
||||
qty_to_replenish = virtual_available_on_dest - qty_already_replenished
|
||||
return min(qty_to_replenish, virtual_available_on_src)
|
||||
|
||||
def _get_qties_to_replenish(self, moves_by_location):
|
||||
products = set()
|
||||
for moves in moves_by_location.values():
|
||||
products.update(moves.product_id.ids)
|
||||
qties_on_locations = self._compute_quantities_dict(
|
||||
(self.location_id | self.location_src_id),
|
||||
self.env["product.product"].browse(products),
|
||||
)
|
||||
qties_replenished = defaultdict(lambda: defaultdict(lambda: 0))
|
||||
qties_to_replenish = defaultdict(list)
|
||||
for orderpoint in self:
|
||||
if orderpoint.location_id not in moves_by_location:
|
||||
continue
|
||||
|
||||
for product in moves_by_location[orderpoint.location_id].product_id:
|
||||
qties_replenished_for_location = qties_replenished[
|
||||
orderpoint.location_id
|
||||
]
|
||||
qty_to_replenish = orderpoint._get_qty_to_replenish(
|
||||
product,
|
||||
qties_on_locations,
|
||||
qties_replenished_for_location[product],
|
||||
)
|
||||
if (
|
||||
float_compare(
|
||||
qty_to_replenish, 0, precision_rounding=product.uom_id.rounding
|
||||
)
|
||||
> 0
|
||||
):
|
||||
qties_to_replenish[orderpoint].append((product, qty_to_replenish))
|
||||
qties_replenished_for_location[product] += qty_to_replenish
|
||||
return qties_to_replenish
|
||||
|
||||
def __prepare_procurements(self, moves_by_location):
|
||||
qties_to_replenish_by_orderpoint = self._get_qties_to_replenish(
|
||||
moves_by_location
|
||||
)
|
||||
procurements = []
|
||||
for orderpoint, qties_to_replenish in qties_to_replenish_by_orderpoint.items():
|
||||
proc_vals = orderpoint._prepare_procurement_values()
|
||||
for product, qty in qties_to_replenish:
|
||||
date_planned = moves_by_location[
|
||||
orderpoint.location_id
|
||||
]._get_location_orderpoint_replenishment_date(product)
|
||||
procurements.append(
|
||||
orderpoint._prepare_procurement(
|
||||
product, qty, date_planned, proc_vals
|
||||
)
|
||||
)
|
||||
return procurements
|
||||
|
||||
def _prepare_procurements(self, products=False):
|
||||
moves_by_location = self._find_potential_moves_to_replenish_by_location(
|
||||
products
|
||||
)
|
||||
return self._sort_orderpoints().__prepare_procurements(moves_by_location)
|
||||
|
||||
def run_replenishment(self, products=False):
|
||||
"""Run the replenishment for all potential products or only a selection"""
|
||||
procurements = self._prepare_procurements(products)
|
||||
if not procurements:
|
||||
return
|
||||
self.env["procurement.group"].with_context(from_orderpoint=True).run(
|
||||
procurements, raise_user_error=False
|
||||
)
|
||||
self._after_replenishment()
|
||||
|
||||
def _prepare_to_assign_replenishment_move_domain(self):
|
||||
"""Returns a domain which selects moves created by a replenishment"""
|
||||
domain = [
|
||||
("state", "in", ["confirmed", "partially_available"]),
|
||||
("procure_method", "=", "make_to_stock"),
|
||||
("location_orderpoint_id", "in", self.ids),
|
||||
]
|
||||
return domain
|
||||
|
||||
def _assign_replenishment_moves(self):
|
||||
"""Assigns moves created by the orderpoints"""
|
||||
domain = self._prepare_to_assign_replenishment_move_domain()
|
||||
moves_to_assign = self.env["stock.move"].search(
|
||||
domain, order="priority desc, date asc, id asc"
|
||||
)
|
||||
for moves_chunk in split_every(100, moves_to_assign.ids):
|
||||
self.env["stock.move"].browse(moves_chunk)._action_assign()
|
||||
|
||||
def _after_replenishment(self):
|
||||
self._assign_replenishment_moves()
|
||||
|
||||
@api.model
|
||||
def _prepare_orderpoint_domain_location(self, location_ids, location_field=False):
|
||||
"""
|
||||
Returns the domain part of the location selection of _get_orderpoints
|
||||
:param list int location_ids: list of stock.location ids
|
||||
:param str location_field: location_id or location_src_id
|
||||
To create the domain searching the specific location field
|
||||
"""
|
||||
ids = location_ids
|
||||
if not isinstance(ids, list):
|
||||
ids = ids.ids
|
||||
|
||||
location_field = not location_field and "location_id" or location_field
|
||||
return [(location_field, "parent_of", ids)]
|
||||
|
||||
def _prepare_orderpoint_domain(
|
||||
self, trigger, locations=False, location_field=False
|
||||
):
|
||||
"""Returns the domain for _get_orderpoints"""
|
||||
domain = [("trigger", "=", trigger)]
|
||||
if locations:
|
||||
domain = expression.AND(
|
||||
[
|
||||
domain,
|
||||
self._prepare_orderpoint_domain_location(locations, location_field),
|
||||
]
|
||||
)
|
||||
return domain
|
||||
|
||||
@api.model
|
||||
def _get_orderpoints(self, trigger, locations=False, location_field=False):
|
||||
"""Returns orderpoints selected by trigger, locations and location_field"""
|
||||
domain = self._prepare_orderpoint_domain(trigger, locations, location_field)
|
||||
return self.search(domain)
|
||||
|
||||
def _is_location_parent_of(self, location, location_field):
|
||||
"""
|
||||
Checks if one location of the given orderpoints
|
||||
is a parent of the given location
|
||||
|
||||
:param location: browse record of stock.location
|
||||
:param location_field: should be location_id or location_src_id
|
||||
orderpoints location field to check against
|
||||
"""
|
||||
for parent_location in getattr(self, location_field):
|
||||
if location.parent_path.startswith(parent_location.parent_path):
|
||||
return True
|
||||
|
||||
@api.model
|
||||
def run_auto_replenishment(self, products, locations, location_field=False):
|
||||
"""
|
||||
Run the replenishment for all given products
|
||||
Selects the right orderpoints by locations and location_field
|
||||
|
||||
:param products: browse record list of product.product
|
||||
:param locations: browse record list of stock.location
|
||||
:param location_field: should be location_id or location_src_id
|
||||
"""
|
||||
if not locations or not products:
|
||||
return
|
||||
self = self._get_orderpoints("auto", locations, location_field)
|
||||
self.run_replenishment(products)
|
||||
|
||||
@api.model
|
||||
def run_cron_replenishment(self, location_ids=False):
|
||||
self = self._get_orderpoints("cron", location_ids)
|
||||
self.run_replenishment()
|
||||
106
stock_location_orderpoint/models/stock_move.py
Normal file
106
stock_location_orderpoint/models/stock_move.py
Normal file
@@ -0,0 +1,106 @@
|
||||
# Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from collections import defaultdict
|
||||
|
||||
from odoo import _, fields, models
|
||||
from odoo.tools import ormcache
|
||||
|
||||
from odoo.addons.queue_job.job import identity_exact
|
||||
|
||||
|
||||
class StockMove(models.Model):
|
||||
_inherit = "stock.move"
|
||||
|
||||
location_orderpoint_id = fields.Many2one(
|
||||
"stock.location.orderpoint", "Stock location orderpoint"
|
||||
)
|
||||
|
||||
@ormcache("self", "product")
|
||||
def _get_location_orderpoint_replenishment_date(self, product):
|
||||
return min(
|
||||
self.filtered(lambda move: move.product_id == product).mapped("date")
|
||||
)
|
||||
|
||||
def _prepare_auto_replenishment_for_waiting_moves(self):
|
||||
self._prepare_auto_replenishment(
|
||||
"location_id",
|
||||
self.env["stock.location.orderpoint"]._get_waiting_move_domain(),
|
||||
)
|
||||
|
||||
def _prepare_auto_replenishment_for_done_moves(self):
|
||||
self._prepare_auto_replenishment(
|
||||
"location_dest_id",
|
||||
[
|
||||
("move_dest_ids", "=", False),
|
||||
("procure_method", "=", "make_to_stock"),
|
||||
("state", "=", "done"),
|
||||
],
|
||||
)
|
||||
|
||||
def _prepare_auto_replenishment(self, location_field, domain):
|
||||
if self.env.context.get("skip_auto_replenishment"):
|
||||
return
|
||||
locations_products = defaultdict(set)
|
||||
location_ids = set()
|
||||
product_obj = self.env["product.product"]
|
||||
for move in self.filtered_domain(domain):
|
||||
location = getattr(move, location_field)
|
||||
locations_products[location].add(move.product_id.id)
|
||||
location_ids.add(location.id)
|
||||
# Map the the move's location field
|
||||
# to the correspoding stock.location.orderpoint's location field
|
||||
location_field = (
|
||||
location_field == "location_id" and location_field or "location_src_id"
|
||||
)
|
||||
orderpoints = self.env["stock.location.orderpoint"]._get_orderpoints(
|
||||
"auto", list(location_ids), location_field
|
||||
)
|
||||
for location, products in locations_products.items():
|
||||
if not orderpoints._is_location_parent_of(location, location_field):
|
||||
continue
|
||||
for product in product_obj.browse(products):
|
||||
self._enqueue_auto_replenishment(
|
||||
location, product, location_field
|
||||
).delay()
|
||||
|
||||
def _enqueue_auto_replenishment(
|
||||
self, location, product, location_field, **job_options
|
||||
):
|
||||
"""Enqueue a job stock.location.orderpoint.moves_auto_replenishment()
|
||||
|
||||
Can be extended to pass different options to the job (priority, ...).
|
||||
The usage of `.setdefault` allows to override the options set by default.
|
||||
|
||||
return: a `Job` instance
|
||||
"""
|
||||
job_options = job_options.copy()
|
||||
job_options.setdefault(
|
||||
"description",
|
||||
_("Try to replenish quantities for location {} and product {}").format(
|
||||
location.display_name, product.display_name
|
||||
),
|
||||
)
|
||||
# do not enqueue 2 jobs for the same location and product set
|
||||
job_options.setdefault("identity_key", identity_exact)
|
||||
delayable = self.env["stock.location.orderpoint"].delayable(**job_options)
|
||||
job = delayable.run_auto_replenishment(
|
||||
product,
|
||||
location,
|
||||
location_field,
|
||||
)
|
||||
return job
|
||||
|
||||
def _action_assign(self, *args, **kwargs):
|
||||
"""This triggers the replenishment for new moves which are waiting for stock"""
|
||||
res = super()._action_assign(*args, **kwargs)
|
||||
self._prepare_auto_replenishment_for_waiting_moves()
|
||||
return res
|
||||
|
||||
def _action_done(self, *args, **kwargs):
|
||||
"""
|
||||
This triggers the replenishment for waiting moves
|
||||
when the stock increases on a source location of an orderpoint
|
||||
"""
|
||||
moves = super()._action_done(*args, **kwargs)
|
||||
moves._prepare_auto_replenishment_for_done_moves()
|
||||
return moves
|
||||
11
stock_location_orderpoint/models/stock_rule.py
Normal file
11
stock_location_orderpoint/models/stock_rule.py
Normal file
@@ -0,0 +1,11 @@
|
||||
# Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import models
|
||||
|
||||
|
||||
class StockRule(models.Model):
|
||||
_inherit = "stock.rule"
|
||||
|
||||
def _get_custom_move_fields(self):
|
||||
res = super()._get_custom_move_fields()
|
||||
return res + ["location_orderpoint_id"]
|
||||
51
stock_location_orderpoint/readme/CONFIGURE.rst
Normal file
51
stock_location_orderpoint/readme/CONFIGURE.rst
Normal file
@@ -0,0 +1,51 @@
|
||||
First configuration
|
||||
===================
|
||||
|
||||
#. In order to replenish your stock location from another one, you first need
|
||||
to set the multi locations configuration.
|
||||
#. So, go to Inventory > Configuration > Settings > Warehouse
|
||||
#. Check the 'Storage Locations' box.
|
||||
#. As you should be able to configure a dedicated route to replenishment, you
|
||||
should also activate, in the same menu, the 'Multi-Step Routes' box.
|
||||
|
||||
Locations configuration
|
||||
=======================
|
||||
|
||||
#. Identify the location you want to apply a replenishment rule (e.g.: WH/Stock)
|
||||
#. Create (if not exists) a new location for replenishment under Warehouse view (e.g.: WH)
|
||||
location as we want to get the stock in replenishment taken into account of
|
||||
our product stock total quantity.
|
||||
|
||||
Route Configuration
|
||||
===================
|
||||
|
||||
#. You should configure at least a route with a rule that:
|
||||
|
||||
* Pull from the Replenishment stock location.
|
||||
* For the stock location you want to (e.g.: WH/Stock)
|
||||
|
||||
Location Orderpoint configuration
|
||||
=================================
|
||||
|
||||
#. Go either by the stock location you want to replenish and click on 'Orderpoints'
|
||||
or go to Inventory > Configuration > Settings > Warehouse > Stock Location Orderpoint
|
||||
#. Click on 'Create'
|
||||
#. Set a sequence
|
||||
#. Choose if the rule will be applied:
|
||||
|
||||
* Automatically (Auto/realtime): at each stock movement on the stock location, the rule will be
|
||||
evaluated.
|
||||
* Manually (Manual): If set, an action 'Run Replenishment' will be displayed on the rule
|
||||
and allow to run it manually.
|
||||
* by cron (Scheduled): A cron job will trigger the replenishment rules of this kind.
|
||||
#. Choose a replenish method:
|
||||
|
||||
* Fill up: The replenishment will be triggered when a move is waiting availability
|
||||
and forecast quantity is negative at the location (i.e. min=0). The replenished quantity will
|
||||
bring back the forecast quantity to 0 (i.e. max=0) but will be limited to what is available at
|
||||
the source location to plan only reservable replenishment moves.
|
||||
#. Choose the location to replenish
|
||||
#. Choose the route to use to replenish. The source location will be computed automatically based on
|
||||
the route value.
|
||||
#. Define a procurement group if you want to group some movements together.
|
||||
#. Define a priority for the created moves.
|
||||
3
stock_location_orderpoint/readme/CONTRIBUTORS.rst
Normal file
3
stock_location_orderpoint/readme/CONTRIBUTORS.rst
Normal file
@@ -0,0 +1,3 @@
|
||||
* Michael Tietz (MT Software) <mtietz@mt-software.de>
|
||||
* Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
|
||||
* Denis Roussel <denis.roussel@acsone.eu>
|
||||
2
stock_location_orderpoint/readme/DESCRIPTION.rst
Normal file
2
stock_location_orderpoint/readme/DESCRIPTION.rst
Normal file
@@ -0,0 +1,2 @@
|
||||
Declare orderpoint on a location allowing to replenish any product with the same criteria.
|
||||
This is for an internal warehouse replenishment currently not compatible with the purchase buy route.
|
||||
3
stock_location_orderpoint/security/ir.model.access.csv
Normal file
3
stock_location_orderpoint/security/ir.model.access.csv
Normal file
@@ -0,0 +1,3 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_stock_location_orderpoint_manager,stock.location.orderpoint - manager,model_stock_location_orderpoint,stock.group_stock_manager,1,1,1,1
|
||||
access_stock_location_orderpoint_user,stock.location.orderpoint - user,model_stock_location_orderpoint,stock.group_stock_user,1,0,0,0
|
||||
|
424
stock_location_orderpoint/static/description/index.html
Normal file
424
stock_location_orderpoint/static/description/index.html
Normal file
@@ -0,0 +1,424 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
|
||||
<title>stock_location_orderpoint</title>
|
||||
<style type="text/css">
|
||||
|
||||
/*
|
||||
:Author: David Goodger (goodger@python.org)
|
||||
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
|
||||
:Copyright: This stylesheet has been placed in the public domain.
|
||||
|
||||
Default cascading style sheet for the HTML output of Docutils.
|
||||
|
||||
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
|
||||
customize this style sheet.
|
||||
*/
|
||||
|
||||
/* used to remove borders from tables and images */
|
||||
.borderless, table.borderless td, table.borderless th {
|
||||
border: 0 }
|
||||
|
||||
table.borderless td, table.borderless th {
|
||||
/* Override padding for "table.docutils td" with "! important".
|
||||
The right padding separates the table cells. */
|
||||
padding: 0 0.5em 0 0 ! important }
|
||||
|
||||
.first {
|
||||
/* Override more specific margin styles with "! important". */
|
||||
margin-top: 0 ! important }
|
||||
|
||||
.last, .with-subtitle {
|
||||
margin-bottom: 0 ! important }
|
||||
|
||||
.hidden {
|
||||
display: none }
|
||||
|
||||
.subscript {
|
||||
vertical-align: sub;
|
||||
font-size: smaller }
|
||||
|
||||
.superscript {
|
||||
vertical-align: super;
|
||||
font-size: smaller }
|
||||
|
||||
a.toc-backref {
|
||||
text-decoration: none ;
|
||||
color: black }
|
||||
|
||||
blockquote.epigraph {
|
||||
margin: 2em 5em ; }
|
||||
|
||||
dl.docutils dd {
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Uncomment (and remove this text!) to get bold-faced definition list terms
|
||||
dl.docutils dt {
|
||||
font-weight: bold }
|
||||
*/
|
||||
|
||||
div.abstract {
|
||||
margin: 2em 5em }
|
||||
|
||||
div.abstract p.topic-title {
|
||||
font-weight: bold ;
|
||||
text-align: center }
|
||||
|
||||
div.admonition, div.attention, div.caution, div.danger, div.error,
|
||||
div.hint, div.important, div.note, div.tip, div.warning {
|
||||
margin: 2em ;
|
||||
border: medium outset ;
|
||||
padding: 1em }
|
||||
|
||||
div.admonition p.admonition-title, div.hint p.admonition-title,
|
||||
div.important p.admonition-title, div.note p.admonition-title,
|
||||
div.tip p.admonition-title {
|
||||
font-weight: bold ;
|
||||
font-family: sans-serif }
|
||||
|
||||
div.attention p.admonition-title, div.caution p.admonition-title,
|
||||
div.danger p.admonition-title, div.error p.admonition-title,
|
||||
div.warning p.admonition-title, .code .error {
|
||||
color: red ;
|
||||
font-weight: bold ;
|
||||
font-family: sans-serif }
|
||||
|
||||
/* Uncomment (and remove this text!) to get reduced vertical space in
|
||||
compound paragraphs.
|
||||
div.compound .compound-first, div.compound .compound-middle {
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
div.compound .compound-last, div.compound .compound-middle {
|
||||
margin-top: 0.5em }
|
||||
*/
|
||||
|
||||
div.dedication {
|
||||
margin: 2em 5em ;
|
||||
text-align: center ;
|
||||
font-style: italic }
|
||||
|
||||
div.dedication p.topic-title {
|
||||
font-weight: bold ;
|
||||
font-style: normal }
|
||||
|
||||
div.figure {
|
||||
margin-left: 2em ;
|
||||
margin-right: 2em }
|
||||
|
||||
div.footer, div.header {
|
||||
clear: both;
|
||||
font-size: smaller }
|
||||
|
||||
div.line-block {
|
||||
display: block ;
|
||||
margin-top: 1em ;
|
||||
margin-bottom: 1em }
|
||||
|
||||
div.line-block div.line-block {
|
||||
margin-top: 0 ;
|
||||
margin-bottom: 0 ;
|
||||
margin-left: 1.5em }
|
||||
|
||||
div.sidebar {
|
||||
margin: 0 0 0.5em 1em ;
|
||||
border: medium outset ;
|
||||
padding: 1em ;
|
||||
background-color: #ffffee ;
|
||||
width: 40% ;
|
||||
float: right ;
|
||||
clear: right }
|
||||
|
||||
div.sidebar p.rubric {
|
||||
font-family: sans-serif ;
|
||||
font-size: medium }
|
||||
|
||||
div.system-messages {
|
||||
margin: 5em }
|
||||
|
||||
div.system-messages h1 {
|
||||
color: red }
|
||||
|
||||
div.system-message {
|
||||
border: medium outset ;
|
||||
padding: 1em }
|
||||
|
||||
div.system-message p.system-message-title {
|
||||
color: red ;
|
||||
font-weight: bold }
|
||||
|
||||
div.topic {
|
||||
margin: 2em }
|
||||
|
||||
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
|
||||
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
|
||||
margin-top: 0.4em }
|
||||
|
||||
h1.title {
|
||||
text-align: center }
|
||||
|
||||
h2.subtitle {
|
||||
text-align: center }
|
||||
|
||||
hr.docutils {
|
||||
width: 75% }
|
||||
|
||||
img.align-left, .figure.align-left, object.align-left, table.align-left {
|
||||
clear: left ;
|
||||
float: left ;
|
||||
margin-right: 1em }
|
||||
|
||||
img.align-right, .figure.align-right, object.align-right, table.align-right {
|
||||
clear: right ;
|
||||
float: right ;
|
||||
margin-left: 1em }
|
||||
|
||||
img.align-center, .figure.align-center, object.align-center {
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
table.align-center {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.align-left {
|
||||
text-align: left }
|
||||
|
||||
.align-center {
|
||||
clear: both ;
|
||||
text-align: center }
|
||||
|
||||
.align-right {
|
||||
text-align: right }
|
||||
|
||||
/* reset inner alignment in figures */
|
||||
div.align-right {
|
||||
text-align: inherit }
|
||||
|
||||
/* div.align-center * { */
|
||||
/* text-align: left } */
|
||||
|
||||
.align-top {
|
||||
vertical-align: top }
|
||||
|
||||
.align-middle {
|
||||
vertical-align: middle }
|
||||
|
||||
.align-bottom {
|
||||
vertical-align: bottom }
|
||||
|
||||
ol.simple, ul.simple {
|
||||
margin-bottom: 1em }
|
||||
|
||||
ol.arabic {
|
||||
list-style: decimal }
|
||||
|
||||
ol.loweralpha {
|
||||
list-style: lower-alpha }
|
||||
|
||||
ol.upperalpha {
|
||||
list-style: upper-alpha }
|
||||
|
||||
ol.lowerroman {
|
||||
list-style: lower-roman }
|
||||
|
||||
ol.upperroman {
|
||||
list-style: upper-roman }
|
||||
|
||||
p.attribution {
|
||||
text-align: right ;
|
||||
margin-left: 50% }
|
||||
|
||||
p.caption {
|
||||
font-style: italic }
|
||||
|
||||
p.credits {
|
||||
font-style: italic ;
|
||||
font-size: smaller }
|
||||
|
||||
p.label {
|
||||
white-space: nowrap }
|
||||
|
||||
p.rubric {
|
||||
font-weight: bold ;
|
||||
font-size: larger ;
|
||||
color: maroon ;
|
||||
text-align: center }
|
||||
|
||||
p.sidebar-title {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold ;
|
||||
font-size: larger }
|
||||
|
||||
p.sidebar-subtitle {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold }
|
||||
|
||||
p.topic-title {
|
||||
font-weight: bold }
|
||||
|
||||
pre.address {
|
||||
margin-bottom: 0 ;
|
||||
margin-top: 0 ;
|
||||
font: inherit }
|
||||
|
||||
pre.literal-block, pre.doctest-block, pre.math, pre.code {
|
||||
margin-left: 2em ;
|
||||
margin-right: 2em }
|
||||
|
||||
pre.code .ln { color: grey; } /* line numbers */
|
||||
pre.code, code { background-color: #eeeeee }
|
||||
pre.code .comment, code .comment { color: #5C6576 }
|
||||
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
|
||||
pre.code .literal.string, code .literal.string { color: #0C5404 }
|
||||
pre.code .name.builtin, code .name.builtin { color: #352B84 }
|
||||
pre.code .deleted, code .deleted { background-color: #DEB0A1}
|
||||
pre.code .inserted, code .inserted { background-color: #A3D289}
|
||||
|
||||
span.classifier {
|
||||
font-family: sans-serif ;
|
||||
font-style: oblique }
|
||||
|
||||
span.classifier-delimiter {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold }
|
||||
|
||||
span.interpreted {
|
||||
font-family: sans-serif }
|
||||
|
||||
span.option {
|
||||
white-space: nowrap }
|
||||
|
||||
span.pre {
|
||||
white-space: pre }
|
||||
|
||||
span.problematic {
|
||||
color: red }
|
||||
|
||||
span.section-subtitle {
|
||||
/* font-size relative to parent (h1..h6 element) */
|
||||
font-size: 80% }
|
||||
|
||||
table.citation {
|
||||
border-left: solid 1px gray;
|
||||
margin-left: 1px }
|
||||
|
||||
table.docinfo {
|
||||
margin: 2em 4em }
|
||||
|
||||
table.docutils {
|
||||
margin-top: 0.5em ;
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
table.footnote {
|
||||
border-left: solid 1px black;
|
||||
margin-left: 1px }
|
||||
|
||||
table.docutils td, table.docutils th,
|
||||
table.docinfo td, table.docinfo th {
|
||||
padding-left: 0.5em ;
|
||||
padding-right: 0.5em ;
|
||||
vertical-align: top }
|
||||
|
||||
table.docutils th.field-name, table.docinfo th.docinfo-name {
|
||||
font-weight: bold ;
|
||||
text-align: left ;
|
||||
white-space: nowrap ;
|
||||
padding-left: 0 }
|
||||
|
||||
/* "booktabs" style (no vertical lines) */
|
||||
table.docutils.booktabs {
|
||||
border: 0px;
|
||||
border-top: 2px solid;
|
||||
border-bottom: 2px solid;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
table.docutils.booktabs * {
|
||||
border: 0px;
|
||||
}
|
||||
table.docutils.booktabs th {
|
||||
border-bottom: thin solid;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
|
||||
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
|
||||
font-size: 100% }
|
||||
|
||||
ul.auto-toc {
|
||||
list-style-type: none }
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="document" id="stock-location-orderpoint">
|
||||
<h1 class="title">stock_location_orderpoint</h1>
|
||||
|
||||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_location_orderpoint"><img alt="OCA/stock-logistics-warehouse" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/stock-logistics-warehouse-14-0/stock-logistics-warehouse-14-0-stock_location_orderpoint"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runboat.odoo-community.org/webui/builds.html?repo=OCA/stock-logistics-warehouse&target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
|
||||
<p>Declare orderpoint on a location allowing to replenish any product with the same criteria.
|
||||
This is for an internal warehouse replenishment currently not compatible with the purchase buy route.</p>
|
||||
<p><strong>Table of contents</strong></p>
|
||||
<div class="contents local topic" id="contents">
|
||||
<ul class="simple">
|
||||
<li><a class="reference internal" href="#bug-tracker" id="id1">Bug Tracker</a></li>
|
||||
<li><a class="reference internal" href="#credits" id="id2">Credits</a><ul>
|
||||
<li><a class="reference internal" href="#authors" id="id3">Authors</a></li>
|
||||
<li><a class="reference internal" href="#contributors" id="id4">Contributors</a></li>
|
||||
<li><a class="reference internal" href="#maintainers" id="id5">Maintainers</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="bug-tracker">
|
||||
<h1><a class="toc-backref" href="#id1">Bug Tracker</a></h1>
|
||||
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/issues">GitHub Issues</a>.
|
||||
In case of trouble, please check there if your issue has already been reported.
|
||||
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
||||
<a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_location_orderpoint%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
|
||||
<p>Do not contact contributors directly about support or help with technical issues.</p>
|
||||
</div>
|
||||
<div class="section" id="credits">
|
||||
<h1><a class="toc-backref" href="#id2">Credits</a></h1>
|
||||
<div class="section" id="authors">
|
||||
<h2><a class="toc-backref" href="#id3">Authors</a></h2>
|
||||
<ul class="simple">
|
||||
<li>MT Software</li>
|
||||
<li>BCIM</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="contributors">
|
||||
<h2><a class="toc-backref" href="#id4">Contributors</a></h2>
|
||||
<ul class="simple">
|
||||
<li>Michael Tietz (MT Software) <<a class="reference external" href="mailto:mtietz@mt-software.de">mtietz@mt-software.de</a>></li>
|
||||
<li>Jacques-Etienne Baudoux (BCIM) <<a class="reference external" href="mailto:je@bcim.be">je@bcim.be</a>></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="maintainers">
|
||||
<h2><a class="toc-backref" href="#id5">Maintainers</a></h2>
|
||||
<p>This module is maintained by the OCA.</p>
|
||||
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
|
||||
<p>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.</p>
|
||||
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
|
||||
<p><a class="reference external" href="https://github.com/mt-software-de"><img alt="mt-software-de" src="https://github.com/mt-software-de.png?size=40px" /></a></p>
|
||||
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_location_orderpoint">OCA/stock-logistics-warehouse</a> project on GitHub.</p>
|
||||
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
1
stock_location_orderpoint/tests/__init__.py
Normal file
1
stock_location_orderpoint/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import test_location_orderpoint
|
||||
162
stock_location_orderpoint/tests/common.py
Normal file
162
stock_location_orderpoint/tests/common.py
Normal file
@@ -0,0 +1,162 @@
|
||||
# Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from datetime import datetime
|
||||
|
||||
from odoo.tests.common import Form, SavepointCase
|
||||
|
||||
|
||||
class TestLocationOrderpointCommon(SavepointCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.uom_unit = cls.env.ref("uom.product_uom_unit")
|
||||
cls.product = cls.env["product.product"].create(
|
||||
{
|
||||
"name": "Desk Combination",
|
||||
"type": "product",
|
||||
}
|
||||
)
|
||||
cls.warehouse = cls.env.ref("stock.warehouse0")
|
||||
cls.location_dest = cls.warehouse.lot_stock_id
|
||||
cls.env["stock.location.orderpoint"].search([]).write({"active": False})
|
||||
|
||||
def _create_picking_type(self, name, location_src, location_dest, warehouse):
|
||||
return self.env["stock.picking.type"].create(
|
||||
{
|
||||
"name": name,
|
||||
"sequence_code": f"INT/REPL/{location_src.name}",
|
||||
"default_location_src_id": location_src.id,
|
||||
"default_location_dest_id": location_dest.id,
|
||||
"code": "internal",
|
||||
"warehouse_id": warehouse.id,
|
||||
"show_operations": True,
|
||||
}
|
||||
)
|
||||
|
||||
def _create_route(self, name, picking_type, location_src, location_dest, warehouse):
|
||||
return self.env["stock.location.route"].create(
|
||||
{
|
||||
"name": name,
|
||||
"sequence": 0,
|
||||
"rule_ids": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": name,
|
||||
"action": "pull",
|
||||
"location_id": location_dest.id,
|
||||
"location_src_id": location_src.id,
|
||||
"picking_type_id": picking_type.id,
|
||||
"warehouse_id": warehouse.id,
|
||||
},
|
||||
)
|
||||
],
|
||||
"warehouse_ids": [(6, 0, warehouse.ids)],
|
||||
}
|
||||
)
|
||||
|
||||
def _create_picking_type_route_rule(self, location):
|
||||
name = "Internal Replenishment"
|
||||
name = f"{name}-{location.name}"
|
||||
picking_type = self._create_picking_type(
|
||||
name, location, self.location_dest, self.warehouse
|
||||
)
|
||||
route = self._create_route(
|
||||
name, picking_type, location, self.location_dest, self.warehouse
|
||||
)
|
||||
return picking_type, route
|
||||
|
||||
def _create_orderpoint(self, **kwargs):
|
||||
location_orderpoint = Form(self.env["stock.location.orderpoint"])
|
||||
location_orderpoint.location_id = self.location_dest
|
||||
for field, value in kwargs.items():
|
||||
setattr(location_orderpoint, field, value)
|
||||
return location_orderpoint.save()
|
||||
|
||||
def _create_move(self, name, qty, location, location_dest):
|
||||
move = self.env["stock.move"].create(
|
||||
{
|
||||
"name": name,
|
||||
"date": datetime.today(),
|
||||
"product_id": self.product.id,
|
||||
"product_uom": self.uom_unit.id,
|
||||
"product_uom_qty": qty,
|
||||
"location_id": location.id,
|
||||
"location_dest_id": location_dest.id,
|
||||
}
|
||||
)
|
||||
move._write({"create_date": datetime.now()})
|
||||
move._action_confirm()
|
||||
return move
|
||||
|
||||
def _create_scrap_move(self, qty, location):
|
||||
scrap = self.env["stock.location"].search(
|
||||
[("scrap_location", "=", True)], limit=1
|
||||
)
|
||||
move = self._create_move("Scrap", qty, location, scrap)
|
||||
move.move_line_ids.write({"qty_done": qty})
|
||||
move._action_done()
|
||||
return move
|
||||
|
||||
def _create_incoming_move(self, qty, location):
|
||||
move = self._create_move(
|
||||
"Receive", qty, self.env.ref("stock.stock_location_suppliers"), location
|
||||
)
|
||||
move.move_line_ids.write({"qty_done": qty})
|
||||
move._action_done()
|
||||
return move
|
||||
|
||||
def _create_outgoing_move(self, qty, location=None):
|
||||
move = self._create_move(
|
||||
"Delivery",
|
||||
qty,
|
||||
location or self.location_dest,
|
||||
self.env.ref("stock.stock_location_customers"),
|
||||
)
|
||||
move._action_assign()
|
||||
return move
|
||||
|
||||
def _create_quants(self, product, location, qty):
|
||||
self.env["stock.quant"].create(
|
||||
{
|
||||
"product_id": product.id,
|
||||
"location_id": location.id,
|
||||
"quantity": qty,
|
||||
}
|
||||
)
|
||||
|
||||
def _run_replenishment(self, orderpoints):
|
||||
self.product.invalidate_cache()
|
||||
orderpoints.run_replenishment()
|
||||
|
||||
def _get_replenishment_move(self, orderpoints):
|
||||
return self.env["stock.move"].search(
|
||||
[
|
||||
("origin", "in", orderpoints.mapped("name")),
|
||||
("product_id", "=", self.product.id),
|
||||
("state", "!=", "cancel"),
|
||||
]
|
||||
)
|
||||
|
||||
def _check_replenishment_move(self, move, qty, orderpoint):
|
||||
self.assertEqual(move.rule_id, orderpoint.route_id.rule_ids)
|
||||
self.assertEqual(move.location_orderpoint_id, orderpoint)
|
||||
self.assertEqual(move.product_qty, qty)
|
||||
self.assertEqual(move.location_id, orderpoint.location_src_id)
|
||||
self.assertEqual(move.location_dest_id, orderpoint.location_id)
|
||||
self.assertEqual(move.state, "assigned")
|
||||
self.assertEqual(move.priority, orderpoint.priority)
|
||||
|
||||
def _create_location(self, name):
|
||||
return self.env["stock.location"].create(
|
||||
{"name": name, "location_id": self.location_dest.location_id.id}
|
||||
)
|
||||
|
||||
def _create_orderpoint_complete(self, location_name, **kwargs):
|
||||
location = self._create_location(location_name)
|
||||
picking_type, route = self._create_picking_type_route_rule(location)
|
||||
values = kwargs or {}
|
||||
values.update({"route_id": route})
|
||||
orderpoint = self._create_orderpoint(**values)
|
||||
return orderpoint, location
|
||||
193
stock_location_orderpoint/tests/test_location_orderpoint.py
Normal file
193
stock_location_orderpoint/tests/test_location_orderpoint.py
Normal file
@@ -0,0 +1,193 @@
|
||||
# Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from psycopg2 import IntegrityError
|
||||
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
from odoo.addons.queue_job.job import identity_exact
|
||||
from odoo.addons.queue_job.tests.common import trap_jobs
|
||||
|
||||
from .common import TestLocationOrderpointCommon
|
||||
|
||||
|
||||
class TestLocationOrderpoint(TestLocationOrderpointCommon):
|
||||
def test_manual_replenishment(self):
|
||||
orderpoint, location_src = self._create_orderpoint_complete(
|
||||
"Stock2", trigger="manual"
|
||||
)
|
||||
orderpoint2, location_src2 = self._create_orderpoint_complete(
|
||||
"Stock2.2", trigger="manual"
|
||||
)
|
||||
|
||||
self.assertEqual(orderpoint.location_src_id, location_src)
|
||||
move = self._create_outgoing_move(12)
|
||||
move = self._create_outgoing_move(1)
|
||||
self.assertEqual(move.state, "confirmed")
|
||||
|
||||
orderpoints = orderpoint | orderpoint2
|
||||
self._run_replenishment(orderpoints)
|
||||
|
||||
replenish_move = self._get_replenishment_move(orderpoints)
|
||||
self.assertFalse(replenish_move)
|
||||
|
||||
self._create_quants(self.product, location_src, 12)
|
||||
|
||||
self._run_replenishment(orderpoints)
|
||||
replenish_move = self._get_replenishment_move(orderpoints)
|
||||
self._check_replenishment_move(replenish_move, 12, orderpoint)
|
||||
|
||||
replenish_move._action_cancel()
|
||||
|
||||
self._create_quants(self.product, location_src2, 12)
|
||||
self._run_replenishment(orderpoints)
|
||||
|
||||
replenish_moves = self._get_replenishment_move(orderpoints)
|
||||
self.assertEqual(len(replenish_moves), 2)
|
||||
self.assertEqual(sum(replenish_moves.mapped("product_qty")), 13)
|
||||
|
||||
move = replenish_moves.filtered(
|
||||
lambda _move: _move.rule_id == orderpoint.route_id.rule_ids
|
||||
)
|
||||
self._check_replenishment_move(move, 12, orderpoint)
|
||||
|
||||
move = replenish_moves - move
|
||||
self._check_replenishment_move(move, 1, orderpoint2)
|
||||
|
||||
def test_check_unique(self):
|
||||
orderpoint, location_src = self._create_orderpoint_complete("Stock2")
|
||||
with mute_logger("odoo.sql_db"):
|
||||
with self.assertRaises(IntegrityError):
|
||||
self._create_orderpoint(route_id=orderpoint.route_id)
|
||||
|
||||
def test_check_constrains(self):
|
||||
with self.assertRaises(ValidationError):
|
||||
self._create_orderpoint(route_id=self.warehouse.delivery_route_id)
|
||||
|
||||
def test_cron_replenishment(self):
|
||||
cron = self.env.ref("stock_location_orderpoint.ir_cron_location_replenishment")
|
||||
orderpoint, location_src = self._create_orderpoint_complete(
|
||||
"Stock2", trigger="cron"
|
||||
)
|
||||
self._create_outgoing_move(12)
|
||||
|
||||
self.product.invalidate_cache()
|
||||
cron.method_direct_trigger()
|
||||
|
||||
replenish_move = self._get_replenishment_move(orderpoint)
|
||||
self.assertFalse(replenish_move)
|
||||
|
||||
self._create_quants(self.product, location_src, 12)
|
||||
|
||||
self.product.invalidate_cache()
|
||||
cron.method_direct_trigger()
|
||||
|
||||
replenish_move = self._get_replenishment_move(orderpoint)
|
||||
self._check_replenishment_move(replenish_move, 12, orderpoint)
|
||||
|
||||
def test_auto_replenishment(self):
|
||||
job_func = self.env["stock.location.orderpoint"].run_auto_replenishment
|
||||
move_qty = 12
|
||||
with trap_jobs() as trap:
|
||||
move = self._create_outgoing_move(move_qty)
|
||||
trap.assert_jobs_count(0, only=job_func)
|
||||
trap.perform_enqueued_jobs()
|
||||
replenish_move = self.env["stock.move"].search(
|
||||
[
|
||||
("product_id", "=", move.product_id.id),
|
||||
("location_dest_id", "=", move.location_id.id),
|
||||
]
|
||||
)
|
||||
self.assertFalse(replenish_move)
|
||||
|
||||
orderpoint, location_src = self._create_orderpoint_complete(
|
||||
"Stock2", trigger="auto"
|
||||
)
|
||||
with trap_jobs() as trap:
|
||||
move = self._create_outgoing_move(move_qty)
|
||||
trap.assert_jobs_count(1, only=job_func)
|
||||
trap.assert_enqueued_job(
|
||||
orderpoint.run_auto_replenishment,
|
||||
args=(move.product_id, move.location_id, "location_id"),
|
||||
kwargs={},
|
||||
properties=dict(
|
||||
identity_key=identity_exact,
|
||||
),
|
||||
)
|
||||
self.product.invalidate_cache()
|
||||
trap.perform_enqueued_jobs()
|
||||
replenish_move = self._get_replenishment_move(orderpoint)
|
||||
self.assertFalse(replenish_move)
|
||||
|
||||
with trap_jobs() as trap:
|
||||
move = self._create_incoming_move(move_qty, location_src)
|
||||
trap.assert_jobs_count(1, only=job_func)
|
||||
trap.assert_enqueued_job(
|
||||
orderpoint.run_auto_replenishment,
|
||||
args=(move.product_id, move.location_dest_id, "location_src_id"),
|
||||
kwargs={},
|
||||
properties=dict(
|
||||
identity_key=identity_exact,
|
||||
),
|
||||
)
|
||||
self.product.invalidate_cache()
|
||||
trap.perform_enqueued_jobs()
|
||||
replenish_move = self._get_replenishment_move(orderpoint)
|
||||
self._check_replenishment_move(replenish_move, move_qty, orderpoint)
|
||||
|
||||
# Create a second incoming move so that the qty_available would be 24
|
||||
move = self._create_incoming_move(move_qty, location_src)
|
||||
with trap_jobs() as trap:
|
||||
move = self._create_outgoing_move(move_qty)
|
||||
trap.assert_jobs_count(1, only=job_func)
|
||||
trap.assert_enqueued_job(
|
||||
orderpoint.run_auto_replenishment,
|
||||
args=(move.product_id, move.location_id, "location_id"),
|
||||
kwargs={},
|
||||
properties=dict(
|
||||
identity_key=identity_exact,
|
||||
),
|
||||
)
|
||||
self.product.invalidate_cache()
|
||||
trap.perform_enqueued_jobs()
|
||||
replenish_move_new = self._get_replenishment_move(orderpoint)
|
||||
self.assertEqual(replenish_move, replenish_move_new)
|
||||
self._check_replenishment_move(replenish_move, move_qty * 2, orderpoint)
|
||||
|
||||
def test_auto_no_replenishment(self):
|
||||
"""
|
||||
Create a stock move that should not create a replenishment:
|
||||
- A move from a new stock location 'WH/Stock 2' to Scrap
|
||||
"""
|
||||
job_func = self.env["stock.location.orderpoint"].run_auto_replenishment
|
||||
with trap_jobs() as trap:
|
||||
new_location = self.env["stock.location"].create(
|
||||
{
|
||||
"name": "Other Stock",
|
||||
"location_id": self.location_dest.location_id.id,
|
||||
}
|
||||
)
|
||||
_, _ = self._create_orderpoint_complete("Stock2", trigger="auto")
|
||||
self.location_dest = new_location
|
||||
self._create_quants(self.product, self.location_dest, 10.0)
|
||||
move = self._create_scrap_move(10.0, self.location_dest)
|
||||
trap.assert_jobs_count(0, only=job_func)
|
||||
trap.perform_enqueued_jobs()
|
||||
replenish_move = self.env["stock.move"].search(
|
||||
[
|
||||
("product_id", "=", move.product_id.id),
|
||||
("location_dest_id", "=", move.location_id.id),
|
||||
]
|
||||
)
|
||||
self.assertFalse(replenish_move)
|
||||
|
||||
def test_orderpoint_count(self):
|
||||
"""
|
||||
One orderpoint has already been created in demo data.
|
||||
Check after each creation that count is increasing.
|
||||
"""
|
||||
_, _ = self._create_orderpoint_complete("Stock2", trigger="cron")
|
||||
self.assertEqual(1, self.location_dest.location_orderpoint_count)
|
||||
_, _ = self._create_orderpoint_complete("Stock3", trigger="cron")
|
||||
self.assertEqual(2, self.location_dest.location_orderpoint_count)
|
||||
15
stock_location_orderpoint/views/menu.xml
Normal file
15
stock_location_orderpoint/views/menu.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<odoo>
|
||||
<record id="action_stock_location_orderpoint" model="ir.actions.act_window">
|
||||
<field name="name">Stock Location Orderpoint</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">stock.location.orderpoint</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
</record>
|
||||
<menuitem
|
||||
id="menu_stock_location_orderpoint"
|
||||
action="action_stock_location_orderpoint"
|
||||
name="Stock Location Orderpoint"
|
||||
parent="stock.menu_product_in_config_stock"
|
||||
sequence="50"
|
||||
/>
|
||||
</odoo>
|
||||
28
stock_location_orderpoint/views/stock_location.xml
Normal file
28
stock_location_orderpoint/views/stock_location.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2023 ACSONE SA/NV
|
||||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
|
||||
<odoo>
|
||||
<record id="view_location_form" model="ir.ui.view">
|
||||
<field name="name">stock.location.form (in stock_location_orderpoint)</field>
|
||||
<field name="model">stock.location</field>
|
||||
<field name="inherit_id" ref="stock.view_location_form" />
|
||||
<field name="arch" type="xml">
|
||||
<div name="button_box" position="inside">
|
||||
<button
|
||||
string=""
|
||||
class="oe_stat_button"
|
||||
icon="fa-refresh"
|
||||
name="action_open_location_orderpoints"
|
||||
type="object"
|
||||
groups="stock.group_stock_multi_locations"
|
||||
>
|
||||
<field
|
||||
name="location_orderpoint_count"
|
||||
string="Orderpoints"
|
||||
widget="statinfo"
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -0,0 +1,94 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<record id="view_stock_location_orderpoint_tree_editable" model="ir.ui.view">
|
||||
<field name="name">stock.location.orderpoint.tree.editable</field>
|
||||
<field name="model">stock.location.orderpoint</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Stock Location Oderpoints">
|
||||
<field name="sequence" widget="handle" />
|
||||
<field name="name" />
|
||||
<field name="location_id" options="{'no_create': True}" />
|
||||
<field
|
||||
name="route_id"
|
||||
options="{'no_create': True}"
|
||||
attrs="{'readonly': [('location_id', '=', False)]}"
|
||||
/>
|
||||
<field name="location_src_id" />
|
||||
<field name="trigger" />
|
||||
<field name="replenish_method" />
|
||||
<field name="group_id" />
|
||||
<field
|
||||
name="company_id"
|
||||
optional="hide"
|
||||
readonly="1"
|
||||
groups="base.group_multi_company"
|
||||
/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="stock_location_orderpoint_form">
|
||||
<field name="name">stock.location.orderpoint.form</field>
|
||||
<field name="model">stock.location.orderpoint</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<header>
|
||||
<button
|
||||
name="run_replenishment"
|
||||
type="object"
|
||||
string="Run replenishment"
|
||||
attrs="{'invisible': ['|', ('active', '=', False), ('trigger', '!=', 'manual')]}"
|
||||
/>
|
||||
</header>
|
||||
<sheet>
|
||||
<div class="oe_button_box" name="active_button_box">
|
||||
<button
|
||||
name="toggle_active"
|
||||
type="object"
|
||||
class="oe_stat_button"
|
||||
icon="fa-archive"
|
||||
>
|
||||
<field
|
||||
name="active"
|
||||
widget="boolean_button"
|
||||
options='{"terminology": "archive"}'
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
<group>
|
||||
<field name="name" force_save="1" />
|
||||
<field name="sequence" />
|
||||
<field name="trigger" />
|
||||
<field name="replenish_method" />
|
||||
<field
|
||||
name="company_id"
|
||||
readonly="1"
|
||||
groups="base.group_multi_company"
|
||||
/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="location_id" />
|
||||
<field name="location_src_id" />
|
||||
<field name="route_id" />
|
||||
<field name="group_id" />
|
||||
<field name="priority" />
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="stock_location_orderpoint_search">
|
||||
<field name="name">stock.location.orderpoint.search</field>
|
||||
<field name="model">stock.location.orderpoint</field>
|
||||
<field name="arch" type="xml">
|
||||
<search>
|
||||
<field name="name" />
|
||||
<field name="location_id" />
|
||||
<field name="location_src_id" />
|
||||
<field name="route_id" />
|
||||
<field name="group_id" />
|
||||
<field name="trigger" />
|
||||
<field name="replenish_method" />
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
81
stock_location_orderpoint_source_relocate/README.rst
Normal file
81
stock_location_orderpoint_source_relocate/README.rst
Normal file
@@ -0,0 +1,81 @@
|
||||
=========================================
|
||||
stock_location_orderpoint_source_relocate
|
||||
=========================================
|
||||
|
||||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
.. |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-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--warehouse-lightgray.png?logo=github
|
||||
:target: https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_location_orderpoint_source_relocate
|
||||
:alt: OCA/stock-logistics-warehouse
|
||||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
|
||||
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-14-0/stock-logistics-warehouse-14-0-stock_location_orderpoint_source_relocate
|
||||
:alt: Translate me on Weblate
|
||||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
|
||||
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/stock-logistics-warehouse&target_branch=14.0
|
||||
:alt: Try me on Runboat
|
||||
|
||||
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||
|
||||
Run an auto location orderpoint replenishment also after a move gets relocated by Stock Move Source Relocate
|
||||
|
||||
**Table of contents**
|
||||
|
||||
.. contents::
|
||||
:local:
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-warehouse/issues>`_.
|
||||
In case of trouble, please check there if your issue has already been reported.
|
||||
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
||||
`feedback <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_location_orderpoint_source_relocate%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
|
||||
~~~~~~~
|
||||
|
||||
* MT Software
|
||||
|
||||
Contributors
|
||||
~~~~~~~~~~~~
|
||||
|
||||
* Michael Tietz (MT Software) <mtietz@mt-software.de>
|
||||
|
||||
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-mt-software-de| image:: https://github.com/mt-software-de.png?size=40px
|
||||
:target: https://github.com/mt-software-de
|
||||
:alt: mt-software-de
|
||||
|
||||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
|
||||
|
||||
|maintainer-mt-software-de|
|
||||
|
||||
This module is part of the `OCA/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_location_orderpoint_source_relocate>`_ project on GitHub.
|
||||
|
||||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
||||
1
stock_location_orderpoint_source_relocate/__init__.py
Normal file
1
stock_location_orderpoint_source_relocate/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
||||
19
stock_location_orderpoint_source_relocate/__manifest__.py
Normal file
19
stock_location_orderpoint_source_relocate/__manifest__.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
"name": "stock_location_orderpoint_source_relocate",
|
||||
"author": "MT Software, Odoo Community Association (OCA)",
|
||||
"summary": "Run an auto location orderpoint replenishment "
|
||||
"also after a move gets relocated by Stock Move Source Relocate",
|
||||
"version": "14.0.1.0.0",
|
||||
"development_status": "Alpha",
|
||||
"data": [],
|
||||
"depends": [
|
||||
"stock_location_orderpoint",
|
||||
"stock_move_source_relocate",
|
||||
],
|
||||
"license": "AGPL-3",
|
||||
"maintainers": ["mt-software-de"],
|
||||
"website": "https://github.com/OCA/stock-logistics-warehouse",
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
from . import stock_move
|
||||
@@ -0,0 +1,22 @@
|
||||
# Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import models
|
||||
|
||||
|
||||
class StockMove(models.Model):
|
||||
_inherit = "stock.move"
|
||||
|
||||
def _action_assign(self, *args, **kwargs):
|
||||
self = self.with_context(skip_auto_replenishment=True)
|
||||
res = super()._action_assign(*args, **kwargs)
|
||||
self = self.with_context(skip_auto_replenishment=False)
|
||||
return res
|
||||
|
||||
def _apply_source_relocate_rule(self, *args, **kwargs):
|
||||
relocated = super()._apply_source_relocate_rule(*args, **kwargs)
|
||||
if not relocated:
|
||||
return relocated
|
||||
relocated.with_context(
|
||||
skip_auto_replenishment=False
|
||||
)._prepare_auto_replenishment_for_waiting_moves()
|
||||
return relocated
|
||||
@@ -0,0 +1 @@
|
||||
* Michael Tietz (MT Software) <mtietz@mt-software.de>
|
||||
@@ -0,0 +1 @@
|
||||
Run an auto location orderpoint replenishment also after a move gets relocated by Stock Move Source Relocate
|
||||
@@ -0,0 +1,421 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
|
||||
<title>stock_location_orderpoint_source_relocate</title>
|
||||
<style type="text/css">
|
||||
|
||||
/*
|
||||
:Author: David Goodger (goodger@python.org)
|
||||
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
|
||||
:Copyright: This stylesheet has been placed in the public domain.
|
||||
|
||||
Default cascading style sheet for the HTML output of Docutils.
|
||||
|
||||
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
|
||||
customize this style sheet.
|
||||
*/
|
||||
|
||||
/* used to remove borders from tables and images */
|
||||
.borderless, table.borderless td, table.borderless th {
|
||||
border: 0 }
|
||||
|
||||
table.borderless td, table.borderless th {
|
||||
/* Override padding for "table.docutils td" with "! important".
|
||||
The right padding separates the table cells. */
|
||||
padding: 0 0.5em 0 0 ! important }
|
||||
|
||||
.first {
|
||||
/* Override more specific margin styles with "! important". */
|
||||
margin-top: 0 ! important }
|
||||
|
||||
.last, .with-subtitle {
|
||||
margin-bottom: 0 ! important }
|
||||
|
||||
.hidden {
|
||||
display: none }
|
||||
|
||||
.subscript {
|
||||
vertical-align: sub;
|
||||
font-size: smaller }
|
||||
|
||||
.superscript {
|
||||
vertical-align: super;
|
||||
font-size: smaller }
|
||||
|
||||
a.toc-backref {
|
||||
text-decoration: none ;
|
||||
color: black }
|
||||
|
||||
blockquote.epigraph {
|
||||
margin: 2em 5em ; }
|
||||
|
||||
dl.docutils dd {
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Uncomment (and remove this text!) to get bold-faced definition list terms
|
||||
dl.docutils dt {
|
||||
font-weight: bold }
|
||||
*/
|
||||
|
||||
div.abstract {
|
||||
margin: 2em 5em }
|
||||
|
||||
div.abstract p.topic-title {
|
||||
font-weight: bold ;
|
||||
text-align: center }
|
||||
|
||||
div.admonition, div.attention, div.caution, div.danger, div.error,
|
||||
div.hint, div.important, div.note, div.tip, div.warning {
|
||||
margin: 2em ;
|
||||
border: medium outset ;
|
||||
padding: 1em }
|
||||
|
||||
div.admonition p.admonition-title, div.hint p.admonition-title,
|
||||
div.important p.admonition-title, div.note p.admonition-title,
|
||||
div.tip p.admonition-title {
|
||||
font-weight: bold ;
|
||||
font-family: sans-serif }
|
||||
|
||||
div.attention p.admonition-title, div.caution p.admonition-title,
|
||||
div.danger p.admonition-title, div.error p.admonition-title,
|
||||
div.warning p.admonition-title, .code .error {
|
||||
color: red ;
|
||||
font-weight: bold ;
|
||||
font-family: sans-serif }
|
||||
|
||||
/* Uncomment (and remove this text!) to get reduced vertical space in
|
||||
compound paragraphs.
|
||||
div.compound .compound-first, div.compound .compound-middle {
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
div.compound .compound-last, div.compound .compound-middle {
|
||||
margin-top: 0.5em }
|
||||
*/
|
||||
|
||||
div.dedication {
|
||||
margin: 2em 5em ;
|
||||
text-align: center ;
|
||||
font-style: italic }
|
||||
|
||||
div.dedication p.topic-title {
|
||||
font-weight: bold ;
|
||||
font-style: normal }
|
||||
|
||||
div.figure {
|
||||
margin-left: 2em ;
|
||||
margin-right: 2em }
|
||||
|
||||
div.footer, div.header {
|
||||
clear: both;
|
||||
font-size: smaller }
|
||||
|
||||
div.line-block {
|
||||
display: block ;
|
||||
margin-top: 1em ;
|
||||
margin-bottom: 1em }
|
||||
|
||||
div.line-block div.line-block {
|
||||
margin-top: 0 ;
|
||||
margin-bottom: 0 ;
|
||||
margin-left: 1.5em }
|
||||
|
||||
div.sidebar {
|
||||
margin: 0 0 0.5em 1em ;
|
||||
border: medium outset ;
|
||||
padding: 1em ;
|
||||
background-color: #ffffee ;
|
||||
width: 40% ;
|
||||
float: right ;
|
||||
clear: right }
|
||||
|
||||
div.sidebar p.rubric {
|
||||
font-family: sans-serif ;
|
||||
font-size: medium }
|
||||
|
||||
div.system-messages {
|
||||
margin: 5em }
|
||||
|
||||
div.system-messages h1 {
|
||||
color: red }
|
||||
|
||||
div.system-message {
|
||||
border: medium outset ;
|
||||
padding: 1em }
|
||||
|
||||
div.system-message p.system-message-title {
|
||||
color: red ;
|
||||
font-weight: bold }
|
||||
|
||||
div.topic {
|
||||
margin: 2em }
|
||||
|
||||
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
|
||||
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
|
||||
margin-top: 0.4em }
|
||||
|
||||
h1.title {
|
||||
text-align: center }
|
||||
|
||||
h2.subtitle {
|
||||
text-align: center }
|
||||
|
||||
hr.docutils {
|
||||
width: 75% }
|
||||
|
||||
img.align-left, .figure.align-left, object.align-left, table.align-left {
|
||||
clear: left ;
|
||||
float: left ;
|
||||
margin-right: 1em }
|
||||
|
||||
img.align-right, .figure.align-right, object.align-right, table.align-right {
|
||||
clear: right ;
|
||||
float: right ;
|
||||
margin-left: 1em }
|
||||
|
||||
img.align-center, .figure.align-center, object.align-center {
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
table.align-center {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.align-left {
|
||||
text-align: left }
|
||||
|
||||
.align-center {
|
||||
clear: both ;
|
||||
text-align: center }
|
||||
|
||||
.align-right {
|
||||
text-align: right }
|
||||
|
||||
/* reset inner alignment in figures */
|
||||
div.align-right {
|
||||
text-align: inherit }
|
||||
|
||||
/* div.align-center * { */
|
||||
/* text-align: left } */
|
||||
|
||||
.align-top {
|
||||
vertical-align: top }
|
||||
|
||||
.align-middle {
|
||||
vertical-align: middle }
|
||||
|
||||
.align-bottom {
|
||||
vertical-align: bottom }
|
||||
|
||||
ol.simple, ul.simple {
|
||||
margin-bottom: 1em }
|
||||
|
||||
ol.arabic {
|
||||
list-style: decimal }
|
||||
|
||||
ol.loweralpha {
|
||||
list-style: lower-alpha }
|
||||
|
||||
ol.upperalpha {
|
||||
list-style: upper-alpha }
|
||||
|
||||
ol.lowerroman {
|
||||
list-style: lower-roman }
|
||||
|
||||
ol.upperroman {
|
||||
list-style: upper-roman }
|
||||
|
||||
p.attribution {
|
||||
text-align: right ;
|
||||
margin-left: 50% }
|
||||
|
||||
p.caption {
|
||||
font-style: italic }
|
||||
|
||||
p.credits {
|
||||
font-style: italic ;
|
||||
font-size: smaller }
|
||||
|
||||
p.label {
|
||||
white-space: nowrap }
|
||||
|
||||
p.rubric {
|
||||
font-weight: bold ;
|
||||
font-size: larger ;
|
||||
color: maroon ;
|
||||
text-align: center }
|
||||
|
||||
p.sidebar-title {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold ;
|
||||
font-size: larger }
|
||||
|
||||
p.sidebar-subtitle {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold }
|
||||
|
||||
p.topic-title {
|
||||
font-weight: bold }
|
||||
|
||||
pre.address {
|
||||
margin-bottom: 0 ;
|
||||
margin-top: 0 ;
|
||||
font: inherit }
|
||||
|
||||
pre.literal-block, pre.doctest-block, pre.math, pre.code {
|
||||
margin-left: 2em ;
|
||||
margin-right: 2em }
|
||||
|
||||
pre.code .ln { color: grey; } /* line numbers */
|
||||
pre.code, code { background-color: #eeeeee }
|
||||
pre.code .comment, code .comment { color: #5C6576 }
|
||||
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
|
||||
pre.code .literal.string, code .literal.string { color: #0C5404 }
|
||||
pre.code .name.builtin, code .name.builtin { color: #352B84 }
|
||||
pre.code .deleted, code .deleted { background-color: #DEB0A1}
|
||||
pre.code .inserted, code .inserted { background-color: #A3D289}
|
||||
|
||||
span.classifier {
|
||||
font-family: sans-serif ;
|
||||
font-style: oblique }
|
||||
|
||||
span.classifier-delimiter {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold }
|
||||
|
||||
span.interpreted {
|
||||
font-family: sans-serif }
|
||||
|
||||
span.option {
|
||||
white-space: nowrap }
|
||||
|
||||
span.pre {
|
||||
white-space: pre }
|
||||
|
||||
span.problematic {
|
||||
color: red }
|
||||
|
||||
span.section-subtitle {
|
||||
/* font-size relative to parent (h1..h6 element) */
|
||||
font-size: 80% }
|
||||
|
||||
table.citation {
|
||||
border-left: solid 1px gray;
|
||||
margin-left: 1px }
|
||||
|
||||
table.docinfo {
|
||||
margin: 2em 4em }
|
||||
|
||||
table.docutils {
|
||||
margin-top: 0.5em ;
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
table.footnote {
|
||||
border-left: solid 1px black;
|
||||
margin-left: 1px }
|
||||
|
||||
table.docutils td, table.docutils th,
|
||||
table.docinfo td, table.docinfo th {
|
||||
padding-left: 0.5em ;
|
||||
padding-right: 0.5em ;
|
||||
vertical-align: top }
|
||||
|
||||
table.docutils th.field-name, table.docinfo th.docinfo-name {
|
||||
font-weight: bold ;
|
||||
text-align: left ;
|
||||
white-space: nowrap ;
|
||||
padding-left: 0 }
|
||||
|
||||
/* "booktabs" style (no vertical lines) */
|
||||
table.docutils.booktabs {
|
||||
border: 0px;
|
||||
border-top: 2px solid;
|
||||
border-bottom: 2px solid;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
table.docutils.booktabs * {
|
||||
border: 0px;
|
||||
}
|
||||
table.docutils.booktabs th {
|
||||
border-bottom: thin solid;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
|
||||
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
|
||||
font-size: 100% }
|
||||
|
||||
ul.auto-toc {
|
||||
list-style-type: none }
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="document" id="stock-location-orderpoint-source-relocate">
|
||||
<h1 class="title">stock_location_orderpoint_source_relocate</h1>
|
||||
|
||||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_location_orderpoint_source_relocate"><img alt="OCA/stock-logistics-warehouse" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/stock-logistics-warehouse-14-0/stock-logistics-warehouse-14-0-stock_location_orderpoint_source_relocate"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runboat.odoo-community.org/webui/builds.html?repo=OCA/stock-logistics-warehouse&target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
|
||||
<p>Run an auto location orderpoint replenishment also after a move gets relocated by Stock Move Source Relocate</p>
|
||||
<p><strong>Table of contents</strong></p>
|
||||
<div class="contents local topic" id="contents">
|
||||
<ul class="simple">
|
||||
<li><a class="reference internal" href="#bug-tracker" id="id1">Bug Tracker</a></li>
|
||||
<li><a class="reference internal" href="#credits" id="id2">Credits</a><ul>
|
||||
<li><a class="reference internal" href="#authors" id="id3">Authors</a></li>
|
||||
<li><a class="reference internal" href="#contributors" id="id4">Contributors</a></li>
|
||||
<li><a class="reference internal" href="#maintainers" id="id5">Maintainers</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="bug-tracker">
|
||||
<h1><a class="toc-backref" href="#id1">Bug Tracker</a></h1>
|
||||
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/issues">GitHub Issues</a>.
|
||||
In case of trouble, please check there if your issue has already been reported.
|
||||
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
||||
<a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_location_orderpoint_source_relocate%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
|
||||
<p>Do not contact contributors directly about support or help with technical issues.</p>
|
||||
</div>
|
||||
<div class="section" id="credits">
|
||||
<h1><a class="toc-backref" href="#id2">Credits</a></h1>
|
||||
<div class="section" id="authors">
|
||||
<h2><a class="toc-backref" href="#id3">Authors</a></h2>
|
||||
<ul class="simple">
|
||||
<li>MT Software</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="contributors">
|
||||
<h2><a class="toc-backref" href="#id4">Contributors</a></h2>
|
||||
<ul class="simple">
|
||||
<li>Michael Tietz (MT Software) <<a class="reference external" href="mailto:mtietz@mt-software.de">mtietz@mt-software.de</a>></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="maintainers">
|
||||
<h2><a class="toc-backref" href="#id5">Maintainers</a></h2>
|
||||
<p>This module is maintained by the OCA.</p>
|
||||
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
|
||||
<p>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.</p>
|
||||
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
|
||||
<p><a class="reference external" href="https://github.com/mt-software-de"><img alt="mt-software-de" src="https://github.com/mt-software-de.png?size=40px" /></a></p>
|
||||
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_location_orderpoint_source_relocate">OCA/stock-logistics-warehouse</a> project on GitHub.</p>
|
||||
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1 @@
|
||||
from . import test_location_orderpoint
|
||||
@@ -0,0 +1,65 @@
|
||||
# Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo.tests.common import Form
|
||||
|
||||
from odoo.addons.queue_job.job import identity_exact
|
||||
from odoo.addons.queue_job.tests.common import trap_jobs
|
||||
from odoo.addons.stock_location_orderpoint.tests.common import (
|
||||
TestLocationOrderpointCommon,
|
||||
)
|
||||
from odoo.addons.stock_move_source_relocate.tests.common import SourceRelocateCommon
|
||||
|
||||
|
||||
class TestLocationOrderpoint(TestLocationOrderpointCommon, SourceRelocateCommon):
|
||||
def test_auto_replenishment(self):
|
||||
name = "Internal Replenishment"
|
||||
replenishment_location = self.env["stock.location"].create(
|
||||
{
|
||||
"name": name,
|
||||
"location_id": self.wh.lot_stock_id.location_id.id,
|
||||
}
|
||||
)
|
||||
internal_location = replenishment_location.create(
|
||||
{
|
||||
"name": name,
|
||||
"location_id": self.wh.lot_stock_id.id,
|
||||
}
|
||||
)
|
||||
picking_type = self._create_picking_type(
|
||||
name, replenishment_location, internal_location, self.wh
|
||||
)
|
||||
route = self._create_route(
|
||||
name, picking_type, replenishment_location, internal_location, self.wh
|
||||
)
|
||||
|
||||
orderpoint = Form(self.env["stock.location.orderpoint"])
|
||||
orderpoint.location_id = internal_location
|
||||
orderpoint.route_id = route
|
||||
orderpoint = orderpoint.save()
|
||||
|
||||
job_func = self.env["stock.location.orderpoint"].run_auto_replenishment
|
||||
|
||||
self._create_incoming_move(10, replenishment_location)
|
||||
self._create_relocate_rule(
|
||||
self.wh.lot_stock_id, internal_location, self.wh.out_type_id
|
||||
)
|
||||
with trap_jobs() as trap:
|
||||
move = self._create_outgoing_move(10, self.wh.lot_stock_id)
|
||||
move.picking_type_id = self.wh.out_type_id.id
|
||||
move._assign_picking()
|
||||
move._action_assign()
|
||||
self.assertEqual(move.location_id, internal_location)
|
||||
trap.assert_jobs_count(1, only=job_func)
|
||||
trap.assert_enqueued_job(
|
||||
orderpoint.run_auto_replenishment,
|
||||
args=(move.product_id, internal_location, "location_id"),
|
||||
kwargs={},
|
||||
properties=dict(
|
||||
identity_key=identity_exact,
|
||||
),
|
||||
)
|
||||
|
||||
self.product.invalidate_cache()
|
||||
trap.perform_enqueued_jobs()
|
||||
replenish_move = self._get_replenishment_move(orderpoint)
|
||||
self._check_replenishment_move(replenish_move, 10, orderpoint)
|
||||
@@ -100,12 +100,13 @@ class TestAssignAutoRelease(PromiseReleaseCommonCase):
|
||||
* 1 to assign other moves
|
||||
* 1 to release the other moves (This one depends on the first one)
|
||||
"""
|
||||
job_func = self.product1.moves_auto_assign
|
||||
with trap_jobs() as trap:
|
||||
self._receive_product(self.product1, 100)
|
||||
# .with_delay() has been called a first one to auto assigned
|
||||
trap.assert_jobs_count(2)
|
||||
trap.assert_jobs_count(1, only=job_func)
|
||||
trap.assert_enqueued_job(
|
||||
self.product1.moves_auto_assign,
|
||||
job_func,
|
||||
args=(self.loc_bin1,),
|
||||
kwargs={},
|
||||
properties=dict(
|
||||
|
||||
Reference in New Issue
Block a user