Skip to Content
Menu
This question has been flagged
2 Replies
149 Zobrazenia

In Odoo 17, I need to display the vendor’s bank account number directly on the Purchase Order, both in the form view and in the PDF report, because the client requires advance payments against the PO and Accounting needs to see the account number as soon as the PO is generated. In vendor bills (account.move), Odoo already includes the fields bank_partner_id and partner_bank_id with the domain [('partner_id', '=', bank_partner_id)], which works perfectly to show only the vendor’s bank accounts. However, in Purchase Orders (purchase.order), these fields do not exist. I tried to replicate them in Odoo Studio by creating a Many2one field and copying the same domain/context, but when validating the view I get the error: “Field 'bank_partner_id' used in context ({'default_partner_id': bank_partner_id}) must be present in view but is missing”.

What I need is a way to show the vendor’s bank account on the Purchase Order. Ideally, either (A) automatically display it as a related field pointing to partner_id.bank_ids, or (B) allow the buyer to select from the vendor’s bank accounts, just like in vendor bills, and then have that value appear in the PO report. My questions are: what is the cleanest way to implement this? Should I extend purchase.order with a partner_bank_id Many2one field (like in account.move) and add the domain on partner_id, or create a bank_partner_id related to partner_id to replicate invoice logic? Also, is there a recommended hook or method to extend this properly in custom code instead of hacking it in Studio? Finally, from a business perspective, do you consider it bad practice to display vendor bank details on the PO? The client requires it because of advance payments, but normally Odoo only handles this at the invoice/payment stage.

How would you implement this in Odoo 17 so that it works smoothly in both the form and the report?

Avatar
Zrušiť
Best Answer

Hello Pedro,



  To display the vendor's bank account number on the Purchase Order in Odoo 17, you can follow these steps. This approach involves extending the purchase.order model to include the vendor's bank account information, ensuring it appears both in the form view and the PDF report. Here's a clean and effective way to achieve this:

  1. Create a new Many2one field in the purchase.order model via a custom module to hold the vendor's bank account. This field should relate to the res.partner.bank model. Use the domain to filter bank accounts based on the vendor's ID.

  2. In your custom module, override the create and write methods of the purchase.order model to automatically populate this field based on the vendor's default bank account or allow users to manually select it.

  3. Update the form view of the Purchase Order in Odoo Studio to include this new field, ensuring it's visible and editable as needed.

  4. Modify the Purchase Order report template to include the bank account information. This might require extending the report's QWeb template to display the new field.

  Regarding your question about business practices, displaying vendor bank details on the PO can be sensitive. It's generally safe if your Odoo instance is secure and access to POs is restricted to authorized personnel. However, always ensure compliance with your local data protection regulations.


For personalized assistance:
https://www.pragtech.co.in/contact-us-mql.html

Avatar
Zrušiť
Best Answer

Hi,


In Odoo 17, the cleanest way to show vendor bank details on Purchase Orders is to extend the purchase.order model with a new partner_bank_id field, similar to what exists in invoices. This field should be a Many2one to res.partner.bank with a domain restricting it to the selected vendor’s bank accounts. If needed, it can also auto-populate when a vendor is chosen, for example by defaulting to the first available bank account.


On the user interface side, this field can be added to the Purchase Order form view, and the chosen bank account can also be displayed in the Purchase Order PDF report by referencing o.partner_bank_id.acc_number. This mirrors the logic Odoo already uses in accounting and ensures that the right account details are available early in the process.


From a business perspective, while Odoo normally introduces bank details at the invoice or payment stage, adding them directly to Purchase Orders is not bad practice if the client requires advance payments. It provides clarity to Accounting and ensures payments are directed correctly. Overall, this customization is straightforward and robust, and it integrates smoothly with Odoo’s standard logic.


The cleanest way is to extend the model in Python, not in Studio. You only need one extra field on purchase.order:


from odoo import fields, models



class PurchaseOrder(models.Model):

    _inherit = "purchase.order"


    partner_bank_id = fields.Many2one(

        "res.partner.bank",

        string="Vendor Bank Account",

        domain="[('partner_id', '=', partner_id)]",

        help="Bank account of the vendor for advance payments",

    )



XML


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

    <field name="name">purchase.order.form.inherit.bank</field>

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

    <field name="inherit_id" ref="purchase.purchase_order_form"/>

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

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

            <field name="partner_bank_id"/>

        </xpath>

    </field>

</record>



-Add it to the PO report (QWeb). For example, in report_purchaseorder_document:


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

    <p>

        <strong>Vendor Bank Account:</strong>

        <span t-esc="o.partner_bank_id.acc_number"/>

    </p>

</xpath>



Hope it helps

Avatar
Zrušiť
Related Posts Replies Zobrazenia Aktivita
1
aug 25
588
0
jan 25
1184
0
dec 24
1096
1
máj 25
1056
1
mar 25
1350