Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
10429 Tampilan

I'm trying to hide the invoice lines where quantity is set to 0, so I edited account.invoice.form view, and tried with:

...
<page string="Invoice Lines">
  <field name="invoice_line" nolabel="1" widget="one2many_list" domain="[('quantity', '&gt;', 0)]">
    <tree string="Invoice Lines" editable="bottom">
      <field name="sequence" widget="handle"/>...

But this doesn't have any effect at all. No matter what I put into domain, the list remains the same.

Please advise. Thanks!

Avatar
Buang
Jawaban Terbai

Hi!

Using domain would not lead you to required behavior. In case of tables it is used in case of many2many fields in order to restrict selection, not visibility of rows. So, it is a constraint to choose records

If I'm not mistaken, the only way to achieve the desired requirement, is to re-define the functions on the Python level. 

I guess, there are 2 alternatives:

1. TO re-define the get method of a related model. Technically better, but may influence other places, where lines are used in the interface

2. To create a new computed table, where to put only desired lines, and inverse them in original method. This is logically simplier, e.g.:

To the model account invoice:

@api.multi def _compute_new_line_ids(self)

for invoice in self:

 new_ids = invoice.line_ids.filtered(

                lambda t: t.quantity > 0,

            )

 invoice.new_line_ids = [(6,0,new_ids.ids )]

 new_ids = invoice.line_ids.filtered(

                lambda t: t.quantity == 0,

            )

 invoice.new_line_ids_zero = [(6,0,new_ids.ids )]

@api.multi def _inverse_new_line_ids(self):

for invoice in self:

invoice.line_ids = [(6,0,invoice.new_line_ids + invoice.new_line_ids_zero)]

new_line_ids = fields.One2many(

"account.invoice.line",

"invoice_new_id",

compute=_compute_new_line_ids,

inverse=_inverse_new_line_ids,

string="Invoice Lines) # invoice_new_id - is a new back reference in line model

new_line_ids_zero = fields.One2many(

"account.invoice.line",

"invoice_new_id_2",

compute=_compute_new_line_ids,

inverse=_inverse_new_line_ids,

string="Invoice Lines) # invoice_new_id_2 - is a new back reference in line model

On a xml form replace line_ids with new_line_ids


Avatar
Buang

Depending on your requirements, it may be better not to just hide, but remove the lines. Just add inverse to line_ids, and in this function remove zero lines. It would be updated each time you create or write a record

can you explain further, why you made two o2m fields
why did you make two different inverses,
how exactly are you going to replace the o2m in XML in this case?

Jawaban Terbai

You can write domain in the field you defined.

doctor_ids = fields.Many2many('example.a', 'example_a_b_rel', 'example_a_id', 'example_b_id', domain="[('is_doctor', '=', True)]")

Avatar
Buang

This doesn't hide the filed. It prevents it to be created at the first place.

Post Terkait Replies Tampilan Aktivitas
3
Feb 24
2677
0
Mei 16
2978
4
Feb 25
6716
2
Feb 22
2951
1
Jan 22
3486