Skip to content

[16.0][IMP][purchase_blanket_order] add send a mail and put supplier…#3080

Open
Kev-Roche wants to merge 1 commit into
OCA:16.0from
akretion:16.0-imp-add_send_a_mail_and_put_supplier_code_in_line_name
Open

[16.0][IMP][purchase_blanket_order] add send a mail and put supplier…#3080
Kev-Roche wants to merge 1 commit into
OCA:16.0from
akretion:16.0-imp-add_send_a_mail_and_put_supplier_code_in_line_name

Conversation

@Kev-Roche

Copy link
Copy Markdown
Contributor

… code in line name

This PR Add "Send by Email" button on Purchase Blanket Orders and fix purchase order line name to use supplier code.

@OCA-git-bot OCA-git-bot added series:16.0 mod:purchase_blanket_order Module purchase_blanket_order labels May 28, 2026
@Kev-Roche Kev-Roche force-pushed the 16.0-imp-add_send_a_mail_and_put_supplier_code_in_line_name branch 3 times, most recently from 9dc9b98 to dbb7562 Compare May 28, 2026 10:24

@BhaveshHeliconia BhaveshHeliconia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have completed the review of the code implementation for the Purchase Blanket Order Email Template
Here is a summary of the assessment and the optimizations applied:

  1. Email Subject Line Enhancement
  • Current state: {{ object.name }} (e.g., BO00001)
  • Issue: Receiving an email with just a document number can easily look like spam or confuse suppliers, resulting in lower open rates.
  • Fix: Upgraded the subject line to include the company name and document type context:
    {{ object.company_id.name }} Blanket Order (Ref {{ object.name or '' }})
  1. HTML Structure Fixes (Body HTML)
  • Issue: The original template placed a tag directly inside a
    layer without an enclosing wrapper. This is semantically invalid HTML and causes layout breakage across strict email clients like Microsoft Outlook and Gmail.
  • Fix: Re-structured the markup into an Odoo-standard responsive HTML email table container.

@BhaveshHeliconia

Copy link
Copy Markdown
Contributor
  1. Company Branding & Fallbacks
  • Improvement: Included the company context inside the email text body. If a Blanket Order is sent but the internal Odoo user profile (object.user_id) lacks a properly configured name, the signature will seamlessly fall back onto the company name (object.company_id.name) to maintain a professional appearance.
  1. Backend Python Optimization
  • Sanitized the context dictionary layout using Odoo's native clean_context() helper method to prevent active view variables from conflicting with the Mail Composer wizard.
  • Streamlined the dynamic variable assignment using modern Python conditional expressions.

@Kev-Roche Kev-Roche force-pushed the 16.0-imp-add_send_a_mail_and_put_supplier_code_in_line_name branch from dbb7562 to af513fd Compare June 19, 2026 13:09
@Kev-Roche

Copy link
Copy Markdown
Contributor Author

Thanks @BhaveshHeliconia for your review, I applied your suggestions about 1,2,3 but did not understand the 4th point.

@Kev-Roche Kev-Roche force-pushed the 16.0-imp-add_send_a_mail_and_put_supplier_code_in_line_name branch from af513fd to 9694b60 Compare June 19, 2026 13:11
"purchase_blanket_order.email_template_blanket_order",
raise_if_not_found=False,
)
ctx = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. "Sanitized the context dictionary layout using Odoo's native
    In your original method, you defined the context dictionary like this:
    ctx = {
    "default_model": "purchase.blanket.order",
    "default_res_id": self.id,
    ...
    }

When you return an action to open a new wizard window in Odoo, Odoo automatically carries over the current view's context (self.env.context).

If your user clicked the "Send Email" button from a specific Kanban view, a Search filter, or an active form view action, variables like active_id, active_model, or view-specific default values (e.g., default_partner_id) are passed silently along in the background. When the Mail Composer wizard opens up, these hidden context keys can conflict with the email wizard's fields, causing visual bugs, wrong data population, or access errors.

The Optimized Fix:
ctx = dict(clean_context(self.env.context))
ctx.update({
"default_model": "purchase.blanket.order",
"default_res_id": self.id,
# ...
})
Odoo's native clean_context() strips out all action-specific, search-specific, and view-specific keys (like active_id, search_default_..., etc.) from the environment context. It hands you a clean slate. By converting it to a dictionary and updating it, you guarantee that only the specific parameters you intend for the Mail Composer are passed, eliminating unpredictable backend bugs.

  1. "Streamlined the dynamic variable assignment using modern Python conditional expressions."
    In your original snippet, the template ID assignment was written using old Python/Odoo legacy shorthand notation:
    "default_template_id": template and template.id or False,
    This is an old-school way of writing an inline fallback condition. It works like this: If template is true, evaluate template.id. If template.id is true, return it; otherwise return False.

While it works most of the time, it introduces a dangerous edge case in Python: if template.id evaluates to 0 (or any falsy value), the expression will mistakenly skip to the or False statement. While Odoo database IDs are rarely 0, it is still structurally unsafe and harder to read at a glance.
"default_template_id": template.id if template else False,

This uses modern Python ternary operators (conditional expressions). It translates perfectly to human-readable logic: "Give me template.id if a template exists, otherwise give me False."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:purchase_blanket_order Module purchase_blanket_order series:16.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants