Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2278 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 7 23
3827
2
thg 1 24
5491
1
thg 8 23
2167
0
thg 6 23
2069
1
thg 1 23
3589