Skip to Content
Menu
This question has been flagged

Hello Community, i want to add a new column to the sale order tree view, this new value or field is the qty_invoiced from sale_order_line.py model.

Now, in the sale_views.xml i tried to add this new field in the tree view but got the error that this field does not exist, because this view is for the sale_order.py not sale_order_line.py.

hope to be clear with this explanation, also i use Odoo 15 enterprise, tried to add the field with Studio but doesn't appear in the existing fields.

Here are some sc.


this is the field i want to add.


this is where i want to add the field

if you know the correct method to do this, it'll great if you share

thanks!!!

Avatar
Discard
Best Answer

Hi,

Try this method:

1.Create a new Python file or use an existing one and define a new model that inherits from sale.order.from odoo import models, fields, api

class SaleOrder(models.Model):
    _inherit = 'sale.order'

    qty_invoiced = fields.Float(string='Invoiced Quantity', compute='_compute_qty_invoiced', store=True)

    @api.depends('order_line.qty_invoiced')
    def _compute_qty_invoiced(self):
        for order in self:
            order.qty_invoiced = sum(order.order_line.mapped('qty_invoiced'))
2. In the XML file (your_module/views/sale_order_views.xml), extend the Sale Order tree view and add the new field.

<record id="view_order_tree" model="ir.ui.view">
<field name="name">sale.order.view.tree.inherit</field>
<field name="model">sale.order</field>
    <field name="inherit_id" ref="    sale.view_order_tree"/>
    <field name="arch" type="xml">
<xpath expr="//field[@name='invoice_status']" position="after">
                    <field name="qty_invoiced"/>
                </xpath>
            </field>
</record>


3. Update your manifest file to include the new XML file. Upgrade your module for the changes to take effect.

Avatar
Discard
Related Posts Replies Views Activity
1
Jul 23
3711
2
Jan 24
5356
1
Aug 23
2050
0
Jun 23
1964
1
Jan 23
3475