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 inherit a def function ?

S'inscrire

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

Cette question a été signalée
8 Réponses
12172 Vues
Avatar
Maurice Agée

I would like to edit 'onchange_product_id' to 'purchase' to add a new field from 'product_template' in 'purchase_order_line'.

Can I use a method like 'inherit' or should I write all the code again?

0
Avatar
Ignorer
Maurice Agée
Auteur

I test with this code , but no corect value in PO_line class purchase_order_line(osv.osv): #_table = 'purchase_order_line' _name = 'purchase.order.line' _inherit = 'purchase.order.line' def onchange_product_id(self, cr, uid, ids, pricelist_id, product_id, qty, uom_id, partner_id, date_order=False, fiscal_position_id=False, date_planned=False, name=False, price_unit=False, state='draft', context=None): res = super(purchase_order_line, self).onchange_product_id(cr, uid, ids, pricelist_id, product_id, qty, uom_id, partner_id, date_order=date_order, fiscal_position_id=fiscal_position_id, date_planned=date_planned, name=name, price_unit=price_unit, state=state, context=context) if 'value' in res: res['value'].update({'unitestock_po': 'product.template.unitestock'}, {'uniteachat_po': 'product.template.uniteachat'}) return res _columns = { 'unitestock_po': fields.many2one('product.template.unitestock','Unité pour Stock',required=True), 'uniteachat_po': fields.many2one('product.template.uniteachat','Unité pour Achats',required=True), }

Avatar
Axel Mendoza
Meilleure réponse

You could override the onchange_product_id in your model inherit to call super() to get the original values returned from onchange_product_id and add your new field value before return

2
Avatar
Ignorer
Avatar
Serpent Consulting Services Pvt. Ltd.
Meilleure réponse

Hello Maurice,

First you have to inherit the view of PO to add your custom field in PO Line.

Ex:

<record id="purchase_order_form_inherit" model="ir.ui.view">
<field name="name">purchase.order.inherit.form</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="model">purchase.order</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='order_line']/tree/field[@name='name']" position="after">
<field name="your_custom_field"/>
</xpath>
</field>
</record>

Now, override onchange_product_id() method, make a super call and add your value to custom field before return statement.

Ex:

def onchange_product_id(self, cr, uid, ids, pricelist_id, product_id, qty, uom_id,
partner_id, date_order=False, fiscal_position_id=False, date_planned=False,
name=False, price_unit=False, state='draft', context=None):
res = super(your_class_name, self).onchange_product_id(cr, uid, ids, pricelist_id, product_id, qty, uom_id,
partner_id, date_order=date_order, fiscal_position_id=fiscal_position_id, date_planned=date_planned,
name=name, price_unit=price_unit, state=state, context=context)
if 'value' in res:
res['value'].update({'your_custom_field': 'value_of_custom_field'})
return res

Hope the given snippet will help you.

EDIT: 

If your custom field is of relational field then you have to pass ID of the record.

Ex:

unitestock_po = self.pool.get('product.product').browse(cr, uid, product_id, context=context).unitestock_po_id
res['value'].update({'your_custom_field': unitestock_po and unitestock_po.id or False})
0
Avatar
Ignorer
Maurice Agée
Auteur

I test with this code, but no value in the PO-line ?? class purchase_order_line(osv.osv): #_table = 'purchase_order_line' _name = 'purchase.order.line' _inherit = 'purchase.order.line' def onchange_product_id(self, cr, uid, ids, pricelist_id, product_id, qty, uom_id, partner_id, date_order=False, fiscal_position_id=False, date_planned=False, name=False, price_unit=False, state='draft', context=None): res = super(purchase_order_line, self).onchange_product_id(cr, uid, ids, pricelist_id, product_id, qty, uom_id, partner_id, date_order=date_order, fiscal_position_id=fiscal_position_id, date_planned=date_planned, name=name, price_unit=price_unit, state=state, context=context) if 'value' in res: res['value'].update({'unitestock_po': 'product.template.unitestock'}, {'uniteachat_po': 'product.template.uniteachat'}) return res _columns = { 'unitestock_po': fields.many2one('product.template.unitestock','Unité pour Stock',required=True), 'uniteachat_po': fields.many2one('product.template.uniteachat','Unité pour Achats',required=True), }

Serpent Consulting Services Pvt. Ltd.

Your both fields are of relational fields. Its not working because you are passing char value instead of record ID. You have to pass record ID of "product.template.unitestock" object.

Serpent Consulting Services Pvt. Ltd.

See my updated code and try that code.

Maurice Agée
Auteur

I try with your last code , no result I try with your code but 'product.template' inplace of 'product.product' , no result To resum : I have a this class and It's good class product_template(osv.osv): _name = 'product.template' _inherit = 'product.template' _columns = { 'matiere': fields.many2one('matierenom','Choix de la nuance',required=True, ondelete='cascade'), 'certificat': fields.many2one('certificatnom','Choix du certificat',required=True, ondelete='cascade'), 'unitestock': fields.many2one('product.uom','Unité de Stockage',required=True, ondelete='cascade'), 'uniteachat': fields.many2one('product.uom','Unité pour achat',required=True, ondelete='cascade'), 'coefficient': fields.float('Coefficient Achats/Stock', required=True, digits=0,), } _sql_constraints = [ ('uniq_name', 'unique(matierenom,product_tmpl_id)',"--"), ('uniq_name', 'unique(certificatnom,product_tmpl_id)',"--"), ] _defaults = { 'coefficient': 1, } product_template() after I want update po_line with unitestock and uniteachat

Serpent Consulting Services Pvt. Ltd.

Maurice, its hard to discuss unformatted code I guess, would love to redirect you to our online training at Udemy at just $99 (67%) discount https://www.udemy.com/odoo-technical/?couponCode=Mufaddal99

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
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