To solve this optimization problem, we first need to define the decision variables and the objective function. Let's denote the number of laptop bags as \(x\) and the number of briefcases as \(y\).

The objective is to maximize profit. Given that each laptop bag yields a profit of $80 and each briefcase yields a profit of $50, the total profit can be represented by the equation:
\[ \text{Profit} = 80x + 50y \]

We also have constraints based on the time available for sewing and painting. For sewing, with 12 minutes required per laptop bag and 10 minutes per briefcase, and a total of 300 minutes available, we have:
\[ 12x + 10y \leq 300 \]

For painting, with 5 minutes required per laptop bag and 9 minutes per briefcase, and a total of 500 minutes available, we have:
\[ 5x + 9y \leq 500 \]

Additionally, \(x\) and \(y\) must be non-negative since they represent quantities of bags.

Now, let's translate this problem into Gurobi code in Python:

```python
from gurobipy import *

# Create a new model
m = Model("Factory_Optimization")

# Define the decision variables
x = m.addVar(lb=0, vtype=GRB.INTEGER, name="laptop_bags")
y = m.addVar(lb=0, vtype=GRB.INTEGER, name="briefcases")

# Set the objective function to maximize profit
m.setObjective(80*x + 50*y, GRB.MAXIMIZE)

# Add constraints for sewing and painting time
m.addConstr(12*x + 10*y <= 300, "sewing_time")
m.addConstr(5*x + 9*y <= 500, "painting_time")

# Optimize the model
m.optimize()

# Print out the results
if m.status == GRB.OPTIMAL:
    print("Optimal solution found:")
    print(f"Number of laptop bags: {x.x}")
    print(f"Number of briefcases: {y.x}")
    print(f"Total profit: ${80*x.x + 50*y.x:.2f}")
else:
    print("No optimal solution found")

```