Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

How to get count of projects per partner?

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
projectpythonmoduleaccountapirelationships
2 Răspunsuri
9714 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
Imagine profil
Jairo Llopis
Autor Cel mai bun răspuns

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
Imagine profil
Abandonează
Imagine profil
Ludo - 21South
Cel mai bun răspuns

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
Imagine profil
Abandonează
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!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
External Python code calling (xml-rpc maybe?) Openerp Fields to work with
python module sale account
Imagine profil
Imagine profil
1
mar. 15
5790
Error when passing information through API Rezolvat
python api
Imagine profil
Imagine profil
1
sept. 23
3174
Search a production order that is planned for today on python with an api
python api
Imagine profil
Imagine profil
3
apr. 19
3804
Java module to Odoo module conversion....
project python
Imagine profil
Imagine profil
Imagine profil
2
nov. 15
5497
Error In Open Erp when create new module
python module
Imagine profil
0
mar. 15
4704
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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