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

Odoo 14: Inherit python method is not working.

S'inscrire

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

Cette question a été signalée
stockfunctioninheritancesuperdef
1 Répondre
5544 Vues
Avatar
Muhammad Faheem Khan

I am trying to inherit a method in stock.inventory.line. My issue is, when this method is called from write method, it is working fine (inherited function work), but if I call it from create method, the original function is being used and my inherited function is being ignored.

Original method:

def _check_no_duplicate_line(self):
domain = [
('product_id', 'in', self.product_id.ids),
('location_id', 'in', self.location_id.ids),
'|', ('partner_id', 'in', self.partner_id.ids), ('partner_id', '=', None),
'|', ('package_id', 'in', self.package_id.ids), ('package_id', '=', None),
'|', ('prod_lot_id', 'in', self.prod_lot_id.ids), ('prod_lot_id', '=', None),
'|', ('inventory_id', 'in', self.inventory_id.ids), ('inventory_id', '=', None),
]
groupby_fields = ['product_id', 'location_id', 'partner_id', 'package_id', 'prod_lot_id', 'inventory_id']
lines_count = {}
for group in self.read_group(domain, ['product_id'], groupby_fields, lazy=False):
key = tuple([group[field] and group[field][0] for field in groupby_fields])
lines_count[key] = group['__count']
for line in self:
key = (line.product_id.id, line.location_id.id, line.partner_id.id, line.package_id.id, line.prod_lot_id.id, line.inventory_id.id)
if lines_count[key] > 1:
raise UserError(_("There is already one inventory adjustment line for this product,"
" you should rather modify this one instead of creating a new one."))


Inherited method:


    def _check_no_duplicate_line(self):
res = super(InventoryLine, self)._check_no_duplicate_line()
print('duplicate line called')
_logger.debug('duplicate line verifeid')
# active_id = self.env.context.get('active_id')
# print(active_id)
invent = self.inventory_id.my_custom_field
print(invent)
if invent:
print('in duplicate tag id fond')
return
else:
print('no id found')
return res

write method:

def write(self, vals):
res = super(InventoryLine, self).write(vals)
self._check_no_duplicate_line()
return res

create method:

@api.model_create_multi
def create(self, vals_list):
some code here. . .

res = super(InventoryLine, self).create(vals_list)
res._check_no_duplicate_line()
return res

What could be the reason? Any help will be greatly appreciated.

0
Avatar
Ignorer
Avatar
Ibrahim Boudmir
Meilleure réponse

Hi, 

I'm commenting your code generally speaking: 

1- In create function, you're calling bulk create.Therefore, You may have a recordset that's been created. so, you need to loop inside your method.

Using return inside of a loop will break it and exit the function even if the loop is still not finished.

Can you try this instead: 

def _check_no_duplicate_line(self):
    for line in self:
        if not line.inventory_id.my_custom_field:
            super(InventoryLine, line)._check_no_duplicate_line()

Add prints or pdb debug to check.

You can write back for further analysis.
Regards.

1
Avatar
Ignorer
Muhammad Faheem Khan
Auteur

Thank you for your response.
I tried what you suggested.
I added _logger.debug('called successfully') in your proposed code (loop)
when I called it from write function, I am getting log in terminal "called successfully"
but when I call it for create, I am not even getting this log, but I am getting error in original method. It is really upsetting me.

Ibrahim Boudmir

can you debug code using pdb package and put it (import pdb; pdb.set_trace() ) just after calling super of create function please?

Then print res and click on "s" in order to get into your method...etc
this is how we're going to understand what's happening.
more at: https://docs.python.org/3/library/pdb.html#pdbcommand-next
--------------------------
If all this is "useless", i suggest you use monkey patch : targetting your method in import section, declare all the method and then replace the native with yours.

Muhammad Faheem Khan
Auteur

Thank you very much for pointing me the right direction. I don't know what is the issue, but I just tested my custom module on another installation after applying your proposed solution (loop), and it worked fine. I did several tests there. It is working fine, but in old installation, it is still the same. Anyway, +100 for you. I will test it with pdb and post results here later from my effected installation.

Ibrahim Boudmir

Thank you

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é
Inherit python function
function python inheritance class super
Avatar
Avatar
Avatar
2
mai 25
2079
Python "super" - function does not work Résolu
python inheritance super
Avatar
Avatar
Avatar
2
déc. 22
13565
Add/Override parent compute method (event.booth) Odoo15 Résolu
inheritance super v15
Avatar
Avatar
1
déc. 22
4942
Problems overriding the same function from two different modules
function inheritance override
Avatar
0
janv. 17
5533
Execution order on inherited functions
function python inheritance
Avatar
0
juil. 25
5891
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