Hello everyone,
I am working with Odoo 12 and having a problem on setting a domain on a form view for the account.payments model.
What I need to do is to show only users (partner_id) that has the field "parent_id" = False under partner_id field.
I have successfully tried on the account.invoice and changed the xml for the form view to:
<record id="mymodule_form_view_account_invoice" model="ir.ui.view">
<field name="name">Account Invoice Hide Children Partners</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="replace">
<field string="Customer" name="partner_id" widget="res_partner_many2one" context="{'search_default_customer':1, 'show_address': 1, 'default_is_company': True, 'show_vat': True}" options="{"always_reload": True, "no_quick_create": True}" domain="[('customer', '=', True),('parent_id', '=', False)]" required="1"/>
</xpath>
</field>
</record>
I was able to hide partners with "parent_id" using the domain:
domain="[('customer', '=', True),('parent_id', '=', False)]" required="1"
Tried to do the same for the account.payment model and was unable to achieve what I want.
I can see that on the account.payment form view there's a "partner_id" field and tried to:
<field name="partner_id" domain="[('parent_id', '=', False)]" attrs="{'required': [('state', '=', 'draft'), ('payment_type', 'in', ('inbound', 'outbound'))], 'invisible': [('payment_type', 'not in', ('inbound', 'outbound'))], 'readonly': [('state', '!=', 'draft')]}" context="{'default_is_company': True, 'default_supplier': payment_type == 'outbound', 'default_customer': payment_type == 'inbound'}"/>
...and it does not work.
Using debug mode with mouse over the field, I can see that the domain is applied but it simple does not work.
Then, I have noticed that, in fact there is no "partner_id" on the account.payment form. This field in on the "account.abstract.payment" abstract model that is shared among models which allows to register payments.
Since I cannot find any related xml id for this model for changing the partner_id default values, I have tried to directly (for testing purposes) change the field definition to:
_name = "account.abstract.payment"
....
....
partner_id = fields.Many2one('res.partner', string='Partner', domain=lambda self: [("parent_id", "=", "False")])
Even adding the domain above on the field definition, I am unable to achieve what I need.
Can anyone help me please?
Thank you all in advance
Best regards
PM
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
Hello Paulo Matos,
Like the way you expected, this problem is not because of that
This is happening because there is an onchange function in account.payment model that returns the domain of the partner_id.
So even if you put some domains in XML, it overrides by that function.
This onchange function is work when you change the partner_type field. so it will always execute when you create a new record.
So better you have to override that function.
Like this.
@api.onchange('partner_type') |
Code is not tested. I hope it will work.
Anyway, I think you get some idea about this.
Edited Part:
----
This code is for inheriting the function instead of the override.
@api.onchange('partner_type') |
-----
Thanks & Regards
Avinash N K
@Avinash,
Thank you very much for your help and time.
The code itself did not work but with your help I get an idea of what the problem is.
Thank you very very much
Best regards
PM
Hi EuroGold,
I update some code for you. check if it helps you.
Thanks
@Avinash,,
Thank you once again.
Your code worked exactly as expected.
Thank you very much once again
Best regards
PM
Hello Avinash & Paulo.
I'm facing the same issue, I am unable to change the domain of partner_id field on account.payments model. I see Avinash posted the solution to this problem, but I don't know how and where to put the code for inherit the onchange function. Can someone put me in the right direction? Best regards
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
1
Sep 19
|
3320 | ||
|
1
Aug 23
|
5498 | ||
|
4
Apr 19
|
8075 | ||
|
1
Apr 25
|
927 | ||
|
4
Feb 25
|
701 |