Skip to Content
Menu
This question has been flagged
3 Replies
3654 Rodiniai

Hello,

Here is my problem

In account.move form, there is an invisible field Type wich can take values (in_invoice, out_invoice,...)

In the one2many field invoie_line_ids, there is a column "analytic_account_id"

I need to change the domain of this column according i'm in an in_invoice type or out_invoice type.


I tried with a syntax like ('parent.type', '=', 'in_invoice') but it seems that parent can be used only on the right of the '='


How can i do that?

Portretas
Atmesti
Best Answer

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.

Portretas
Atmesti
Autorius

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

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

Autorius

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', []))]"

Autorius

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

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.

Best Answer

You can follow this: https://youtu.be/XGqXEL2qQmE

Hope it helps,

Thanks

Portretas
Atmesti
Autorius Best Answer

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.

Portretas
Atmesti
Autorius

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

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