Перейти к содержимому
Odoo Меню
  • Войти
  • Попробовать бесплатно
  • Модули
    Финансы
    • Бухгалтерия
    • Выставление счетов
    • Расходы
    • Таблицы
    • Документооборот
    • Подпись
    Продажи
    • CRM
    • Продажи
    • POS Магазин
    • POS Ресторан
    • Подписки
    • Аренда
    Вебсайты
    • Конструктор вебсайтов
    • eCommerce
    • Блог
    • Форум
    • Онлайн-чат
    • Электронное обучение
    Логистика
    • Склад
    • Производство
    • PLM
    • Закупки
    • Обслуживание
    • Качество
    Отдел кадров
    • Сотрудники
    • Подбор персонала
    • Отпуска
    • Оценка персонала
    • Реферальная программа
    • Автопарк
    Маркетинг
    • SMM
    • E-mail рассылки
    • СМС рассылки
    • Мероприятия
    • Автоматизация маркетинга
    • Опросы
    Услуги
    • Проекты
    • Табели
    • Выездной сервис
    • Поддержка
    • Планирование
    • Встречи
    Продуктивность
    • Обсуждения
    • Согласование
    • IoT
    • VoIP-телефония
    • Knowledge
    • WhatsApp
    Сторонние приложения Модуль Студия Odoo Платформа Odoo Cloud
  • Индустрии
    Розничная торговля
    • Книжный магазин
    • Магазин одежды
    • Мебельный магазин
    • Продуктовый магазин
    • Строительный магазин
    • Магазин игрушек
    Гостинично-ресторанный бизнес
    • Бар и паб
    • Ресторан
    • Фастфуд
    • Гостевой дом
    • Дистрибьютор напитков
    • Отель
    Недвижимость
    • Агентство недвижимости
    • Архитектурное бюро
    • Строительство
    • Управление недвижимостью
    • Ландшафтный дизайн
    • Товарищество собственников жилья
    Консалтинг
    • Бухгалтерская фирма
    • Партнер Odoo
    • Маркетинговое агентство
    • Юридическая фирма
    • Подбор персонала
    • Аудиторское бюро
    Производство
    • Текстиль
    • Металл
    • Мебель
    • Продукты питания
    • Пивоварня
    • Корпоративные сувениры
    Здоровье и фитнес
    • Спортивный комплекс
    • Магазин оптики
    • Фитнес-клуб
    • Велнес-центр
    • Аптека
    • Салон красоты
    Услуги
    • Специалист по бытовым услугам
    • Продажа и обслуживание IT-оборудования
    • Солнечные энергосистемы
    • Производство обуви
    • Клининг
    • Системы ОВКВ
    Прочее
    • Некоммерческая организация
    • Консалтинг в сфере устойчивого развития
    • Аренда рекламных щитов
    • Бизнес по фотосъемке
    • Прокат велосипедов
    • Реселлер программного обеспечения
    Все индустрии
  • Community
    Обучение
    • Видео уроки
    • Документация
    • Сертификация
    • Тренинг
    • Блог
    • Подкаст
    Образование и развитие
    • Образовательная программа
    • Деловая игра Scale Up!
    • Экскурсия в офис Odoo
    ПО
    • Скачать
    • Сравнить версии
    • Релизы
    Сотрудничество
    • Github
    • Форум
    • Мероприятия
    • Перевод
    • Стать партнером
    • Услуги для партнеров
    • Зарегистрировать бухгалтерскую фирму
    Услуги
    • Найти партнера
    • Найти бухгалтера
    • Встреча с экспертом
    • Услуги по внедрению
    • Отзывы клиентов
    • Поддержка
    • Обновления
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Заказать демонстрацию
  • Цены
  • Поддержка

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

  • CRM
  • e-Commerce
  • Бухгалтерия
  • Склад
  • PoS
  • Проекты
  • MRP
All apps
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Все посты Люди Значки
Теги (Смотреть все)
odoo accounting v14 pos v15
Об этом форуме
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Все посты Люди Значки
Теги (Смотреть все)
odoo accounting v14 pos v15
Об этом форуме
Помощь

odoo 14 call action invoice sent from another model

Подписаться

Получайте уведомления о появлении активности в этом посте

Этот вопрос был отмечен
invoiceactionsodoomodels.Model
3 Ответы
9115 Представления
Аватар
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
Аватар
Отменить
Аватар
Mohamed Lamine Lalmi
Лучший ответ

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
Аватар
Отменить
Joao Almeida
Автор

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
Автор

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
Автор

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
Автор

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
Автор

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
Автор

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
Автор

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
Автор

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

Аватар
Răzvan Anastasescu
Лучший ответ

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
Аватар
Отменить
Аватар
J. Blanco Caura
Лучший ответ

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

0
Аватар
Отменить
Не оставайтесь в стороне – присоединяйтесь к обсуждению!

Создайте аккаунт сегодня, чтобы получить доступ к эксклюзивным функциям и стать частью нашего замечательного сообщества!

Регистрация
Похожие посты Ответы Просмотры Активность
Odoo - Return record lists on form view
actions odoo
Аватар
Аватар
Аватар
Аватар
3
июл. 24
6690
What are the value need to pass in field 'type' of account.invoice table in Odoo to get Customer_Invoice & Supplier_Invoice ?
invoice odoo
Аватар
Аватар
1
окт. 18
4772
Error Converting Sale Orders to Invoice
invoice odoo
Аватар
0
окт. 15
4196
How to remove product description from invoice lines?
invoice odoo v18
Аватар
Аватар
Аватар
2
авг. 25
3061
Remove link from offer and invoice email Решено
invoice emailtemplate odoo
Аватар
Аватар
Аватар
2
нояб. 24
3855
Сообщество
  • Видео уроки
  • Документация
  • Форум
Открытый исходный код
  • Скачать
  • Github
  • Runbot
  • Перевод
Услуги
  • Хостинг Odoo.sh
  • Поддержка
  • Обновление
  • Индивидуальные решения по доработке
  • Образование
  • Найти бухгалтера
  • Найти партнера
  • Стать партнером
О нас
  • Наша компания
  • Активы бренда
  • Cвяжитесь с нами
  • Вакансии
  • Мероприятия
  • Подкаст
  • Блог
  • Клиенты
  • Правовые документы • Конфиденциальность
  • Безопасность
الْعَرَبيّة 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 – это набор бизнес-модулей с открытым исходным кодом, который закроет все потребности вашей компании: CRM, E-commerce, Бухгалтерия, Склад, POS, управление проектами и др.

Odoo сочетает в себе простоту использования и полную интеграцию всех бизнес-процессов в одной системе.

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