Looking for a simple form app mobile friendly ; section that gets contact info ; section order info ; when submitting it creates an odoo sales order
To upload files, please first save the app
import streamlit as st
from datetime import datetime
from sqlalchemy import create_engine, Column, Integer, String, Float, DateTime
from sqlalchemy.orm import DeclarativeBase, Session
# Set page config for mobile-friendly display
st.set_page_config(
page_title="Order Form",
layout="centered",
initial_sidebar_state="collapsed"
)
# Custom CSS for mobile-friendly design
st.markdown("""
<style>
.stButton>button {
width: 100%;
margin-top: 10px;
}
.stTextInput>div>div>input {
padding: 15px 10px;
}
</style>
""", unsafe_allow_html=True)
# Database setup
class Base(DeclarativeBase):
pass
class Order(Base):
__tablename__ = "orders"
id = Column(Integer, primary_key=True)
# Contact Information
name = Column(String)
email = Column(String)
phone = Column(String)
# Order Information
product = Column(String)
quantity = Column(Integer)
unit_price = Column(Float)
total_amount = Column(Float)
notes = Column(String)
created_at = Column(DateTime, default=datetime.utcnow)
engine = create_engine("sqlite:///orders.sqlite")
Base.metadata.create_all(bind=engine)
def create_order(order_data):
with Session(engine) as session:
new_order = Order(**order_data)
session.add(new_order)
session.commit()
return new_order.id
# App Header
st.title("📱 Order Form")
# Use forms to batch the input fields
with st.form("order_form", clear_on_submit=True):
# Contact Information Section
st.subheader("📋 Contact Information")
name = st.text_input("Full Name*")
email = st.text_input("Email Address*")
phone = st.text_input("Phone Number*")
# Order Information Section
st.subheader("🛍️ Order Details")
# Sample product list - this could be fetched from Odoo in a real implementation
product = st.selectbox(
"Product*",
["Product A - $100", "Product B - $150", "Product C - $200"]
)
quantity = st.number_input("Quantity*", min_value=1, value=1)
# Calculate unit price from product selection
unit_price = float(product.split("$")[1])
total_amount = unit_price * quantity
st.write(f"Total Amount: ${total_amount:.2f}")
notes = st.text_area("Additional Notes")
submitted = st.form_submit_button("Submit Order")
if submitted:
if name and email and phone: # Basic validation
order_data = {
"name": name,
"email": email,
"phone": phone,
"product": product,
"quantity": quantity,
"unit_price": unit_price,
"total_amount": total_amount,
"notes": notes
}
try:
order_id = create_order(order_data)
st.success(f"Order #{order_id} has been created successfully!")
# Here you would typically integrate with Odoo API to create the sales order
# For demonstration, we'll just show a success message
st.info("Note: In a production environment, this would create an Odoo sales order.")
except Exception as e:
st.error(f"An error occurred while processing your order: {str(e)}")
else:
st.error("Please fill in all required fields marked with *")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?