Skip to content

Commit

Permalink
fixing planning of inquiries
Browse files Browse the repository at this point in the history
  • Loading branch information
jdetaeye committed Jan 20, 2025
1 parent cbe59b5 commit aa212a7
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 36 deletions.
3 changes: 3 additions & 0 deletions doc/release-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ You can already check out a `preview <https://demo-preview.frepple.com>`_.
| In earlier releases some implementations already used a custom attribute
field for this purpose.
- | Bug fix: Sales orders in the status "inquiry" incorrectly were being planned
when a) the owner field is set and b) the delivery policy is set to alltogether.

.. rubric:: Odoo integration

- | 17, 18: Extra robostness to avoid creating manufacturing orders on
Expand Down
7 changes: 5 additions & 2 deletions src/solver/solverdemand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,15 @@ void SolverCreate::solve(const Demand* salesorder, void* v) {
if (m->getQuantity() - m->getPlannedQuantity() > ROUNDING_ERROR &&
m->getDue() < Date::infiniteFuture &&
(m->getStatus() == Demand::STATUS_OPEN ||
m->getStatus() == Demand::STATUS_QUOTE)) {
m->getStatus() == Demand::STATUS_QUOTE ||
(m->getStatus() == Demand::STATUS_INQUIRY &&
salesorder->getStatus() == Demand::STATUS_INQUIRY))) {
salesorderlines.push_back(&*m);
}
} else if (salesorder->getQuantity() - salesorder->getPlannedQuantity() >
ROUNDING_ERROR &&
salesorder->getDue() < Date::infiniteFuture)
salesorder->getDue() < Date::infiniteFuture &&
salesorder->getStatus() != Demand::STATUS_INQUIRY)
salesorderlines.push_back(const_cast<Demand*>(salesorder));
if (salesorderlines.empty()) {
if (loglevel > 0) logger << " Nothing to be planned." << endl;
Expand Down
13 changes: 10 additions & 3 deletions src/solver/solverplan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,14 @@ void SolverCreate::solve(void* v) {
if (!getConstraints()) {
// Dumb unconstrained plan is running in a single thread
for (auto& i : Demand::all())
if (i.getQuantity() > 0 && (i.getStatus() == Demand::STATUS_OPEN ||
i.getStatus() == Demand::STATUS_QUOTE))
if (i.getQuantity() > 0 &&
(i.getStatus() == Demand::STATUS_OPEN ||
i.getStatus() == Demand::STATUS_QUOTE ||
(i.getStatus() == Demand::STATUS_INQUIRY && i.getOwner() &&
i.getOwner()->hasType<DemandGroup>() &&
i.getOwner()->getStatus() == Demand::STATUS_INQUIRY &&
static_cast<DemandGroup*>(i.getOwner())->getPolicy() !=
Demand::POLICY_INDEPENDENT)))
demands_per_cluster[0].push_back(&i);
} else if (cluster == -1 && !userexit_nextdemand) {
// Many clusters to solve
Expand All @@ -734,7 +740,8 @@ void SolverCreate::solve(void* v) {
Demand::POLICY_INDEPENDENT;
if ((isGroup || (i.getQuantity() > 0 && !isMemberOfGroup)) &&
(i.getStatus() == Demand::STATUS_OPEN ||
i.getStatus() == Demand::STATUS_QUOTE))
i.getStatus() == Demand::STATUS_QUOTE ||
i.getStatus() == Demand::STATUS_INQUIRY))
demands_per_cluster[i.getCluster()].push_back(&i);
}
} else if (!userexit_nextdemand) {
Expand Down
24 changes: 24 additions & 0 deletions test/demand_status/demand_status.1.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
BUFFER item 1 @ factory 2025-01-08T00:00:00 1 1
BUFFER item 1 @ factory 2025-01-08T00:00:00 -1 0
BUFFER item 3 @ factory 2025-03-05T00:00:00 1 1
BUFFER item 3 @ factory 2025-03-05T00:00:00 -1 0
BUFFER item 5A @ factory 2025-05-05T00:00:00 1 1
BUFFER item 5A @ factory 2025-05-05T00:00:00 -1 0
BUFFER item 6A @ factory 2025-06-05T00:00:00 1 1
BUFFER item 6A @ factory 2025-06-05T00:00:00 -1 0
BUFFER item 6B @ factory 2025-06-05T00:00:00 1 1
BUFFER item 6B @ factory 2025-06-05T00:00:00 -1 0
DEMAND order 1 - open 2025-01-08T00:00:00 1
DEMAND order 3 - quote 2025-03-05T00:00:00 1
DEMAND order 5A 2025-05-05T00:00:00 1
DEMAND order 6A 2025-06-05T00:00:00 1
DEMAND order 6B 2025-06-05T00:00:00 1
OPERATION Purchase item 1 @ factory from Magic Supplier 2025-01-01T00:00:00 2025-01-08T00:00:00 1
OPERATION Purchase item 3 @ factory from Magic Supplier 2025-02-26T00:00:00 2025-03-05T00:00:00 1
OPERATION Purchase item 5A @ factory from Magic Supplier 2025-04-28T00:00:00 2025-05-05T00:00:00 1
OPERATION Purchase item 6A @ factory from Magic Supplier 2025-05-29T00:00:00 2025-06-05T00:00:00 1
OPERATION Purchase item 6B @ factory from Magic Supplier 2025-05-29T00:00:00 2025-06-05T00:00:00 1
PROBLEM late 1 units of demand 'order 1 - open' planned up to 3.0 days after its due date 2025-01-05T00:00:00 / 2025-01-08T00:00:00
PROBLEM unplanned Demand 'order 4 - inquiry' is not planned 2025-04-05T00:00:00 / 2025-04-05T00:00:00
PROBLEM unplanned Demand 'order 5B' is not planned 2025-05-05T00:00:00 / 2025-05-05T00:00:00
DEMAND CONSTRAINT order 1 - open Operation 'Purchase item 1 @ factory from Magic Supplier' planned in the past 2024-12-29T00:00:00 / 2025-01-01T00:00:00
23 changes: 23 additions & 0 deletions test/demand_status/demand_status.2.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
BUFFER item 1 @ factory 2025-01-05T00:00:00 1 1
BUFFER item 1 @ factory 2025-01-05T00:00:00 -1 0
BUFFER item 3 @ factory 2025-03-05T00:00:00 1 1
BUFFER item 3 @ factory 2025-03-05T00:00:00 -1 0
BUFFER item 5A @ factory 2025-05-05T00:00:00 1 1
BUFFER item 5A @ factory 2025-05-05T00:00:00 -1 0
BUFFER item 6A @ factory 2025-06-05T00:00:00 1 1
BUFFER item 6A @ factory 2025-06-05T00:00:00 -1 0
BUFFER item 6B @ factory 2025-06-05T00:00:00 1 1
BUFFER item 6B @ factory 2025-06-05T00:00:00 -1 0
DEMAND order 1 - open 2025-01-05T00:00:00 1
DEMAND order 3 - quote 2025-03-05T00:00:00 1
DEMAND order 5A 2025-05-05T00:00:00 1
DEMAND order 6A 2025-06-05T00:00:00 1
DEMAND order 6B 2025-06-05T00:00:00 1
OPERATION Purchase item 1 @ factory from Magic Supplier 2024-12-29T00:00:00 2025-01-05T00:00:00 1
OPERATION Purchase item 3 @ factory from Magic Supplier 2025-02-26T00:00:00 2025-03-05T00:00:00 1
OPERATION Purchase item 5A @ factory from Magic Supplier 2025-04-28T00:00:00 2025-05-05T00:00:00 1
OPERATION Purchase item 6A @ factory from Magic Supplier 2025-05-29T00:00:00 2025-06-05T00:00:00 1
OPERATION Purchase item 6B @ factory from Magic Supplier 2025-05-29T00:00:00 2025-06-05T00:00:00 1
PROBLEM before current Operation 'Purchase item 1 @ factory from Magic Supplier' planned in the past 2024-12-29T00:00:00 / 2025-01-01T00:00:00
PROBLEM unplanned Demand 'order 4 - inquiry' is not planned 2025-04-05T00:00:00 / 2025-04-05T00:00:00
PROBLEM unplanned Demand 'order 5B' is not planned 2025-05-05T00:00:00 / 2025-05-05T00:00:00
23 changes: 23 additions & 0 deletions test/demand_status/demand_status.3.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
BUFFER item 1 @ factory 2025-01-05T00:00:00 1 1
BUFFER item 1 @ factory 2025-01-05T00:00:00 -1 0
BUFFER item 3 @ factory 2025-03-05T00:00:00 1 1
BUFFER item 3 @ factory 2025-03-05T00:00:00 -1 0
BUFFER item 5A @ factory 2025-05-05T00:00:00 1 1
BUFFER item 5A @ factory 2025-05-05T00:00:00 -1 0
BUFFER item 6A @ factory 2025-06-05T00:00:00 1 1
BUFFER item 6A @ factory 2025-06-05T00:00:00 -1 0
BUFFER item 6B @ factory 2025-06-05T00:00:00 1 1
BUFFER item 6B @ factory 2025-06-05T00:00:00 -1 0
DEMAND order 1 - open 2025-01-05T00:00:00 1
DEMAND order 3 - quote 2025-03-05T00:00:00 1
DEMAND order 5A 2025-05-05T00:00:00 1
DEMAND order 6A 2025-06-05T00:00:00 1
DEMAND order 6B 2025-06-05T00:00:00 1
OPERATION Purchase item 1 @ factory from Magic Supplier 2024-12-29T00:00:00 2025-01-05T00:00:00 1
OPERATION Purchase item 3 @ factory from Magic Supplier 2025-02-26T00:00:00 2025-03-05T00:00:00 1
OPERATION Purchase item 5A @ factory from Magic Supplier 2025-04-28T00:00:00 2025-05-05T00:00:00 1
OPERATION Purchase item 6A @ factory from Magic Supplier 2025-05-29T00:00:00 2025-06-05T00:00:00 1
OPERATION Purchase item 6B @ factory from Magic Supplier 2025-05-29T00:00:00 2025-06-05T00:00:00 1
PROBLEM before current Operation 'Purchase item 1 @ factory from Magic Supplier' planned in the past 2024-12-29T00:00:00 / 2025-01-01T00:00:00
PROBLEM unplanned Demand 'order 4 - inquiry' is not planned 2025-04-05T00:00:00 / 2025-04-05T00:00:00
PROBLEM unplanned Demand 'order 5B' is not planned 2025-05-05T00:00:00 / 2025-05-05T00:00:00
113 changes: 113 additions & 0 deletions test/demand_status/demand_status.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8" ?>
<plan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<current>2025-01-01T00:00:00</current>
<suppliers>
<supplier name="Magic Supplier">
<itemsuppliers>
<itemsupplier>
<item name="All products"/>
<location name="factory"/>
<leadtime>P7D</leadtime>
</itemsupplier>
</itemsuppliers>
</supplier>
</suppliers>
<demands>
<demand name="order 1 - open">
<quantity>1</quantity>
<due>2025-01-05T00:00:00</due>
<item name="item 1">
<owner name="All products"/>
</item>
<location name="factory"/>
<status>open</status>
</demand>
<demand name="order 2 - closed">
<quantity>1</quantity>
<due>2025-02-05T00:00:00</due>
<item name="item 2">
<owner name="All products"/>
</item>
<location name="factory"/>
<status>closed</status>
</demand>
<demand name="order 3 - quote">
<quantity>1</quantity>
<due>2025-03-05T00:00:00</due>
<item name="item 3">
<owner name="All products"/>
</item>
<location name="factory"/>
<status>quote</status>
</demand>
<demand name="order 4 - inquiry">
<quantity>1</quantity>
<due>2025-04-05T00:00:00</due>
<item name="item 4">
<owner name="All products"/>
</item>
<location name="factory"/>
<status>inquiry</status>
</demand>
<demand name="order 5" xsi:type="demand_group">
<members>
<demand name="order 5A">
<quantity>1</quantity>
<due>2025-05-05T00:00:00</due>
<item name="item 5A">
<owner name="All products"/>
</item>
<location name="factory"/>
</demand>
<demand name="order 5B">
<quantity>1</quantity>
<due>2025-05-05T00:00:00</due>
<item name="item 5B">
<owner name="All products"/>
</item>
<location name="factory"/>
<status>inquiry</status>
</demand>
</members>
<policy>alltogether</policy>
</demand>
<demand name="order 6" xsi:type="demand_group" status="inquiry">
<members>
<demand name="order 6A">
<quantity>1</quantity>
<due>2025-06-05T00:00:00</due>
<item name="item 6A">
<owner name="All products"/>
</item>
<location name="factory"/>
</demand>
<!-- This inquiry gets planned because the parent is an inquiry as well. -->
<demand name="order 6B">
<quantity>1</quantity>
<due>2025-06-05T00:00:00</due>
<item name="item 6B">
<owner name="All products"/>
</item>
<location name="factory"/>
<status>inquiry</status>
</demand>
</members>
<policy>alltogether</policy>
</demand>
</demands>

<?python
print("CREATING CONSTRAINED PLAN")
frepple.solver_mrp(plantype=1, constraints=15, loglevel=2).solve()
frepple.saveplan("output.1.xml")

print("CREATING SMART UNCONSTRAINED PLAN")
frepple.solver_mrp(plantype=2, constraints=15, loglevel=2).solve()
frepple.saveplan("output.2.xml")

print("CREATING UNCONSTRAINED PLAN")
frepple.solver_mrp(plantype=2, constraints=0, loglevel=2).solve()
frepple.saveplan("output.3.xml")
?>

</plan>
11 changes: 5 additions & 6 deletions test/forecast_10/forecast_10.3.expect
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ BUFFER item @ factory 2025-02-09T00:00:00 10 10
BUFFER item @ factory 2025-02-09T00:00:00 -10 0
BUFFER item @ factory 2025-02-14T00:00:00 70 70
BUFFER item @ factory 2025-02-14T00:00:00 -60 10
BUFFER item @ factory 2025-02-19T00:00:00 -10 0
BUFFER item @ factory 2025-03-15T00:00:00 100 100
BUFFER item @ factory 2025-03-15T00:00:00 -100 0
BUFFER item @ factory 2025-04-15T00:00:00 100 100
BUFFER item @ factory 2025-04-15T00:00:00 -100 0
BUFFER item @ factory 2025-03-15T00:00:00 100 110
BUFFER item @ factory 2025-03-15T00:00:00 -100 10
BUFFER item @ factory 2025-04-15T00:00:00 100 110
BUFFER item @ factory 2025-04-15T00:00:00 -100 10
DEMAND A quote 2025-02-10T00:00:00 10
DEMAND An inquiry 2025-02-20T00:00:00 10
DEMAND An open sales order 2025-02-01T00:00:00 10
DEMAND forecast - 2025-01-01 2025-01-16T00:00:00 100
DEMAND forecast - 2025-02-01 2025-02-15T00:00:00 60
Expand All @@ -30,3 +28,4 @@ OPERATION Shipping forecast 2025-03-15T00:00:00 2025-03-16T00:00:00 100
OPERATION Shipping forecast 2025-04-15T00:00:00 2025-04-16T00:00:00 100
OPERATION Shipping open sales order 2025-01-31T00:00:00 2025-02-01T00:00:00 10
OPERATION Shipping quote 2025-02-09T00:00:00 2025-02-10T00:00:00 10
PROBLEM unplanned Demand 'An inquiry' is not planned 2025-02-20T00:00:00 / 2025-02-20T00:00:00
Loading

0 comments on commit aa212a7

Please sign in to comment.