Skip to Content
Course content

Lecture 1.1: Introduction to Python and Odoo

ODOO PYTHON BOOTCAMP / LECTURE 1.1

Learn to program.
Learn to think in systems.

AI can help you write code. Building a dependable business system still requires you to understand what that code means.

FOUNDATIONSREAD · TRACE · TRY · EXPLAINNO PYTHON EXPERIENCE REQUIRED

01 / THE WORK BEHIND THE CODE

Someone still has to decide what “correct” means.

Imagine a library that lets members borrow books. An AI assistant produces a working checkout screen in minutes. It looks convincing. But can a member borrow a copy already on loan? Can a clerk see another branch’s members? What happens when two clerks try to lend the same copy at once?

Those are programming questions, business questions and security questions at the same time. A screen that saves a record is only the beginning. The system must preserve the rules people rely on, including when users make mistakes or requests arrive together.

You do not need to memorize the framework. You do need to learn how to investigate it. Python gives us a precise way to express rules; Odoo provides models, views, access controls and other application services; PostgreSQL stores durable data. We will connect those tools to business decisions.

01

Describe

State the rule in words a business owner can confirm.

02

Implement

Make the rule explicit in a small, readable change.

03

Verify

Try the normal case, boundary and failure. Explain the evidence.

What you will be able to do after this lesson

  • Trace a borrowing request from a person to stored records and back.
  • Distinguish a business process, data flow, model relationship and object snapshot.
  • Explain how durable engineering skills guide both your work and an AI assistant.
  • Run a small Python rule and check its boundary cases.

02 / FOLLOW THE DATA

Before writing a method, draw the movement.

A diagram earns its place when it helps you answer a question. We will use several views of the same small library example. It is a teaching scenario, not a claim that every later project uses this domain.

First view: what happens in the business?

PROCESS MAPOne borrowing request
REQUESTMember asks for a copy
→
DECISIONCheck membership, limit & availability
→
IF ALLOWEDCreate the loan
→
CONFIRMShow the due date
If a check fails → Explain the reason. Do not create a loan.
A process map shows activities and decisions. Ask who owns each step, where delays occur and what exceptions need a human decision.

Systems thinking asks what happens beyond the screen: lending changes availability, overdue loans affect eligibility, and a return changes what another member can borrow. Business process engineering asks whether the workflow itself is sensible before we automate it. Automating a confused process makes the confusion faster.

Second view: what crosses the system boundary?

DATA FLOW / CONTEXT VIEWInputs and outputs have names
EXTERNAL ACTORLibrary clerk
member ID + copy ID→
PROCESS 0Library borrowing system
confirmation + due date
or refusal reason
→
EXTERNAL ACTORLibrary clerk
The two clerk boxes represent the same actor, repeated for readability. This is a data-flow view: arrows name information, not the order in which a user clicks buttons.

Now open the box.

DATA FLOW / INSIDE THE SYSTEMRequest → decision → durable record
1 / VALIDATE REQUESTAuthenticated clerk
member ID · copy ID

Check the clerk’s permission and record access.

2 / EVALUATE RULESMembership status
active loans · copy status

Read only the records this operation is allowed to use.

3 / RECORD RESULTLoan data or refusal

Create a loan only if all rules hold.

Member store ── status ──→ 2 / Evaluate rules

Copy store ── copy status ──→ 2 / Evaluate rules

Loan store ── current loans ──→ 2 / Evaluate rules

1 / Validate request ── authorized request ──→ 2 / Evaluate rules

2 / Evaluate rules ── allowed loan data ──→ 3 / Record result

3 / Record result ── new loan ──→ Loan store

1, 2 or 3 ── refusal or confirmation ──→ Clerk

Rectangles labelled “store” hold data; numbered boxes transform or validate it. This simplified logical view omits transport details. Writing safely also requires transaction and concurrency handling: a prior availability read alone cannot prevent two simultaneous loans.
Pause & trace · Where could the wrong result begin?

The clerk submits a member ID, but the system never reads membership status. Can the interface alone enforce “active members only”?

Reason it through: No. A hidden or disabled button does not protect another request path. The server must validate the rule using the relevant data. Draw the missing status flow before asking AI to change the code.

Where does Python fit?

Browser / interfaceDisplays data and captures actions. Odoo uses JavaScript, Owl components and templates where appropriate.
Python / Odoo serverModels, business methods, validation, access checks and request handling.
ORM / PostgreSQLOdoo’s object-relational mapper reads and writes database records; PostgreSQL also enforces database constraints.

QWeb renders Odoo templates, including the page around this article. Article content is stored HTML; it does not automatically execute arbitrary QWeb directives or mount Owl widgets. Choose the interface mechanism to fit the job. The business rule still needs protection on the server.

03 / GIVE THE BUSINESS A SHAPE

Relationships are decisions, too.

A title is not a physical copy. A member is not a loan. Separating those concepts lets us represent two copies of the same book, a member’s borrowing history and the difference between “returned” and “never borrowed.”

ENTITY–RELATIONSHIP DIAGRAMStructure: what can relate to what?

Book

PK id

title

1 → 0..*has copies

Copy

PK id

FK book_id → Book

barcode

Member

PK id

name · active

1 → 0..*has loans

Loan

PK id

FK member_id → Member

FK copy_id → Copy

due_date · returned_at

Copy 1 → 0..* Loan over time; each loan references exactly one copy and one member.
PK = primary key; FK = foreign key. 0..* means zero or more. In this example every copy belongs to one book. History permits many loans per copy; “at most one open loan per copy” is an additional invariant, not something this cardinality enforces.

Normalization helps avoid conflicting copies of the same fact. Store a book’s title on Book; refer to it through Copy and Loan instead of typing it into every loan row. A title correction then has one authoritative place. Some business records intentionally preserve historical snapshots; choose that deliberately and document why.

OBJECT DIAGRAMSnapshot: which records exist right now?

member_17 : Member

name = “Amina”
active = True

loan_93 : Loan

member_id = 17
copy_id = 42
returned_at = None

copy_42 : Copy

book_id = 8
barcode = “LIB-0042”

loan_93 → member_17 via member_id · loan_93 → copy_42 via copy_id · copy_42 → book_8 via book_id
These are invented example records, not live site data. The ERD defines possible relationships; the object diagram shows particular instances and links. Here copy 42 has an open loan, so a second open loan must be rejected.
Check your model · Why not put member_id directly on Book?

Two copies of one title can be borrowed by different members. A single member field on Book cannot represent that or retain loan history. Copy identifies the physical item; Loan records each borrowing event.

04 / SKILLS THAT OUTLAST THE TOOLS

Thirteen habits to carry into every build.

These are the lenses we will use to improve the course. This introduction establishes the vocabulary; it does not assume you already know the techniques. Open each card for a concrete question you can ask about your own work.

Understand the work

01 Systems thinking

Look at boundaries, dependencies and feedback, not just the method in front of you. A return changes availability, which changes what another member can borrow.

Ask: If this record changes, which people, processes and downstream records are affected?

02 Business process engineering

Map actors, decisions, exceptions and handoffs before automating. Find out who handles a damaged copy or an eligibility dispute.

Ask: Is this the right process, and who owns the exception?

03 Requirements discovery & critical reasoning

Turn “make checkout easy” into observable acceptance criteria. Confirm whether the borrowing limit is per member, branch or membership type. Separate evidence from assumptions.

Ask: What example would show that we misunderstood the requirement?

Design the structure

04 Design patterns

Recognize recurring design problems and proven ways to address them. A policy or Strategy pattern may help if different membership types need interchangeable eligibility rules. A simple function may be enough first.

Ask: What actually varies, and does a pattern make that variation easier to understand?

05 SOLID principles

Single responsibility: keep eligibility decisions separate from reminder delivery. Open/closed: allow a new policy without rewriting unrelated behavior. Liskov substitution: a replacement policy must honor its promised contract. Interface segregation: callers should not depend on methods they do not need. Dependency inversion: business decisions should depend on a stable contract rather than a particular email or API provider.

Ask: Can I change a borrowing rule without breaking unrelated features? Apply these principles with Odoo’s extension conventions; do not add layers just to satisfy an acronym.

06 Model relationships & database normalization

Choose entities, cardinalities and sources of truth deliberately. Book, Copy and Loan represent different facts. Use relationships rather than repeated text where the domain calls for it.

Ask: Which fact could disagree with another copy of itself, and what prevents impossible states?

07 Security: roles, access rights & record rules

Define who may do what and to which records. Odoo model access rights grant operations; record rules restrict eligible records. Field restrictions and server logic may also be needed. Test with real restricted roles: an administrator session is not evidence of learner or clerk access.

Ask: Can a clerk from branch A read or change branch B’s loans through a direct request? Avoid broad elevated access as a shortcut.

08 Integration & failure design

Expect external services to be slow, unavailable or to deliver the same event twice. Decide timeout, retry and duplicate-handling behavior. A retried checkout request must not silently create another loan.

Ask: If the caller repeats this after a timeout, can the operation safely run again?

Deliver with evidence

09 Project management

Break the work into reviewable slices, make dependencies visible and define “done.” Deliver one safe borrowing flow before adding reminders, reporting and multiple branches.

Ask: What is the smallest useful change we can demonstrate, test and recover from?

10 Context engineering

Give an AI assistant the business rule, relevant model definitions, exact Odoo version, permitted scope, examples and acceptance tests. Include uncertainties and ask it to identify missing information. Keep credentials and private customer data out of the prompt.

Ask: Does the assistant have the context needed to distinguish a plausible answer from the correct one?

11 Test-driven development

State a behavior in a test, watch it fail for the expected reason, implement enough to pass, then improve the design while keeping the test green. For a three-loan limit, check both two active loans and three.

Ask: What failing test would expose the mistake before we write the implementation?

12 Debugging & observability

Reproduce a problem, form a hypothesis and follow evidence across layers. Use useful logs and tracebacks without exposing sensitive data. If a loan is refused, distinguish an access failure from an eligibility failure.

Ask: What observation would confirm or disprove my explanation?

13 Technical communication & decision records

Explain a design to a business owner and leave the next developer a reason for the choice. Record why a loan stores its original due date even if the lending policy later changes.

Ask: Could someone maintain this safely without the original conversation?

Use AI deliberately: a small SWOT.

SWOT / AI-ASSISTED DEVELOPMENTA planning tool, not a quality certificate
S / STRENGTHS

Fast drafts & alternatives

Useful for explaining unfamiliar code, drafting tests and comparing designs.

W / WEAKNESSES

Missing local understanding

A plausible answer may assume the wrong model, business rule or framework version.

O / OPPORTUNITIES

More time for reasoning

Use faster drafts to explore failure cases, review relationships and improve explanations.

T / THREATS

Errors that look finished

Unreviewed changes can expose data, corrupt records or create maintenance costs.

Strengths and weaknesses describe the tool in this workflow; opportunities and threats describe consequences in its wider use. These are practical judgments, not measured performance claims. Turn each concern into a review or test.
A useful AI brief

“In our learning example, active members may hold at most three open loans. Here are the model definitions and framework version. First identify missing requirements, especially permissions and simultaneous requests. Propose tests for the limit, inactive membership and an unavailable copy. Explain the change before implementing it.”

05 / MAKE A RULE EXECUTABLE

Your first experiment: predict, run, explain.

Python uses names for values, functions for reusable behavior, and indentation to group statements. You will learn each of those in the next lessons. For now, read this small rule aloud: borrowing is allowed when the member is active and their number of active loans is less than three.

PYTHON / A PURE RULE, WITHOUT ODOO
def can_borrow(member_active, active_loans):
    return member_active and active_loans < 3

print(can_borrow(True, 2))   # predict before running
print(can_borrow(True, 3))
print(can_borrow(False, 0))

Save this as borrowing_rule.py and run python3 borrowing_rule.py in your development environment. On systems using a different launcher, use that environment’s Python 3 command. If Python is not installed yet, use the following installation lesson first, then return here. Do not experiment in a live Odoo shell.

Reveal the output and explain the boundary
True
False
False

True and False are Boolean values. < 3 excludes three; changing it to <= 3 would allow a fourth loan. and requires both conditions to hold. This is why a tiny operator deserves a boundary test.

TEST-DRIVEN DEVELOPMENTTurn the boundary into a repeatable check
REDWrite a test.
See the expected failure.
→
GREENImplement just enough
to make it pass.
→
REFACTORImprove the design.
Keep the tests passing.
Repeat for the next behavior. A test that never failed may not prove what you think it proves.
PYTHON / BEGINNER CHECKS
assert can_borrow(True, 2) is True
assert can_borrow(True, 3) is False
assert can_borrow(False, 0) is False

assert raises an error if its condition is false. These are learning checks, not production validation or a complete Odoo test suite. For a first red–green exercise, temporarily return True from the function, run the checks and observe which one fails; then restore the rule. In later work, write the test before the implementation.

Five minutes of design before the next lecture

  1. Change one requirement: premium members may hold five loans. What new information must the rule receive?
  2. Draw its data flow: label where membership type comes from and where the decision goes.
  3. Write two examples: a premium member with four loans and one with five. Predict both results.
  4. Explain one risk: what happens if the browser can choose its own membership type?
Compare your reasoning

The rule needs a trusted limit or membership policy. Four is below five, so that case is allowed; five is at the limit, so it is refused. The server must obtain authoritative membership information rather than trusting a browser-provided entitlement. Passing a limit makes this small rule reusable, but validating who receives that limit belongs to the surrounding application.

06 / YOUR ROUTE THROUGH THE COURSE

Start small. Keep the whole system in view.

The saved course has seven sections: Python Basics for Odoo Development; Odoo 18 Essentials; Python Logic for Odoo Applications; Building Practical Odoo Applications; Advanced Python and Odoo Techniques; a Coinbase Trading Bot capstone; and an Art & Music Exploration Platform capstone. Each offers opportunities to ask the same questions about behavior, data, permissions and evidence.

Take these questions into the next lesson

Can you trace it?

Name the input, authoritative data, rule, stored result and response.

Can you defend it?

Explain the relationship, permission boundary, failure case and test.

You are learning to build systems that people can rely on. Syntax is the starting point. Understanding the work, modeling it clearly and checking it carefully are the skills that make the code useful.

UP NEXT / LECTURE 1.2Python Syntax and Data Types

Give business facts precise names and values.

Continue to data types →

This lecture serves as an introductory session designed to equip you with the foundational knowledge required for developing applications using the Odoo framework, leveraging the power of Python programming.

Throughout this lecture, we will explore several key areas that will lay the groundwork for your journey as an Odoo developer. The primary functional goals we aim to accomplish include understanding the basics of Python, familiarizing ourselves with the Odoo framework, and setting up our development environment for Odoo 18.

Commenting is not enabled on this course.