Odooers论坛

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

v13 : Tree/Many2one add dynamic domain according value in parent.field

形象
odoo
形象
丢弃
2 答案
0
形象
odoo
最佳答案

Hi Vincent DUBREIL,

Can you please share your full requirement. Because yes in the domain, you can not use parent in the left side of the domain arguments, but in the attrs yes you can use. You can try the below two options that might be work for you.

If you are going specific to the domain then you can try the Many2one field (move_id) of your One2many field (invoie_line_ids) just like ('move_id.type', '=', 'in_invoice'). 

Another one is the related field. You can create the related field of the parent type field in the invoie_line_ids model and try with that related field insted of the parent type : ('related_field_type', '=', 'in_invoice').

Hope it will help you.

Updated Answer:
Ok as per your requirement, you can add this domain on the analytic account field in invoice lines tree view: 

              domain="context.get('default_move_type') in ('out_invoice', 'out_refund', 'out_receipt') and [('name', 'ilike', 'FCT_')]"


Hope it will help you.

5 注释
形象
丢弃
形象
odoo
-

Hi Malay,
could you, please, give me more informations according my last answer because i still haven't found the solution!

形象
odoo
-

Hi Vincent DUBREIL,

Ok as per Your requirement, you can add this domain into the analytic account field in invoice lines tree view.

domain="context.get('default_move_type') in ('out_invoice', 'out_refund', 'out_receipt') and [('name', 'ilike', "FCT_")]"

形象
odoo
-

Hi Malay,

Sorry for the delay
I tried your solution but it doesn't works
error : TypeError: CreateListFromArrayLike called on non-object

Are you sure of this syntax because every similar examples i found, context.get is always on the right side of the domain arguments.
Like : domain="[('id', 'in', context.get('product_ids', []))]"

形象
odoo
-

Find part of the problem.
I'm always on version 13 of Odoo and the field is type, not move_type.
But the error is always the same.

I tried to change the syntax like that :
[(context.get('default_type'), 'in', ['in_invoice', 'in_refund', 'in_receipt'])]

But i've got the following error :
ValueError: Invalid field 'in_invoice' in leaf "<osv.ExtendedLeaf: ('in_invoice', 'in', ['in_invoice', 'in_refund', 'in_receipt']) on account_analytic_account (ctx: )>"

形象
odoo
-

Hi Vincent DUBREIL,

Ok, As i see, you have added the condition in the list of tuple , Please try with direct condition as we use it in the domain like this instead of the list of tuple :

domain="context.get('default_type') in ('in_invoice', 'in_refund', 'in_receipt')"

Yes you can add the domain list of tuples after the conditions like:

domain="context.get('default_type') in ('in_invoice', 'in_refund', 'in_receipt') and [('name', 'ilike', 'FCT_')]"

If you pass the domain with list and tuple type, then yes you need the field exist in the domain field model. But you can also add the condition and the domain combination as well .

For reference please check this:

(field name="product_id"
domain="context.get('default_type') in ('out_invoice', 'out_refund', 'out_receipt')
and [('sale_ok', '=', True), '|', ('company_id', '=', False), ('company_id', '=', parent.company_id)]
or [('purchase_ok', '=', True), '|', ('company_id', '=', False), ('company_id', '=', parent.company_id)]
"/)

Hope it will help you.

0
形象
odoo
最佳答案

Hi Malay,

thank you for your answer.

Here is my full requirement :

In the view, account.view_move_form, there is the field "invoice_line_ids" with the many2one column "account_analytic_id" linked to the model account.account.

This view is the same used for customer invoices or vendors bills (and refund, receipt,...)

But i need, according the type of the account.move record, to fill this m2o 'account_analytic_id" with differents values.

for types in ("out_invoice","out_refund","out_receipt"), fill with account.account start with "FCT_"

for all other types, fill with all others account_account (except "FCT_")


Hope it is clear enough.

2 注释
形象
丢弃
形象
odoo
-

Finally i found a solution with a dynamic domain return by python function with @onchange like :

@api.onchange('product_id')
def onchange_product_id(self):
if self.move_id.type in ('in_invoice','in_refund','in_receipt'):
res = {
'domain' : {
'analytic_account_id' : [('name', 'ilike', "FCT_")],
}
}
else:
res = {}

return res

形象
odoo
-

Hi Vincent DUBREIL,
Please check the updated andwer to add domain.