[16.0][IMP][purchase_blanket_order] add send a mail and put supplier…#3080
[16.0][IMP][purchase_blanket_order] add send a mail and put supplier…#3080Kev-Roche wants to merge 1 commit into
Conversation
9dc9b98 to
dbb7562
Compare
There was a problem hiding this comment.
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:
- 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 '' }})
- 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.
|
dbb7562 to
af513fd
Compare
|
Thanks @BhaveshHeliconia for your review, I applied your suggestions about 1,2,3 but did not understand the 4th point. |
…code in line name
af513fd to
9694b60
Compare
| "purchase_blanket_order.email_template_blanket_order", | ||
| raise_if_not_found=False, | ||
| ) | ||
| ctx = { |
There was a problem hiding this comment.
- "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.
- "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."
… 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.