Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Consulting
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

odoo 14 call action invoice sent from another model

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
invoiceactionsodoomodels.Model
3 Replies
8983 Rodiniai
Portretas
Joao Almeida

Right now I'm trying to call  programmatically, from  another  model,  the action 'action_invoice_sent'  that exists in the invoice details  page  as  a  button  called  'Send  &  Print'  (I'm not able to post images).

I call the action as a method: 'invoice_object.action_invoice_sent()' but nothing happens. Does anyone knows how to send invoices programmatically?

Thanks


1
Portretas
Atmesti
Portretas
Mohamed Lamine Lalmi
Best Answer

Hello Joao,

The function action_invoice_sent  return  an  action  in  dictionary  format.  You have to return the result of this function to perform the action.

def  my_action(self):    
    action = invoice_object.action_invoice_sent()
    return  action

Otherwise, if you want to perform sending the Invoice directly (without opening the wizard), so you will have to create account.invoice.send object with the following context values:



def action_send_invoice_directly(self):
    # Search for your invoice_object
    invoice_object = ...

template = self.env.ref('account.email_template_edi_invoice', raise_if_not_found=False)
lang = False

if template:
lang = template._render_lang(invoice_object.ids)[invoice_object.id]

if not lang:
lang = get_lang(self.env).code

ctx = dict(
mark_invoice_as_sent=True,
active_ids=invoice_object.ids, # Use ids and not id (it has to be a list)
custom_layout="mail.mail_notification_paynow",
model_description=invoice_object.with_context(lang=lang).type_name,
force_email=True,
default_res_model='account.move',
default_use_template=bool(template),
)
values = {
'model': 'account.move',
'res_id': invoice_object.id,
'template_id': template and template.id or False,
'composition_mode': 'comment',
}

wizard = self.env['account.invoice.send'].with_context(ctx).create(values)
    wizard._compute_composition_mode()
wizard.onchange_template_id()
wizard.onchange_is_email()

    # If you want to send without printing the invoice use this function

    wizard._send_email()

# If you want to send and print use this function
    # wizard.send_and_print_action()

Hope my answer helps you.

4
Portretas
Atmesti
Joao Almeida
Autorius

hi Mahamed,
in this case I want it to run without returning it, since it's an automated processing of invoices. Is this possible?

Mohamed Lamine Lalmi

Hey again,
Yes, It is possible but in a different way. In this cas you can't use the function action_invoice_sent because this function will not send the invoice, it will open the Wizard "account.invoice.send" then this wizard has it own function the send the invoice (_send_email). I'll update my response according to your needs.

Joao Almeida
Autorius

it makes sense. In that case, how can I send the invoice?

Mohamed Lamine Lalmi

Dear Joao,
I've updated my answer.
Good luck.

Joao Almeida
Autorius

wow, that is so great! looked all over the internet to find something like that. Than you so much.

One doubt: what is the "self.ids" in this line?
lang = template._render_lang(self.ids)[self.id]

Joao Almeida
Autorius

it's almost working. The invoice is marked as sent, but the email is not actually sent (it's not even on emails list that failed on odoo settings, so it's not an SMTP configuration problem)
I tried to look into the system's 'account.move.send' model and didn't find what could be the possible cause.

Joao Almeida
Autorius

found the solution, 3 methods must be called before send:

wizard = self.env['account.invoice.send'].with_context(ctx).create(values)

wizard._compute_composition_mode()
wizard.onchange_template_id()
wizard.onchange_is_email()

# If you want to send without printing the invoice use this function
wizard._send_email()

Joao Almeida
Autorius

now, the only thing that is not working is the invoice 'move_to_sent' is not set as true.

Mohamed Lamine Lalmi

Dear Joao,
for this line: lang = template._render_lang(self.ids)[self.id],
I did a mistake and i've updated the code.
_render_lang: Given some record ids, return the lang for each record based on lang field of template or through specific context-based key.
This line is added to ensure that the email will be sent in the correct language.

Mohamed Lamine Lalmi

Good catch Joao!

found the solution, 3 methods must be called before send:

wizard = self.env['account.invoice.send'].with_context(ctx).create(values)

wizard._compute_composition_mode()
wizard.onchange_template_id()
wizard.onchange_is_email()

Mohamed Lamine Lalmi

Dear Joao, could you please add a positif vote on my solution. :)

Joao Almeida
Autorius

added a positive vote :)

also could you change your post to reflect the corrections we discussed here? Just to help someone in the future that stumbles upon this post.

Also, in this line 'model_description=self.with_context(lang=lang).type_name,' self is actually invoice_object? At least I had to use it

Also, I had to create a composer instance:
composer = http.request.env['mail.compose.message'].create({
'composition_mode': 'comment'
})

then use it in the values:
values = {
'model': 'account.move',
'is_email': True,
'res_id': invoice_object.id,
'template_id': template and template.id or False,
'composition_mode': 'comment',
'composer_id': composer.id,
'invoice_ids': invoice_object.ids,
}

Mohamed Lamine Lalmi

Thank you for the positive vote :)
Yes, you were right, it should be invoice_object.
Updates are made on my response.
Thank you for your feedback, it was like a teamwork.

Joao Almeida
Autorius

Hi Mohamed

thank you so much for your help :) yes it felt like team work. With this, now anyone can implement the same

Gouranga Kala

Hi Mohammad,
The above code fits to my requirements, but the only problem is it is generating 2 emails.
1. from user to customer
2.from user to user itself (which is not required)
Can you please help me ?
I am using odoo 16 enterprise. Thanks in advance

Portretas
Răzvan Anastasescu
Best Answer

I think that using the wizard (which will generate some data in temp tables) and composer (which is not used anyway) it's a little bit too complex (and actually slower)

I'd use something like this:

def action_send_invoice(self):
# one 'account.move' object
invoice = self.env['account.move'].search([], limit=1)

template = self.env.ref('account.email_template_edi_invoice')

if not(invoice and template):
return False

res = template.send_mail(invoice.id, force_send=True, notif_layout='mail.mail_notification_paynow')

# or:
res = invoice.with_context(force_send=True).message_post_with_template(template.id, email_layout_xmlid='mail.mail_notification_paynow')

if res:
invoice.is_move_sent = True

return res

Attachments and partner language will be automatically taken care of, but you have to manually set the invoice as sent if success

1
Portretas
Atmesti
Portretas
J. Blanco Caura
Best Answer

Excellent. I congratulate you, of someone out of shape trying to catch the thread of programming again

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

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

Registracija
Related Posts Replies Rodiniai Veikla
Odoo - Return record lists on form view
actions odoo
Portretas
Portretas
Portretas
Portretas
3
liep. 24
6554
What are the value need to pass in field 'type' of account.invoice table in Odoo to get Customer_Invoice & Supplier_Invoice ?
invoice odoo
Portretas
Portretas
1
spal. 18
4688
Error Converting Sale Orders to Invoice
invoice odoo
Portretas
0
spal. 15
4118
How to remove product description from invoice lines?
invoice odoo v18
Portretas
Portretas
Portretas
2
rugp. 25
2951
Remove link from offer and invoice email Solved
invoice emailtemplate odoo
Portretas
Portretas
Portretas
2
lapkr. 24
3720
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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