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 connect button with function?

Abonare

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

Această întrebare a fost marcată
functionforminheritbutton
3 Răspunsuri
20913 Vizualizări
Imagine profil
arcull

Hi everyone.

I'm trying to put a new button on sales invoice which will print my customized version of invoice. So I've created new addon"my" and now need to connect this button click with function in "my" module. Can you please suggest, how can I refernce function in my model when hitting my new print button. The "print_invoice_my" refers to account.invoice model, while it should refernce to "my" model. Therefore I get an error when trying to run, it says it can not find  "print_invoice_my" in account.invoice.Here is my xml:

<openerp>
<data>
<record id="invoice_form_my" model="ir.ui.view">
<field name="name">account.invoice.form.my</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<button name="invoice_print" position="after">
<button type="object" name="print_invoice_my" string="my Invoice"/>
</button>
</field>
</record>
</data>
</openerp>

Much thanks, Arcull

1
Imagine profil
Abandonează
Imagine profil
Anil Kesariya
Cel mai bun răspuns

Hi Arcull,


Make sure you have the method or definition with this name print_invoice_my inside your account.invoice model,

When your button type="object" that means odoo framework will look for the method inside model provided on same view, with button name value.



Hope this might help


Regards,

Anil.

4
Imagine profil
Abandonează
arcull
Autor

Thanks Anil. I don't want to modify existing model. I will inherit account.invoice model, but don't know how will my xml for custom invoice then look like? I mean the tags:model and inherit_id. Thanks for your help.

Imagine profil
Temur
Cel mai bun răspuns

You've to define print_invoice_my python function in account.invoice model, because of name="print_invoice_my" the function with name print_invoice_my from the corresponding model (account.invoice in your case) is being called and as you have not defined it, you've got above error.



UPDATE:

if you're interested in changing view of report itself, or add additional fields to it, then you should inherit or change the report view defined here: https://github.com/odoo/odoo/blob/dc48744bf7438761e1f25d411ec61755f74c60df/addons/account/views/report_invoice.xml#L4


for example, if you add new field in account.invoice, named my_field, then something like this should do the trick:

<template id="report_invoice_document" inherit_id="account.report_invoice_document">

<xpath expr="//div/div/div/address" position="after">

<span t-field="o.my_field" /> 

</xpath> </template>

this way, "my_field" is added to the printed invoice.

0
Imagine profil
Abandonează
arcull
Autor

Thanks Temur, but the point is, that I don' want to adjust the original account.invoice model, I want to inherit it in my module and add the function there. How can I achieve that? Thanks again.

Temur

So mean I. It's correct, you must inherit account.invoice model in your module and define your function print_invoice_my in the inherited model, but you're actually extending the existing account.invoice model, and so defining function in it. I just skipped over the details in my answer

arcull
Autor

Thanks Temur. Will do that, but how will my xml for custom invoice then look like? I guess account.invoice will change to my. What about the "inherit_id" tag? Thanks.

Temur

No, there is nothing to change in XML, account.invoice will stay same because you'll extend the account.invoice model by "Extension" inheritance, see documentation at https://www.odoo.com/documentation/8.0/reference/orm.html#inheritance-and-extension , there is explanation of a different inheritance approach, you'll need to apply the "Extension" one (scroll down a bit at the referred page); "inherit_id" refers to the XML record you're extending in your xml, it does not need to be changed either.

arcull
Autor

Thank you Temur, will try to impelment this and report back.

arcull
Autor

Unfortunatelly I can't make the inheritance to work. Please see my post at https://www.odoo.com/forum/help-1/question/cant-inherit-account-invoice-96458

Temur

Answered... We do not use _name or we use same _name as in a parent class in case of extension inheritance.

Temur

updated with view extension example... If you're going to customize invoice then it may halp.

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
module without fields?
function inherit column button
Imagine profil
Imagine profil
Imagine profil
2
mar. 15
5324
Inherit form view from a predefined module.
form inherit
Imagine profil
Imagine profil
1
mar. 15
4727
api request
function api button
Imagine profil
0
dec. 24
2039
How to Resolve the "Inherited view cannot have 'Groups' defined on the record" Error in Odoo?
form inherit odoo16
Imagine profil
Imagine profil
1
aug. 24
2901
Is it possible to choose the priority of an overload of a function ? Rezolvat
function create inherit
Imagine profil
Imagine profil
2
iul. 25
5146
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