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 get count of projects per partner?

Odoberať

Get notified when there's activity on this post

This question has been flagged
projectpythonmoduleaccountapirelationships
2 Replies
9717 Zobrazenia
Avatar
Jairo Llopis

I have this code in my module:

from openerp import api, fields, models


class Partner(models.Model):
    _name = _inherit = "res.partner"

    @api.one
    @api.depends("project_ids")
    def _project_count(self):
        self.project_count = len(self.project_ids)

    project_count = fields.Integer(compute="_project_count")
    project_ids = fields.One2many("project.project", "partner_id")

But it yields this exception:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/openerp/http.py", line 496, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/local/lib/python2.7/dist-packages/openerp/http.py", line 513, in dispatch
    result = self._call_function(**self.params)
  File "/usr/local/lib/python2.7/dist-packages/openerp/http.py", line 279, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/openerp/http.py", line 276, in checked_call
    return self.endpoint(*a, **kw)
  File "/usr/local/lib/python2.7/dist-packages/openerp/http.py", line 723, in __call__
    return self.method(*args, **kw)
  File "/usr/local/lib/python2.7/dist-packages/openerp/http.py", line 372, in response_wrap
    response = f(*args, **kw)
  File "/usr/local/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 941, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/usr/local/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 924, in _call_kw
    records = getattr(request.session.model(model), method)(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/openerp/http.py", line 825, in proxy
    result = meth(cr, request.uid, *args, **kw)
  File "/usr/local/lib/python2.7/dist-packages/openerp/api.py", line 234, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/openerp/models.py", line 3085, in read
    result = BaseModel.read(records, fields, load=load)
  File "/usr/local/lib/python2.7/dist-packages/openerp/api.py", line 232, in wrapper
    return new_api(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/openerp/models.py", line 3128, in read
    values[name] = field.convert_to_read(record[name], use_name_get)
  File "/usr/local/lib/python2.7/dist-packages/openerp/models.py", line 5411, in __getitem__
    return self._fields[key].__get__(self, type(self))
  File "/usr/local/lib/python2.7/dist-packages/openerp/fields.py", line 707, in __get__
    self.determine_value(record)
  File "/usr/local/lib/python2.7/dist-packages/openerp/fields.py", line 807, in determine_value
    self.compute_value(recs)
  File "/usr/local/lib/python2.7/dist-packages/openerp/fields.py", line 767, in compute_value
    self._compute_value(records)
  File "/usr/local/lib/python2.7/dist-packages/openerp/fields.py", line 759, in _compute_value
    self.compute(records)
  File "/usr/local/lib/python2.7/dist-packages/openerp/api.py", line 232, in wrapper
    return new_api(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/openerp/api.py", line 392, in new_api
    result = [method(rec, *args, **kwargs) for rec in self]
  File "/opt/odoo/extra-addons/grupoesoc/partner_projects/partner_projects.py", line 28, in _project_count
    self.project_count = len(self.project_ids)
  File "/usr/local/lib/python2.7/dist-packages/openerp/fields.py", line 707, in __get__
    self.determine_value(record)
  File "/usr/local/lib/python2.7/dist-packages/openerp/fields.py", line 798, in determine_value
    record._prefetch_field(self)
  File "/usr/local/lib/python2.7/dist-packages/openerp/api.py", line 232, in wrapper
    return new_api(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/openerp/models.py", line 3167, in _prefetch_field
    result = records.read(list(fnames), load='_classic_write')
  File "/usr/local/lib/python2.7/dist-packages/openerp/api.py", line 232, in wrapper
    return new_api(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/openerp/models.py", line 3117, in read
    self._read_from_database(stored)
  File "/usr/local/lib/python2.7/dist-packages/openerp/api.py", line 232, in wrapper
    return new_api(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/openerp/models.py", line 3276, in _read_from_database
    res2 = self._columns[f].get(cr, self._model, ids, f, user, context=context, values=result)
  File "/usr/local/lib/python2.7/dist-packages/openerp/osv/fields.py", line 689, in get
    }, (tuple(record_ids),))
  File "/usr/local/lib/python2.7/dist-packages/openerp/sql_db.py", line 158, in wrapper
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/openerp/sql_db.py", line 234, in execute
    res = self._obj.execute(query, params)
ProgrammingError: column "partner_id" does not exist
LINE 1: SELECT id, partner_id                        FROM project_pr...
                   ^

Seems like I cannot relate it directly to project.project because the field partner_id comes from account.analytic.account, but then how can I get the relationship between res.partner and project.project?

0
Avatar
Zrušiť
Avatar
Jairo Llopis
Autor Best Answer

The answer is to use a relationship with "account.analytic.account" and filter from there:

from openerp import api, fields, models


class Partner(models.Model):
    _name = _inherit = "res.partner"

    @api.one
    @api.depends("contract_ids")
    def _project_count(self):
        self.project_count = len(self.env["project.project"].search(
            [("analytic_account_id",
              "in",
              [c.id for c in self.contract_ids])]))

    project_count = fields.Integer(compute="_project_count")
1
Avatar
Zrušiť
Avatar
Ludo - 21South
Best Answer

Project by itself is an analytic account. Looking at the source code, it tells me the following:

    _inherits = {'account.analytic.account': "analytic_account_id",

                 "mail.alias": "alias_id"}

This means that on the project there should be an analytic_account_id field, pointing to the related analytic account. You could use that. Depending on your business needs, it could be a related field or perhaps a one2many field using using related fields to view project names.

1
Avatar
Zrušiť
Jairo Llopis
Autor

Thanks. The problem is that not all analytic accounts are projects, but I will search from there.

Ludo - 21South

If I recall correctly, the analytic account has a field "type" which indicates what type of account it is. Project should be an option there.

Jairo Llopis
Autor

It's true, but that field does not say if it is a project or not. I already found the solution, thanks.

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
External Python code calling (xml-rpc maybe?) Openerp Fields to work with
python module sale account
Avatar
Avatar
1
mar 15
5790
Error when passing information through API Solved
python api
Avatar
Avatar
1
sep 23
3177
Search a production order that is planned for today on python with an api
python api
Avatar
Avatar
3
apr 19
3808
Java module to Odoo module conversion....
project python
Avatar
Avatar
Avatar
2
nov 15
5499
Error In Open Erp when create new module
python module
Avatar
0
mar 15
4706
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