correct problem for sending invoice emails
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
from odoo import models, api, fields
|
from odoo import models, api, fields
|
||||||
@@ -9,37 +10,41 @@ class AccountInvoiceSend(models.TransientModel):
|
|||||||
|
|
||||||
# Allow archived partners to remain selectable
|
# Allow archived partners to remain selectable
|
||||||
partner_ids = fields.Many2many(
|
partner_ids = fields.Many2many(
|
||||||
'res.partner',
|
"res.partner",
|
||||||
string='Recipients',
|
string="Recipients",
|
||||||
help='Contacts of the invoice that will receive the email.',
|
help="Contacts of the invoice that will receive the email.",
|
||||||
context={'active_test': False},
|
context={"active_test": False},
|
||||||
check_company=True,
|
check_company=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def default_get(self, fields):
|
def default_get(self, fields):
|
||||||
_logger.error("🔥 ACCOUNT.INVOICE.SEND default_get")
|
_logger.error("🔥 ACCOUNT.INVOICE.SEND default_get")
|
||||||
|
|
||||||
res = super().default_get(fields)
|
res = super().default_get(fields)
|
||||||
|
|
||||||
active_ids = self.env.context.get('active_ids', [])
|
active_ids = self.env.context.get("active_ids", [])
|
||||||
if active_ids:
|
if active_ids:
|
||||||
moves = self.env['account.move'].with_context(
|
moves = (
|
||||||
active_test=False
|
self.env["account.move"]
|
||||||
).browse(active_ids)
|
.with_context(active_test=False)
|
||||||
|
.browse(active_ids)
|
||||||
partners = moves.mapped('partner_id').filtered(lambda p: p.email)
|
)
|
||||||
|
|
||||||
|
partners = moves.mapped("partner_id").filtered(lambda p: p.email)
|
||||||
if partners:
|
if partners:
|
||||||
res['partner_ids'] = [(6, 0, partners.ids)]
|
res["partner_ids"] = [(6, 0, partners.ids)]
|
||||||
_logger.error(f"🔥 Set partner_ids: {res['partner_ids']}")
|
_logger.error(f"🔥 Set partner_ids: {res['partner_ids']}")
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def action_send_and_print(self):
|
def action_send_and_print(self):
|
||||||
_logger.error("🔥🔥🔥 ACCOUNT.INVOICE.SEND action_send_and_print CALLED 🔥🔥🔥")
|
_logger.error("🔥🔥🔥 ACCOUNT.INVOICE.SEND action_send_and_print CALLED 🔥🔥🔥")
|
||||||
_logger.error(f"🔥 Wizard ID: {self.id}")
|
_logger.error(f"🔥 Wizard ID: {self.id}")
|
||||||
_logger.error(f"🔥 Partner IDs: {self.partner_ids.ids}") # This returns a list of IDs
|
_logger.error(
|
||||||
|
f"🔥 Partner IDs: {self.partner_ids.ids}"
|
||||||
|
) # This returns a list of IDs
|
||||||
|
|
||||||
# Call parent with context AND ensure partner_ids are passed
|
# Call parent with context AND ensure partner_ids are passed
|
||||||
return super(
|
return super(
|
||||||
AccountInvoiceSend,
|
AccountInvoiceSend,
|
||||||
@@ -51,14 +56,13 @@ class AccountInvoiceSend(models.TransientModel):
|
|||||||
mark_invoice_as_sent=True,
|
mark_invoice_as_sent=True,
|
||||||
# Pass simple list of IDs, NOT ORM tuple format
|
# Pass simple list of IDs, NOT ORM tuple format
|
||||||
invoice_partner_ids=self.partner_ids.ids if self.partner_ids else [],
|
invoice_partner_ids=self.partner_ids.ids if self.partner_ids else [],
|
||||||
)
|
),
|
||||||
).action_send_and_print()
|
).action_send_and_print()
|
||||||
|
|
||||||
def _get_composer_values(self, res_ids, template):
|
def _get_composer_values(self, res_ids, template):
|
||||||
_logger.error("🔥 ACCOUNT.INVOICE.SEND _get_composer_values")
|
_logger.error("🔥 ACCOUNT.INVOICE.SEND _get_composer_values")
|
||||||
|
|
||||||
# Also pass context to composer
|
values = super(
|
||||||
return super(
|
|
||||||
AccountInvoiceSend,
|
AccountInvoiceSend,
|
||||||
self.with_context(
|
self.with_context(
|
||||||
active_test=False,
|
active_test=False,
|
||||||
@@ -66,5 +70,14 @@ class AccountInvoiceSend(models.TransientModel):
|
|||||||
mail_notify_force=True,
|
mail_notify_force=True,
|
||||||
force_email=True,
|
force_email=True,
|
||||||
mark_invoice_as_sent=True,
|
mark_invoice_as_sent=True,
|
||||||
|
),
|
||||||
|
)._get_composer_values(res_ids, template)
|
||||||
|
|
||||||
|
# 🔥 THIS IS THE CRITICAL PART
|
||||||
|
if self.partner_ids:
|
||||||
|
values["partner_ids"] = [(6, 0, self.partner_ids.ids)]
|
||||||
|
_logger.error(
|
||||||
|
"🔥 Injected partner_ids into composer: %s", self.partner_ids.ids
|
||||||
)
|
)
|
||||||
)._get_composer_values(res_ids, template)
|
|
||||||
|
return values
|
||||||
|
|||||||
Reference in New Issue
Block a user