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

how to format mapped() result

Odoberať

Get notified when there's activity on this post

This question has been flagged
many2manymappingodoo11
2 Replies
12216 Zobrazenia
Avatar
andy

How to format mapped() result?

mapped() output like ['name1','name2','name3'] and related float field [100, 200, 300]

would like to add that value to fields.Text so that it goes fields.Text: name1, name2, name3

and also add currency like $100, $200, $300

can this be done? any example?

thank you

0
Avatar
Zrušiť
Avatar
andy
Autor Best Answer

okey i'm partly solve:
This is my custom modules
that have this fields

report = fields.Many2many(comodel_name="my.report", string="Report")
tprod = fields.Text(string="Product", compute="_tprod")
tprice = fields.Text(string="Prices", compute="_tprice")
tcost = fields.Text(string="Cost", compute="_tcost")


@api.multi
@api.depends('report')
def _tprod(self):
        for rec in self:
            rec.tprod = str(rec.report.mapped('name')).strip("[]").strip("''")

this result is: name1', 'name2
expected : name1, name2 - with out ( ' )

@api.multi
@api.depends('report')
    def _tprice(self):
        for rec in self:
            rec.tprice = str(rec.report.mapped(lambda record: '$ ' + str(record.price))).strip("[]")

this result is : '$100', '$200'
expected: $100, $200
if i put .strip("[]").strip("''") then the result would like $100', '$200 which is not good to look at 

tcost the same as tprice

so for all of you who does not know, mapped() is a list so you cannot add .replace or .strip without turning it to str first that's why must convert str(rec.report.mapped('name')) and also record.price is Float for my part and have to change that as well to str(record.price)

if anyone have more solution to finalize my code please, thank you

Solved with:

@api.multi
@api.depends('report')
def _tprod(self):
        for rec in self:
            rec.tprod = str(rec.report.mapped('name')).strip("[]").replace("'", "")

or if it's not working, you can do this:

    rec.tprod = str(rec.report.mapped('name')).strip("[]")
    rec.tprod = rec.tprod.replace("'", "")

anyway other tips is if you use store=True then you have to delete the value first or if there is already a value in your field, then either delete the value or delete it from database (just be cautions if you are deleting from database, always have backups), or maybe just use "@api.onchange" for testing.

My problem was using store=True i did not see the .replace() because it's already saved values in database (was testing using @api.depends thought that it will change just by refreshing), choose hard way delete field from postgresql and upgrade my module - but you can also create new field and delete old ones

0
Avatar
Zrušiť
Avatar
Travis Waelbroeck
Best Answer

When you use `mapped`, it is going to result in a list. Afterwards, you can use standard Python to manage how you want to format that list. This isn't the prettiest example, but you can do something like this:


>>> ", ".join(["${}".format(price) for price in ['100', '200']])
'$100, $200'


1
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
Add column to a many2many rel table Solved
many2many odoo11
Avatar
Avatar
1
nov 19
5880
Problem with M2M Fields Solved
many2many problem odoo11
Avatar
Avatar
Avatar
2
nov 18
6826
Many2Many and One2Many Field in Odoo Studio Solved
one2many many2many studio odoo11
Avatar
Avatar
Avatar
2
dec 19
7305
Getting TypeError: Cannot read property 'documentElement' of null with fields_view_get() ODOO 11
many2many domain_filter fields_view_get odoo11
Avatar
Avatar
2
sep 18
10236
access files from many2many-field which is passed from context
many2many context files odoo11
Avatar
0
sep 18
4341
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