Skip to content

Commit

Permalink
Quoting updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jdetaeye committed May 13, 2024
1 parent d18d699 commit 2885d62
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
22 changes: 17 additions & 5 deletions frepple/models/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,6 @@ def action_quote(self):
if not base_url.endswith("/"):
base_url += "/"

base_url = base_url.replace("8000", "8002")

webtoken = jwt.encode(
encode_params, user_company_webtoken, algorithm="HS256"
)
Expand All @@ -299,12 +297,23 @@ def action_quote(self):
scenario = "default"

try:
base_url = base_url.replace("localhost", "host.docker.internal")
frepple_response = requests.post(
"%ssvc/%s/quote/%s/" % (base_url, scenario, action),
(
("%ssvc/%s/quote/%s/" % (base_url, scenario, action))
if "8000" not in base_url
else (
"%squote/%s/"
% (
base_url.replace("8000", "8002"),
action,
)
) # Rather ugly logic to recognize development layouts
),
headers=headers,
json=request_body,
)
except:
except Exception:
raise exceptions.UserError(
"The connection with the frePPLe quoting module could not be established"
)
Expand All @@ -319,7 +328,10 @@ def action_quote(self):
quote.detailed_quote = "N/A"
return

response_json = frepple_response.json()
try:
response_json = frepple_response.json()
except Exception:
raise exceptions.UserError("Invalid response from frePPLe")
if (
len(response_json["demands"]) > 0
and "pegging" in response_json["demands"][0]
Expand Down
22 changes: 18 additions & 4 deletions frepple/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _compute_without_quote(self):
else:
enable_quoting_module = self.user_id.id in groups.users.ids
for order in self:
order._without_quote = not enable_quoting_module
order._without_quote = order.state != "draft" or not enable_quoting_module

def use_product_short_names(self):
# Check if we can use short names
Expand Down Expand Up @@ -171,12 +171,23 @@ def action_frepple_quote(self):
scenario = "default"

try:
base_url = base_url.replace("localhost", "host.docker.internal")
frepple_response = requests.post(
"%ssvc/%s/quote/%s/" % (base_url, scenario, action),
(
("%ssvc/%s/quote/%s/" % (base_url, scenario, action))
if "8000" not in base_url
else (
"%squote/%s/"
% (
base_url.replace("8000", "8002"),
action,
)
) # Rather ugly logic to recognize development layouts
),
headers=headers,
json=request_body,
)
except:
except Exception:
raise exceptions.UserError(
"The connection with the frePPLe quoting module could not be established"
)
Expand All @@ -185,7 +196,10 @@ def action_frepple_quote(self):
if response_status_code == 401:
raise exceptions.UserError("User is not authorized to use FrePPLe")

response_json = frepple_response.json()
try:
response_json = frepple_response.json()
except Exception:
raise exceptions.UserError("Invalid response from frePPLe")
if not response_json.get("demands"):
raise exceptions.UserError(
"FrePPLe was unable to plan the sales order line(s)"
Expand Down
1 change: 0 additions & 1 deletion frepple/views/sale_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<!-- E-POWER CUSTOMIZATION -->
<xpath expr="//div[span[@name='expected_date_span']]" position="after">
<field name="_without_quote" invisible="True"/>
<button string="Quote" name="action_frepple_quote" type="object" class="oe_highlight" invisible="_without_quote" confirm="This will send a quote request to frepple"/>
Expand Down

0 comments on commit 2885d62

Please sign in to comment.