summaryrefslogtreecommitdiff
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
parent02d27a0e871dd4949c9382000843cd35dd3db3f8 (diff)
fix send email
-rw-r--r--indoteknik_custom/models/stock_immediate_transfer.py36
-rw-r--r--indoteknik_custom/models/stock_picking.py64
-rw-r--r--indoteknik_custom/views/stock_picking.xml4
3 files changed, 75 insertions, 29 deletions
diff --git a/indoteknik_custom/models/stock_immediate_transfer.py b/indoteknik_custom/models/stock_immediate_transfer.py
new file mode 100644
index 00000000..4be0dff2
--- /dev/null
+++ b/indoteknik_custom/models/stock_immediate_transfer.py
@@ -0,0 +1,36 @@
+from odoo import models, api, _
+from odoo.exceptions import UserError
+
+class StockImmediateTransfer(models.TransientModel):
+ _inherit = 'stock.immediate.transfer'
+
+ def process(self):
+ """Override process method to add send_mail_bills logic."""
+ pickings_to_do = self.env['stock.picking']
+ pickings_not_to_do = self.env['stock.picking']
+
+ for line in self.immediate_transfer_line_ids:
+ if line.to_immediate is True:
+ pickings_to_do |= line.picking_id
+ else:
+ pickings_not_to_do |= line.picking_id
+
+ for picking in pickings_to_do:
+ picking.send_mail_bills()
+ # If still in draft => confirm and assign
+ if picking.state == 'draft':
+ picking.action_confirm()
+ if picking.state != 'assigned':
+ picking.action_assign()
+ if picking.state != 'assigned':
+ raise UserError(_("Could not reserve all requested products. Please use the 'Mark as Todo' button to handle the reservation manually."))
+ for move in picking.move_lines.filtered(lambda m: m.state not in ['done', 'cancel']):
+ for move_line in move.move_line_ids:
+ move_line.qty_done = move_line.product_uom_qty
+
+ pickings_to_validate = self.env.context.get('button_validate_picking_ids')
+ if pickings_to_validate:
+ pickings_to_validate = self.env['stock.picking'].browse(pickings_to_validate)
+ pickings_to_validate = pickings_to_validate - pickings_not_to_do
+ return pickings_to_validate.with_context(skip_immediate=True).button_validate()
+ return True
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':
diff --git a/indoteknik_custom/views/stock_picking.xml b/indoteknik_custom/views/stock_picking.xml
index 9d22903e..c8210efb 100644
--- a/indoteknik_custom/views/stock_picking.xml
+++ b/indoteknik_custom/views/stock_picking.xml
@@ -155,7 +155,7 @@
<field name="sj_documentation" widget="image" />
<field name="paket_documentation" widget="image" />
</group>
- <group>
+ <group attrs="{'invisible': [('carrier_id', '!=', 151)]}">
<field name="envio_id" invisible="1"/>
<field name="envio_code"/>
<field name="envio_ref_code"/>
@@ -173,7 +173,7 @@
<field name="envio_latest_longitude" invisible="1"/>
<field name="tracking_by" invisible="1"/>
</group>
- <group>
+ <group attrs="{'invisible': [('carrier_id', '!=', 9)]}">
<field name="lalamove_data" invisible="1"/>
<field name="lalamove_order_id"/>
<field name="lalamove_address"/>