Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

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

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

How to inherit a def function ?

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
8 Besvarelser
12164 Visninger
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
Kassér
Maurice Agée
Forfatter

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

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
Kassér
Avatar
Serpent Consulting Services Pvt. Ltd.
Bedste svar

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
Kassér
Maurice Agée
Forfatter

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
Forfatter

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

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Tilmeld dig
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة 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 er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

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