Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
2153 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
čvc 23
3725
2
led 24
5374
1
srp 23
2056
0
čvn 23
1994
1
led 23
3487