Skip to content

Commit

Permalink
Merge pull request #439 from frePPLe/17.0
Browse files Browse the repository at this point in the history
Syncing from upstream frePPLe/odoo (17.0)
  • Loading branch information
bt-admin authored May 7, 2024
2 parents fe725f9 + 193b94f commit e31f018
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 184 deletions.
219 changes: 109 additions & 110 deletions frepple/models/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,133 +38,132 @@ def _compute_minimum_shipment(self):
else:
quote.minimum_shipment = 0

def _generate_html(self, frepple_json):
@classmethod
def generate_html(cls, frepple_json):
html = """
<div style="font-family: \'Segoe UI\', Tahoma, Geneva, Verdana, sans-serif; padding: 20px; background-color: #f4f4f4; color: #333;">"""

if frepple_json["demands"][0].get("pegging"):
html = (
html
+ """
<div style="margin-bottom: 40px;">
<h2 style="margin: 0 0 20px 0; padding-bottom: 10px; border-bottom: 3px solid #3498db; color: #3498db;">Category: Operations</h2>
<ul style="list-style-type: none; padding: 0;">
"""
)
for i, operation in enumerate(frepple_json["demands"][0]["pegging"]):
if (
i != 0
and operation["level"]
<= frepple_json["demands"][0]["pegging"][i - 1]["level"]
):
for _ in range(
frepple_json["demands"][0]["pegging"][i - 1]["level"]
- operation["level"]
+ 1
):
html = (
html
+ """
</div>
"""
)
if i == 0:
html = (
html
+ f"""
<li style="background-color: #fff; margin-bottom: 5px; padding: 15px; border-left: 5px solid #3498db;">
{operation["level"]} {operation["operationplan"]["operation"]["name"]}
<br />Quantity: {operation["operationplan"]["quantity"]}
<br />Start Date: {operation["operationplan"]["start"]}
<br />End Date: {operation["operationplan"]["end"]}
"""
)
for demand in frepple_json["demands"]:

else:
if operation["level"] == 0:
if demand.get("pegging"):
html = (
html
+ """
<div style="margin-bottom: 40px;">
<h2 style="margin: 0 0 20px 0; padding-bottom: 10px; border-bottom: 3px solid #3498db; color: #3498db;">Operations for %s</h2>
<ul style="list-style-type: none; padding: 0;">
"""
% (demand.get("name"),)
)
for i, operation in enumerate(demand["pegging"]):
if (
i != 0
and operation["level"] <= demand["pegging"][i - 1]["level"]
):
for _ in range(
demand["pegging"][i - 1]["level"] - operation["level"] + 1
):
html = (
html
+ """
</div>
"""
)
if i == 0:
html = (
html
+ f"""
</li>
<li style="background-color: #fff; margin-bottom: 5px; padding: 15px; border-left: 5px solid #3498db;">
{operation["level"]} {operation["operationplan"]["operation"]["name"]}
<br />Quantity: {operation["operationplan"]["quantity"]}
<br />Start Date: {operation["operationplan"]["start"]}
<br />End Date: {operation["operationplan"]["end"]}
"""
<li style="background-color: #fff; margin-bottom: 5px; padding: 15px; border-left: 5px solid #3498db;">
{operation["level"]} {operation["operationplan"]["operation"]["name"]}
<br />Quantity: {operation["operationplan"]["quantity"]}
<br />Start Date: {operation["operationplan"]["start"]}
<br />End Date: {operation["operationplan"]["end"]}
"""
)

else:
html = (
html
+ f"""
<div style="margin-top: 10px; padding-left: 20px; border-left: 2px dashed #bdc3c7;">
<strong>Sub-operation: {operation["level"]}</strong>
<br>{operation["operationplan"]["operation"]["name"]}
<br>Quantity: {operation["operationplan"]["quantity"]}
<br>Start Date: {operation["operationplan"]["start"]}
<br>End Date: {operation["operationplan"]["end"]}
"""
)
if operation["level"] == 0:
html = (
html
+ f"""
</li>
<li style="background-color: #fff; margin-bottom: 5px; padding: 15px; border-left: 5px solid #3498db;">
{operation["level"]} {operation["operationplan"]["operation"]["name"]}
<br />Quantity: {operation["operationplan"]["quantity"]}
<br />Start Date: {operation["operationplan"]["start"]}
<br />End Date: {operation["operationplan"]["end"]}
"""
)
else:
html = (
html
+ f"""
<div style="margin-top: 10px; padding-left: 20px; border-left: 2px dashed #bdc3c7;">
<strong>Sub-operation: {operation["level"]}</strong>
<br>{operation["operationplan"]["operation"]["name"]}
<br>Quantity: {operation["operationplan"]["quantity"]}
<br>Start Date: {operation["operationplan"]["start"]}
<br>End Date: {operation["operationplan"]["end"]}
"""
)

for i in range(
frepple_json["demands"][0]["pegging"][
len(frepple_json["demands"][0]["pegging"]) - 1
]["level"]
):
html = html + "</div>"
html = (
html
+ """
</li>
</ul>
</div>
"""
)
for i in range(demand["pegging"][len(demand["pegging"]) - 1]["level"]):
html = html + "</div>"
html = (
html
+ """
</li>
</ul>
</div>
"""
)

if frepple_json["demands"][0].get("problems"):
html = (
html
+ """
<div style="margin-bottom: 40px;">
<h2 style="margin: 0 0 20px 0; padding-bottom: 10px; border-bottom: 3px solid #e74c3c; color: #e74c3c;">Category: Problems</h2>
<ul style="list-style-type: none; padding: 0;">
"""
)
for problem in frepple_json["demands"][0]["problems"]:
if demand.get("problems"):
html = (
html
+ f"""
<li style="background-color: #fff; margin-bottom: 5px; padding: 15px; border-left: 5px solid #e74c3c;">
{problem["description"]}
</li>
"""
+ """
<div style="margin-bottom: 40px;">
<h2 style="margin: 0 0 20px 0; padding-bottom: 10px; border-bottom: 3px solid #e74c3c; color: #e74c3c;">Problems for %s</h2>
<ul style="list-style-type: none; padding: 0;">
"""
% (demand.get("name"),)
)
for problem in demand["problems"]:
html = (
html
+ f"""
<li style="background-color: #fff; margin-bottom: 5px; padding: 15px; border-left: 5px solid #e74c3c;">
{problem["description"]}
</li>
"""
)
html = (
html
+ """
</ul>
</div>
"""
)
html = (
html
+ """
</ul>
</div>
"""
)

if frepple_json["demands"][0].get("constraints"):
html = (
html
+ """
<div style="margin-bottom: 40px;">
<h2 style="margin: 0 0 20px 0; padding-bottom: 10px; border-bottom: 3px solid #e74c3c; color: #e74c3c;">Category: Constraints</h2>
<ul style="list-style-type: none; padding: 0;">
"""
)
for constraint in frepple_json["demands"][0]["constraints"]:
if demand.get("constraints"):
html = (
html
+ f"""
<li style="background-color: #fff; margin-bottom: 5px; padding: 15px; border-left: 5px solid #e74c3c;">
{constraint["description"]}
</li>
"""
+ """
<div style="margin-bottom: 40px;">
<h2 style="margin: 0 0 20px 0; padding-bottom: 10px; border-bottom: 3px solid #e74c3c; color: #e74c3c;">Constraints for %s</h2>
<ul style="list-style-type: none; padding: 0;">
"""
% (demand.get("name"),)
)
for constraint in demand["constraints"]:
html = (
html
+ f"""
<li style="background-color: #fff; margin-bottom: 5px; padding: 15px; border-left: 5px solid #e74c3c;">
{constraint["description"]}
</li>
"""
)
html = (
html
+ """
Expand Down Expand Up @@ -347,7 +346,7 @@ def action_quote(self):

quote.promised_delivery_date = promised_delivery_date_utc

quote.detailed_quote = self._generate_html(response_json)
quote.detailed_quote = Quote.generate_html(response_json)
else:
quote.promised_delivery_date = False
quote.detailed_quote = "N/A"
Expand Down
15 changes: 9 additions & 6 deletions frepple/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import time
import datetime

from .quote import Quote

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -112,13 +114,11 @@ def action_frepple_quote(self):
sale_order.partner_id.id,
)
},
"minshipment": int(
line.product_uom_qty
), # Minimum shipment = Per how many do you want to ship | Zelfde als quantity in the knop
"maxlateness": 86400000, # Binnen x aantal seconden moet ik het hebben | Niet Belangrijk dus staat op 1000 dagen
"priority": 20, # Niet belangrijk, ik neem info over van wat de quote tool doet.
"minshipment": int(line.product_uom_qty),
"maxlateness": 86400000,
"priority": 20,
"policy": (
None
"independent"
if sale_order.picking_policy == "direct"
else "alltogether"
),
Expand Down Expand Up @@ -191,6 +191,9 @@ def action_frepple_quote(self):
"FrePPLe was unable to plan the sales order line(s)"
)

html_response = Quote.generate_html(response_json)
sale_order.message_post(body=html_response, body_is_html=True)

# If multiple lines, we need to get the furthest in time
furthest_end_date = None

Expand Down
Loading

0 comments on commit e31f018

Please sign in to comment.