Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • 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 Managament
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and 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
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

Inverse function on compute field

Odoberať

Get notified when there's activity on this post

This question has been flagged
computeinverseodoo10
1 Odpoveď
41060 Zobrazenia
Avatar
Paul San

HI all,

I have to write the inverse function (using the inverse parameter) on a field that is defined so in order to have the "add an item".

x_ids = fields.Many2many("product.pricelist.item", "Pricelist Items", compute="_get_pricelist_items", inverse="_set_pricelist_items")
@api.one
def _get_x_items(self):
self.x_ids = self.env["product.pricelist.item"].search([("product_tmpl_id", "=", self.id)]).ids

The documentation says:

"The inverse method, as its name says, does the inverse of the compute method: the invoked records have a value for the field, and you must apply the necessary changes on the field dependencies such that the computation gives the expected value. Note that a computed field without an inverse method is readonly by default."

THe readonly can't let me to view "add an item".

What's the inverse of search through a model? DO I have to create something?

What does exactly mean this?

3
Avatar
Zrušiť
Paul San
Autor

Hello Hilar AK,

thank for your answer. The case you show me is quite clear and it's the same written in the official documentation but with you images examples now it's even clearer.

BUt I hafve these case where I have a field x_ids that have a m2m relation with another field.

In the compute function there is a search but in the inverse function what I have to written?

COuld you give me any suggestions?

Hilar Andikkadavath

I updated the answer and included details about search

Paul San
Autor

Hilar AK

THank you.

Everytime you answer me I understand more and more.

Now I have this question:

OK i have to define a search function like you wrote me.

IN your example what could be the "_compute_standard_price" implementation?

Hilar Andikkadavath

it returns a price for the product after some calculations.

Avatar
Hilar Andikkadavath
Best Answer

Hi Paul San,

The Use of Inverse parameter is quite simple. Normally the computing fields are read-only because it computes the values on the fly from the record set. If you need to make a manual entry on compute field, that can be done by giving inverse function. So it triggers call of the decorated function when the field is written/”created”. It reverses the computation and set the relevant fields.


upper = fields.Char(compute='_compute_upper',
inverse='_inverse_upper',
search='_search_upper')

@api.depends('employee_id')
def _compute_upper(self):
for rec in self:
rec.upper = rec.employee_name.upper() if rec.employee_name else False

def
_inverse_upper(self):
for rec in self:
rec.employee_name = rec.upper.lower() if rec.upper else False


1.

2. Editing computed field

3.  Inverse Function Triggered

Update:-

By default, a computed field is not stored to the database and is computed on-the-fly. Adding the attribute ``store=True`` will store the field's values in the database. The advantage of a stored field is that searching on that field is done by the database itself.

So computed fields which are not stored in the database can't be searched normally, To enable searching we have to define the search function explicitly. This can be achieved by adding  ''search '' param with computing field. If we add a method to search on a compute field, the method is invoked when processing domains before doing an actual search on the model.

Another eg :

standard_price = fields.Float(
'Cost', compute='_compute_standard_price',
inverse='_set_standard_price', search='_search_standard_price',
digits=dp.get_precision('Product Price'), groups="base.group_user",
)
def _search_standard_price(self, operator, value):
products = self.env['product.product'].search([('standard_price', operator, value)], limit=None)
return [('id', 'in', products.mapped('product_tmpl_id').ids)]



25
Avatar
Zrušiť
Enjoying the discussion? Don't just read, join in!

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

Registrácia
Related Posts Replies Zobrazenia Aktivita
Please Help me, inverse One2many field
one2many inverse odoo10
Avatar
0
apr 18
5652
Inverse function for making the compute field editable Solved
editable compute inverse odoo12
Avatar
Avatar
Avatar
Avatar
3
aug 24
14784
The translation does not change when I change the nameUA field in the view
fields translations compute inverse
Avatar
Avatar
Avatar
2
feb 24
4335
computed one2many field ir.attachment
one2many compute ir_attachment odoo10
Avatar
Avatar
1
okt 20
5709
Computed value for binary fields
models compute binaryfield odoo10
Avatar
4
nov 16
10941
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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