跳至內容
選單
此問題已被標幟
2 回覆
10892 瀏覽次數

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!

頭像
捨棄
最佳答案

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


頭像
捨棄

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?

最佳答案

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)]")

頭像
捨棄

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

相關帖文 回覆 瀏覽次數 活動
3
2月 24
3394
0
5月 16
3381
4
2月 25
7170
2
2月 22
3260
1
1月 22
4015