コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
126 ビュー

Hello,

I have created a new studio field on invoice and would like to add it to pdf formular as well.

How can i add it in V18. 


Thanks in advance for your help.

BR

Sabine

アバター
破棄
最善の回答

Hi Sabine,

Adding a new studio field to a PDF form in V18 typically involves a few steps, often requiring customization of the PDF template. Here's a general approach:

1. Identify the PDF Template:

First, you need to determine which PDF template your invoices are using. In Odoo V18, you can usually find this by going to:

  • Settings > Technical > Reporting > Reports
  • Search for "Invoice" or "Sale Order" related reports.
  • Note down the external ID or module where the report is defined.
2. Locate the QWeb View:

Odoo's PDF reports are usually generated using QWeb views. You'll need to find the specific QWeb view that renders the invoice details. You can usually find this by:

  • Settings > Technical > User Interface > Views
  • Search for views related to "invoice report" or the name you found in step 1. Look for views with type="qweb".
3. Extend or Inherit the QWeb View:

You should not directly modify the original Odoo QWeb view, as your changes would be lost during an update. Instead, you should create a new module and inherit or extend the existing view.

Here's a conceptual outline of what you'd do in your custom module's XML file:

XML    
<odoo> <data> <template id="report_invoice_document_inherit_my_module" inherit_id="account.report_invoice_document"> <xpath expr="//div[@id='informations']" position="after"> <!-- Or find a more appropriate location based on the original template's structure --> <div class="row mt32 mb32"> <div class="col-auto mw-100 mb-2"> <strong>My New Studio Field:</strong> <p t-field="o.x_your_studio_field_name"/> </div> </div> </xpath> </template> </data> </odoo>

Explanation:

  • inherit_id="account.report_invoice_document": Replace account.report_invoice_document with the actual external ID of the invoice report template you found in step 2.
  • <xpath expr="..." position="after">: This is crucial. You need to use an XPath expression to target a specific element in the original template where you want to insert your new field. Common targets could be:
    • //div[@id='informations'] (if you want it near other invoice info)
    • //t[@t-if='o.invoice_origin'] (if you want it near the origin)
    • You'll need to inspect the original QWeb view to find the best xpath to position your field.
  • <p t-field="o.x_your_studio_field_name"/>:
    • o represents the current invoice object.
    • x_your_studio_field_name is the technical name of the studio field you created. You can find this by going to your invoice form in developer mode, hovering over the field, and noting its technical name (it usually starts with x_).
4. Update Your Module:

After adding this XML file to your custom module and ensuring it's loaded (e.g., via __manifest__.py), you'll need to update your module in Odoo:

  • Go to Apps.
  • Search for your custom module.
  • Click "Upgrade".
Example Scenario:

Let's say you added a Studio field called "Customer Reference Number" with the technical name x_customer_ref_number to your account.move model. You want it to appear just below the "Payment Term" on the invoice PDF.

You would inspect the account.report_invoice_document view and find the section for payment terms. Let's assume it looks something like this:

XML
<div t-if="o.invoice_payment_term_id" class="col-auto mw-100 mb-2">
    <strong>Payment Term:</strong>
    <p t-field="o.invoice_payment_term_id.name"/>
</div>


Then your XPath might target this div:

XML
<template id="report_invoice_document_inherit_my_module" inherit_id="account.report_invoice_document"> <xpath expr="//div[contains(@t-if,'o.invoice_payment_term_id')]" position="after"> <div class="col-auto mw-100 mb-2"> <strong>Customer Reference:</strong> <p t-field="o.x_customer_ref_number"/> </div> </xpath> </template>


Important Considerations:
  • Developer Mode: Ensure developer mode is activated in Odoo to access technical menus and inspect views.
  • Debugging: If your field doesn't appear, you might need to:
    • Check Odoo logs for errors.
    • Verify the inherit_id and xpath are correct.
    • Ensure the technical name of your studio field is accurate.
  • Styling: You might need to add CSS classes to your new div or p tags to match the existing styling of the PDF report.
  • Complex Fields: For more complex Studio fields (e.g., Many2one, Many2many), you might need to access their name or other relevant attributes:t-field="o.x_your_many2one_field.name".

This process can be a bit tricky if you're not familiar with QWeb. If you're comfortable with XML and Odoo's technical aspects, it's definitely doable.

Let me know if you have the technical name of your field and can locate the specific report, and I can try to give more tailored advice!

Hope this helps!

アバター
破棄