summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/stock_picking.py
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2025-01-08 13:14:30 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2025-01-08 13:14:30 +0700
commitb977df58492c18fbe0501e9e02cdee24c5e5176d (patch)
tree9ddfb486b3de6af3b7dc54a43444462929fc637e /indoteknik_custom/models/stock_picking.py
parent02d27a0e871dd4949c9382000843cd35dd3db3f8 (diff)
fix send email
Diffstat (limited to 'indoteknik_custom/models/stock_picking.py')
-rw-r--r--indoteknik_custom/models/stock_picking.py64
1 files changed, 37 insertions, 27 deletions
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index 51899de9..2feb9c72 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -164,7 +164,7 @@ class StockPicking(models.Model):
('picking_type_code', '=', 'outgoing'),
('state', '=', 'done'),
('carrier_id', '=', 9)
- ])
+ ])
for picking in pickings:
try:
order_id = picking.lalamove_order_id
@@ -796,27 +796,31 @@ class StockPicking(models.Model):
self.calculate_line_no()
self.date_done = datetime.datetime.utcnow()
self.state_reserve = 'done'
+ return res
+
- template = self.env.ref('indoteknik_custom.mail_template_invoice_po_document')
- if template and self.purchase_id:
- # Render email body
- email_values = template.sudo().generate_email(
- res_ids=[self.purchase_id.id],
- fields=['body_html']
- )
- rendered_body = email_values.get(self.purchase_id.id, {}).get('body_html', '')
+ def send_mail_bills(self):
+ if self.picking_type_code == 'incoming' and self.purchase_id:
+ template = self.env.ref('indoteknik_custom.mail_template_invoice_po_document')
+ if template and self.purchase_id:
+ # Render email body
+ email_values = template.sudo().generate_email(
+ res_ids=[self.purchase_id.id],
+ fields=['body_html']
+ )
+ rendered_body = email_values.get(self.purchase_id.id, {}).get('body_html', '')
- # Render report dengan XML ID
- report = self.env.ref('purchase.action_report_purchase_order') # Gunakan XML ID laporan
- if not report:
- raise UserError("Laporan dengan XML ID 'purchase.action_report_purchase_order' tidak ditemukan.")
+ # Render report dengan XML ID
+ report = self.env.ref('purchase.action_report_purchase_order') # Gunakan XML ID laporan
+ if not report:
+ raise UserError("Laporan dengan XML ID 'purchase.action_report_purchase_order' tidak ditemukan.")
- # Render laporan ke PDF
- pdf_content, _ = report._render_qweb_pdf([self.purchase_id.id])
- report_content = base64.b64encode(pdf_content).decode('utf-8')
+ # Render laporan ke PDF
+ pdf_content, _ = report._render_qweb_pdf([self.purchase_id.id])
+ report_content = base64.b64encode(pdf_content).decode('utf-8')
- # Kirim email menggunakan template
- email_sent = template.sudo().send_mail(self.purchase_id.id, force_send=True)
+ # Kirim email menggunakan template
+ email_sent = template.sudo().send_mail(self.purchase_id.id, force_send=True)
if email_sent:
# Buat attachment untuk laporan
@@ -829,16 +833,22 @@ class StockPicking(models.Model):
'mimetype': 'application/pdf',
})
- # Tambahkan isi email dan laporan ke log note
- self.purchase_id.message_post(
- body=rendered_body,
- subject="Pengiriman Email Invoice",
- message_type='comment',
- subtype_xmlid="mail.mt_note",
- attachment_ids=[attachment.id],
- )
+ # Siapkan data untuk mail.compose.message
+ compose_values = {
+ 'subject': "Pengiriman Email Invoice",
+ 'body': rendered_body,
+ 'attachment_ids': [(4, attachment.id)],
+ 'res_id': self.purchase_id.id,
+ 'model': 'purchase.order',
+ }
- return res
+ # Buat mail.compose.message
+ compose_message = self.env['mail.compose.message'].create(compose_values)
+
+ # Kirim pesan melalui wizard
+ compose_message.action_send_mail()
+
+ return True
def action_cancel(self):
if not self.env.user.is_logistic_approver and self.env.context.get('active_model') == 'stock.picking':