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

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?


Imagine profil
Abandonează

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

Cel mai bun răspuns

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



Imagine profil
Abandonează
Cel mai bun răspuns

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  

Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
mar. 16
8505
3
mar. 15
52277
4
mar. 15
11635
1
iun. 24
2585
1
ian. 24
15226