mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] stock_orderpoint_generator: delivered items options
A new option for auto computing minimum and maximum values depending on the actual delivered items for a period of time
This commit is contained in:
@@ -46,6 +46,7 @@ class OrderpointTemplate(models.Model):
|
||||
("median", "Most frequent"),
|
||||
("avg", "Average"),
|
||||
("min", "Minimum"),
|
||||
("delivered", "Delivered"),
|
||||
],
|
||||
default="max",
|
||||
help="Select a criteria to auto compute the minimum",
|
||||
@@ -60,6 +61,7 @@ class OrderpointTemplate(models.Model):
|
||||
("median", "Most frequent"),
|
||||
("avg", "Average"),
|
||||
("min", "Minimum"),
|
||||
("delivered", "Delivered"),
|
||||
],
|
||||
help="Select a criteria to auto compute the maximum",
|
||||
)
|
||||
@@ -118,7 +120,13 @@ class OrderpointTemplate(models.Model):
|
||||
self, products, location_id, from_date, to_date, criteria
|
||||
):
|
||||
"""Returns a dict with product ids as keys and the resulting
|
||||
calculation of historic moves according to criteria"""
|
||||
calculation of historic moves according to criteria. If the
|
||||
creteria is delivered we just search how many items were
|
||||
delivered in the given period of time"""
|
||||
if criteria == "delivered":
|
||||
return products._get_delivered_to_customer_dict(
|
||||
location_id, from_date, to_date
|
||||
)
|
||||
stock_qty_history = products._compute_historic_quantities_dict(
|
||||
location_id=location_id, from_date=from_date, to_date=to_date
|
||||
)
|
||||
|
||||
@@ -101,6 +101,28 @@ class ProductProduct(models.Model):
|
||||
]
|
||||
return product_moves_dict
|
||||
|
||||
def _get_delivered_to_customer_dict(
|
||||
self, location=False, from_date=False, to_date=False
|
||||
):
|
||||
"""Returns a dict of products with their delivered qtys for the
|
||||
given dates and locations
|
||||
"""
|
||||
domain = [
|
||||
("product_id", "in", self.ids),
|
||||
("state", "=", "done"),
|
||||
("location_dest_id.usage", "=", "customer"),
|
||||
]
|
||||
if location:
|
||||
domain += [("location_id", "child_of", location.id)]
|
||||
if from_date:
|
||||
domain += [("date", ">=", from_date)]
|
||||
if to_date:
|
||||
domain += [("date", "<=", to_date)]
|
||||
move_lines = self.env["stock.move.line"].read_group(
|
||||
domain, ["product_id", "qty_done"], ["product_id"]
|
||||
)
|
||||
return {p["product_id"][0]: p["qty_done"] for p in move_lines}
|
||||
|
||||
def _compute_historic_quantities_dict(
|
||||
self, location_id=False, from_date=False, to_date=False
|
||||
):
|
||||
|
||||
@@ -378,6 +378,13 @@ class TestOrderpointGenerator(SavepointCase):
|
||||
wizard.action_configure()
|
||||
orderpoint_auto_dict.update({"product_min_qty": 55, "product_max_qty": 50})
|
||||
self.check_orderpoint(self.p1, self.template, orderpoint_auto_dict)
|
||||
# Check delivered
|
||||
self.template.auto_min_qty_criteria = "delivered"
|
||||
self.template.auto_max_qty_criteria = "delivered"
|
||||
wizard = self.wizard_over_products(self.p1, self.template)
|
||||
wizard.action_configure()
|
||||
orderpoint_auto_dict.update({"product_min_qty": 3, "product_max_qty": 5})
|
||||
self.check_orderpoint(self.p1, self.template, orderpoint_auto_dict)
|
||||
|
||||
def test_auto_qty_multi_products(self):
|
||||
"""Each product has a different history"""
|
||||
|
||||
Reference in New Issue
Block a user