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

I want to update the existing Sales Order Line tree view that is embedded in the default Odoo 9 Sales Order form view to hide a row based on a condition of the sales order line


View being modified: sale.view_order_form

<notebook>

<page string="Order Lines">

<field name="order_line" mode="tree,kanban" attrs="{'readonly': [('state', 'in', ('done','cancel'))]}">

...

<tree string="Sales Order Lines" editable="bottom" decoration-info="invoice_status=='to invoice'">

<field name="sequence" widget="handle"/>

<field name="product_id"/>

<field name="name"/>

...

<field name="is_delivery" invisible="1"/>

...


Generally, there is only one item which "is_delivery", so I still want to see the rest of the items for the order.


I have tried using domain and attrs but so far I haven't had any success whatsoever. I think it is because the view is using the sale.order model, but the embedded tree view is using records from sale.order.line?


How can I hide the line item if "is_delivery" is True?


Ảnh đại diện
Huỷ bỏ

have you found a way to do so?

I am in the exact same situation, how did you came over this problem?
Thanks in advance

Câu trả lời hay nhất

Hii,

Inherit the sale.order model and add a computed One2many field:

from odoo import models, fields, api


class SaleOrder(models.Model):

    _inherit = 'sale.order'


    filtered_order_line = fields.One2many(

        comodel_name='sale.order.line',

        compute='_compute_filtered_order_line',

        string='Filtered Order Lines',

        store=False,  # not stored, always computed

    )


    @api.depends('order_line.is_delivery')  

    def _compute_filtered_order_line(self):

        for order in self:

            order.filtered_order_line = order.order_line.filtered(lambda l: not l.is_delivery)


Inherit the original Sales Order form view (sale.view_order_form) and replace the existing order_line field with your new computed field filtered_order_line.


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

    <field name="name">sale.order.form.hide.delivery.lines</field>

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

    <field name="inherit_id" ref="sale.view_order_form"/>

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

        <xpath expr="//page[@string='Order Lines']/field[@name='order_line']" position="replace">

            <field name="filtered_order_line" mode="tree,kanban" attrs="{'readonly': [('state', 'in', ('done','cancel'))]}">

                <tree editable="bottom" string="Sales Order Lines">

                    <field name="sequence" widget="handle"/>

                    <field name="product_id"/>

                    <field name="name"/>

                    <field name="product_uom_qty"/>

                    <field name="price_unit"/>

                    <field name="tax_id"/>

                    <field name="price_subtotal"/>

                    <!-- Optional: include is_delivery as invisible just for context -->

                    <field name="is_delivery" invisible="1"/>

                </tree>

            </field>

        </xpath>

    </field>

</record>


i hope it is usefull



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

Interesting question! I've tackled similar visibility issues. One approach is customizing the view definition using XPath expressions based on the 'is_delivery' boolean. Another simpler method might be leveraging computed fields & conditional formatting within Odoo's interface. If you're a fan of puzzles, this is like a code-based  

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

Hello,

Just as a suggestion: try to add a new field to sale.order.line which is 'active', the active field toggle the global visibility of the record as in the documentation , and you can do some changes that when the order line set to is_delivery toTrue then set the active to False

hope this could helps

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 16
8560
3
thg 3 15
52369
4
thg 3 15
11697
1
thg 6 24
2625
1
thg 1 24
15265