Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

How to get count of projects per partner?

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
projectpythonmoduleaccountapirelationships
2 Réponses
9734 Vues
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
Ignorer
Avatar
Jairo Llopis
Auteur Meilleure réponse

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
Ignorer
Avatar
Ludo - 21South
Meilleure réponse

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
Ignorer
Jairo Llopis
Auteur

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
Auteur

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

Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
External Python code calling (xml-rpc maybe?) Openerp Fields to work with
python module sale account
Avatar
Avatar
1
mars 15
5800
Error when passing information through API Résolu
python api
Avatar
Avatar
1
sept. 23
3205
Search a production order that is planned for today on python with an api
python api
Avatar
Avatar
3
avr. 19
3819
Java module to Odoo module conversion....
project python
Avatar
Avatar
Avatar
2
nov. 15
5524
Error In Open Erp when create new module
python module
Avatar
0
mars 15
4737
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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