Skip to Content
मेन्यू
This question has been flagged
1 Reply
105 Views

i want to add a custom field in a quotation and fill it manually each time then it appears in the pdf when i create an invoice

Avatar
Discard
Best Answer

Hi,


Step 1: Create the Custom Field in the sale.order Model


Activate developer mode and create a custom module (if you don't have one). In your custom module's models/sale_order.py file, add a new field to the sale.order model using _inherit. Define the field with an appropriate type (e.g., fields.Text for multi-line text), a descriptive string for the label, and set store=True to ensure the field is stored in the database.


from odoo import models, fields, api


class SaleOrder(models.Model):

    _inherit = 'sale.order'


    x_custom_field = fields.Text(string="Your Custom Field", store=True)


Step 2: Add the Field to the Quotation Form View


In your custom module's views/sale_order_views.xml file, create a view inheritance to modify the existing quotation form view. Use an xpath expression to specify where to insert the new field in the form. Add the <field name="x_custom_field"/> tag to include the custom field in the form view.


<odoo>

        <record id="sale_order_form_custom_field" model="ir.ui.view">

            <field name="name">sale.order.form.custom.field</field>

            <field name="model">sale.order</field>

            <field name="inherit_id" ref="sale.view_order_form"/>

            <field name="arch" type="xml">

                <xpath expr="//notebook/page[@name='other_information']/group" position="inside">

                    <field name="x_custom_field"/>

                </xpath>

            </field>

        </record>

</odoo>


Step 3: Update the Module


Go to the Apps module in Odoo and update your custom module. This will install the new field and view changes, making the custom field visible in the quotation form.


Step 4: Add the Field to the Invoice PDF Report


Identify the ID of the invoice PDF report template (e.g., account.report_invoice_document). In your custom module's views/report_invoice_views.xml file, create a view inheritance to modify the report template. Use an xpath expression to specify where to insert the custom field in the PDF report. Add the necessary HTML and QWeb code to display the custom field's label and value in the PDF.


<odoo>

        <template id="report_invoice_document_custom_field" inherit_id="account.report_invoice_document">

            <xpath expr="//div[@class='page']/div[@class='row mt20']" position="inside">

                <div class="col-auto mw-100 mb-2">

                    <strong>Your Custom Field:</strong>

                    <p t-field="o.x_custom_field"/>

                </div>

            </xpath>

        </template>

</odoo>


Step 5: Update the Module


Go to the Apps module and update your custom module. This will install the new report view changes, ensuring that the custom field appears in the generated invoice PDFs.


Hope it helps

Avatar
Discard
Related Posts Replies Views Activity
2
अग॰ 25
4169
1
फ़र॰ 25
7940
3
अक्तू॰ 25
276
2
अग॰ 25
1080
2
जुल॰ 25
2909