Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
2211 Vizualizări

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!!!

Imagine profil
Abandonează
Cel mai bun răspuns

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.

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
iul. 23
3769
2
ian. 24
5432
1
aug. 23
2099
0
iun. 23
2028
1
ian. 23
3506