Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Inherit partner_id from account.payment with different domain. How to do it?

Subscribe

Get notified when there's activity on this post

This question has been flagged
inheritancepaymentsodoo12.0
2 Replies
6783 Views
Avatar
Paulo Matos

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

0
Avatar
Discard
Avatar
Avinash Nk
Best Answer

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')
def _onchange_partner_type(self):
self.ensure_one()
# Set partner_id domain
if self.partner_type:
return {'domain': {'partner_id': [(self.partner_type, '=', True), ('parent_id', '=', False)]}}



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')
def _onchange_partner_type(self):
res = super(YourClass, self)._onchange_partner_type()
if 'domain' in res:
if 'partner_id' in res['domain']:
res['domain']['partner_id'].append(('parent_id', '=', False))
else:
res['domain']['partner_id'] = [('parent_id', '=', False)]
return res
else:
return {'domain': {'partner_id': [('parent_id', '=', False)]}}


-----

Thanks & Regards

Avinash N K


1
Avatar
Discard
Paulo Matos
Author

@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

Avinash Nk

Hi EuroGold,

I update some code for you. check if it helps you.

Thanks

Paulo Matos
Author

@Avinash,,

Thank you once again.

Your code worked exactly as expected.

Thank you very much once again

Best regards

PM

Avatar
Arturo Velázquez
Best Answer

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

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Inherit a method without copy/paste full original code Solved
inheritance odoo12.0
Avatar
Avatar
1
Sep 19
4518
How to inherit view and add widget in Odoo 12CE ? Solved
form inheritance odoo12.0
Avatar
1
Aug 23
6651
how to use model inheritance on the existing Product model to add some field for my new module ? Solved
inheritance product.product Module odoo12.0
Avatar
Avatar
Avatar
4
Apr 19
9280
Expected singleton: hr.emp.travel.location(62, 63)
odoo12.0
Avatar
Avatar
Avatar
2
Oct 25
1975
When registering payment, i get "can't create a new payment without an outstanding payments/receipts account set"
payments
Avatar
Avatar
1
Apr 25
2974
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now