summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2023-08-23 11:59:53 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2023-08-23 11:59:53 +0700
commita4352ddc19c392e0ed5f30d350ce928d98f5b6e2 (patch)
tree17d1efdf0c3a46f5db06ed469275963275a7496c
parent40b3ae941bce5c822d7297c8ccfc1c752409e21c (diff)
mail po & note
-rwxr-xr-xindoteknik_custom/models/__init__.py1
-rw-r--r--indoteknik_custom/models/po_sync_price.py14
-rw-r--r--indoteknik_custom/models/procurement_monitoring_detail.py6
-rwxr-xr-xindoteknik_custom/models/purchase_order.py78
-rwxr-xr-xindoteknik_custom/models/sale_monitoring_detail.py2
-rwxr-xr-xindoteknik_custom/security/ir.model.access.csv1
-rw-r--r--indoteknik_custom/views/mail_template_po.xml100
-rw-r--r--indoteknik_custom/views/procurement_monitoring_detail.xml7
8 files changed, 135 insertions, 74 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index 255a12f6..d884793a 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -81,3 +81,4 @@ from . import account_general_ledger
from . import account_report_financial
from . import account_report_general_ledger
from . import price_group
+from . import po_sync_price
diff --git a/indoteknik_custom/models/po_sync_price.py b/indoteknik_custom/models/po_sync_price.py
new file mode 100644
index 00000000..3e0ef621
--- /dev/null
+++ b/indoteknik_custom/models/po_sync_price.py
@@ -0,0 +1,14 @@
+from odoo import fields, models, api
+
+
+class POSyncPrice(models.Model):
+ _name = "po.sync.price"
+ _description = "PO Sync Price"
+
+ order_line_id = fields.Many2one('purchase.order.line', string='Purchase Order')
+ # purchase_order_id = fields.Many2one('purchase.order', string='Purchase Order')
+ # product_variant_id = fields.Many2one('product.product', string='Product Variant')
+ # manufacture_id = fields.Many2one('x_manufactures',string="Brand")
+ # unit_price = fields.Float(string="Unit Price")
+ # vendor_price = fields.Float(string="Vendor Price")
+ # created = fields.Datetime(string="Create Date") \ No newline at end of file
diff --git a/indoteknik_custom/models/procurement_monitoring_detail.py b/indoteknik_custom/models/procurement_monitoring_detail.py
index 6031e04a..80e71304 100644
--- a/indoteknik_custom/models/procurement_monitoring_detail.py
+++ b/indoteknik_custom/models/procurement_monitoring_detail.py
@@ -22,6 +22,7 @@ class SaleMonitoringDetail(models.Model):
date_order = fields.Datetime(string="Date Order")
status = fields.Char(string="Status")
po_ids = fields.Many2many('purchase.order', string='PO', compute='_compute_po')
+ note = fields.Char(string="Note")
def _compute_po(self):
for line in self:
@@ -58,7 +59,8 @@ class SaleMonitoringDetail(models.Model):
get_qty_available(sol.product_id) as qty_available,
get_qty_reserved(so.id, sol.product_id) as qty_reserved,
get_qty_po(so.id, sol.product_id) AS qty_po,
- so.date_order AS date_order
+ so.date_order AS date_order,
+ sol.note_procurement as note
FROM sale_order so
JOIN sale_order_line sol ON sol.order_id = so.id
JOIN product_product p ON p.id = sol.product_id
@@ -66,7 +68,7 @@ class SaleMonitoringDetail(models.Model):
WHERE pt.type IN ('consu','product')
AND so.state IN ('sale','done')
AND so.create_date >= '2022-08-10'
- and so.so_status not in ('terproses')
+ and so.so_status not in('terproses')
) a
--where a.qty_po < a.qty_so
)
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index c968ed53..0020753f 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -2,7 +2,14 @@ from odoo import fields, models, api, _
from odoo.exceptions import AccessError, UserError, ValidationError
from datetime import datetime, timedelta
import logging
-from pytz import timezone
+from pytz import timezone, utc
+import io
+from openpyxl import Workbook
+import base64
+try:
+ from odoo.tools.misc import xlsxwriter
+except ImportError:
+ import xlsxwriter
_logger = logging.getLogger(__name__)
@@ -43,7 +50,7 @@ class PurchaseOrder(models.Model):
def add_product_to_pricelist(self):
for line in self.order_line:
- current_time = fields.Datetime.now(timezone('Asia/Jakarta')).strftime('%Y-%m-%d %H:%M:%S')
+ current_time = datetime.utcnow()
purchase_pricelist = self.env['purchase.pricelist'].search([
('product_id', '=', line.product_id.id),
@@ -224,7 +231,8 @@ class PurchaseOrder(models.Model):
raise UserError("Terdapat barang yang tidak bisa diproses")
if line.product_id:
self.add_product_to_pricelist()
- if line.price_unit != line.price_vendor:
+ if line.price_unit != line.price_vendor and line.price_vendor != 0:
+ self._send_po_not_sync()
send_email = True
break
@@ -244,9 +252,69 @@ class PurchaseOrder(models.Model):
return res
+ def _send_po_not_sync(self):
+ # Mengirim data ke model Po Sync Price jika harga po dan purchase pricelist tidak singkron
+ for line in self.order_line:
+ if line.price_unit != line.price_vendor and line.price_vendor != 0:
+ self.env['po.sync.price'].create([{
+ 'order_line_id': line.id,
+ }])
+
+
+
def _send_mail(self):
- template_id = self.env.ref('indoteknik_custom.mail_template_po_sync_price').id
- template = self.env['mail.template'].browse(template_id)
+ output = io.BytesIO()
+ workbook = xlsxwriter.Workbook(output, {'in_memory': True})
+ worksheet = workbook.add_worksheet()
+
+ format6 = workbook.add_format({'font_size': 12, 'align': 'center', 'bg_color': '#D3D3D3', 'bold': True})
+ format1 = workbook.add_format({'font_size': 11, 'align': 'center', 'valign': 'vcenter'})
+ format2 = workbook.add_format({'font_size': 10, 'bold': True})
+ format3 = workbook.add_format({'font_size': 10, 'bold': True})
+
+ worksheet.set_column(0, 0, 10)
+ worksheet.set_column(1, 1, 20)
+ worksheet.set_column(2, 2, 20)
+ worksheet.set_column(3, 3, 20)
+ worksheet.set_column(4, 4, 15)
+ worksheet.set_column(5, 5, 15)
+
+ worksheet.write('A1', 'PO', format6)
+ worksheet.write('B1', 'SKU', format6)
+ worksheet.write('C1', 'Product', format6)
+ worksheet.write('D1', 'Brand', format6)
+ worksheet.write('E1', 'Unit Price', format6)
+ worksheet.write('F1', 'Vendor Price', format6)
+ worksheet.write('G1', 'Created On', format6)
+
+ row_number = 1
+ po_sync = self.env['po.sync.price'].search([], order='create_date desc')
+ for po in po_sync:
+ worksheet.write(row_number, 0, po.order_line_id.order_id.name, format1)
+ worksheet.write(row_number, 1, po.order_line_id.product_id.default_code, format1)
+ worksheet.write(row_number, 2, po.order_line_id.product_id.name, format1)
+ worksheet.write(row_number, 3, po.order_line_id.product_id.x_manufacture.x_name, format1)
+ worksheet.write(row_number, 4, po.order_line_id.price_unit, format1)
+ worksheet.write(row_number, 5, po.order_line_id.price_vendor, format1)
+ worksheet.write(row_number, 6, po.create_date.replace(tzinfo=utc).astimezone(timezone('Asia/Jakarta')).strftime('%Y-%m-%d %H:%M:%S'), format1)
+ row_number += 1
+
+ workbook.close()
+
+ output.seek(0)
+
+ template = self.env.ref('indoteknik_custom.mail_template_po_sync_price')
+ template.attachment_ids.unlink()
+ attachment_vals = {
+ 'name': 'Purchase Order.xlsx',
+ 'datas': base64.b64encode(output.read()),
+ 'mimetype': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
+ 'res_model': 'mail.template',
+ 'res_id': template.id,
+ }
+ attachment_id = self.env['ir.attachment'].create(attachment_vals)
+
+ template.attachment_ids = [(4, attachment_id.id)]
template.send_mail(self.id, force_send=True)
def po_approve(self):
diff --git a/indoteknik_custom/models/sale_monitoring_detail.py b/indoteknik_custom/models/sale_monitoring_detail.py
index 43a8aeb0..dc4caa14 100755
--- a/indoteknik_custom/models/sale_monitoring_detail.py
+++ b/indoteknik_custom/models/sale_monitoring_detail.py
@@ -55,7 +55,7 @@ class SaleMonitoringDetail(models.Model):
get_qty_received(so.id, sol.product_id) AS qty_po_received,
get_qty_reserved(so.id, sol.product_id) as qty_reserved,
sol.note_procurement as note
- FROM sale_order so
+ FROM sale_order so
JOIN sale_order_line sol ON sol.order_id = so.id
JOIN product_product p ON p.id = sol.product_id
JOIN product_template pt ON pt.id = p.product_tmpl_id
diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv
index 6f9ba9e4..da389854 100755
--- a/indoteknik_custom/security/ir.model.access.csv
+++ b/indoteknik_custom/security/ir.model.access.csv
@@ -67,3 +67,4 @@ access_account_move_multi_update,access.account.move.multi_update,model_account_
access_airway_bill,access.airway.bill,model_airway_bill,,1,1,1,1
access_airway_bill_manifest,access.airway.bill.manifest,model_airway_bill_manifest,,1,1,1,1
access_price_group,access.price.group,model_price_group,,1,1,1,1
+access_po_sync_price,access.po.sync.price,model_po_sync_price,,1,1,1,1
diff --git a/indoteknik_custom/views/mail_template_po.xml b/indoteknik_custom/views/mail_template_po.xml
index 02053767..f4eb3577 100644
--- a/indoteknik_custom/views/mail_template_po.xml
+++ b/indoteknik_custom/views/mail_template_po.xml
@@ -12,69 +12,43 @@
style="padding-top: 16px; background-color: #F1F1F1; font-family:Verdana, Arial,sans-serif; color: #454748; width: 100%; border-collapse:separate;">
<tr>
<td align="center">
- <table border="0" cellpadding="0" cellspacing="0" width="590"
- style="padding: 16px; background-color: white; color: #454748; border-collapse:separate;">
- <tbody>
- <!-- HEADER -->
- <tr>
- <td align="center" style="min-width: 590px;">
- <table border="0" cellpadding="0" cellspacing="0" width="590"
- style="min-width: 590px; background-color: white; padding: 0px 8px 0px 8px; border-collapse:separate;">
- <tr>
- <td valign="middle">
- <span style="font-size: 10px;">PO</span><br />
- <span style="font-size: 20px; font-weight: bold;">
- ${object.name}
- </span>
- </td>
- </tr>
- <tr>
- <td colspan="2" style="text-align:center;">
- <hr width="100%"
- style="background-color:rgb(204,204,204);border:medium none;clear:both;display:block;font-size:0px;min-height:1px;line-height:0; margin: 16px 0px 16px 0px;" />
- </td>
- </tr>
- </table>
- </td>
- </tr>
- <!-- CONTENT -->
- <tr>
- <td align="center" style="min-width: 590px;">
- <table border="0" cellpadding="0" cellspacing="0" width="590"
- style="min-width: 590px; background-color: white; padding: 0px 8px 0px 8px; border-collapse:separate;">
- <tr>
- <td valign="top" style="font-size: 13px;">
- <div>
- Dear Stefanus Darren &amp; Tyas K Putra,
- <br/><br/>
- Terdapat PO yang harga Unit Price nya tidak sama dengan yang ada di purchase pricelist nya.
- <br/><br/>
- Berikut adalah rincian PO:
- % for line in object.order_line:
- % if line.price_unit != line.price_vendor
- <ul>
- <li>Nama Produk: ${line.product_id.name}</li>
- <li>Harga Unit dalam PO: Rp ${'{:,.2f}'.format(line.price_unit)}</li>
- <li>Harga Unit dalam Purchase Pricelist: Rp ${'{:,.2f}'.format(line.price_vendor)}</li>
- </ul>
- % endif
- % endfor
- Silahkan periksa dan lakukan koreksi jika diperlukan.
- <br/><br/>
- Terima kasih.
- </div>
- </td>
- </tr>
- <tr>
- <td style="text-align:center;">
- <hr width="100%"
- style="background-color:rgb(204,204,204);border:medium none;clear:both;display:block;font-size:0px;min-height:1px;line-height:0; margin: 16px 0px 16px 0px;" />
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </tbody>
+ <table border="0" cellpadding="0" cellspacing="0" width="100%"
+ style="min-width: 590px; background-color: white; padding: 0px 8px 0px 8px; border-collapse: separate;">
+ <tr>
+ <td valign="top" style="font-size: 13px;">
+ <div>
+ Dear Stefanus Darren &amp; Tyas K Putra,
+ <br /><br />
+ Terdapat PO yang harga Unit Price nya tidak sama dengan yang ada di purchase pricelist nya.
+ <br /><br />
+ Berikut adalah rincian PO:
+ </div>
+ <table border="1" cellpadding="5" cellspacing="0"
+ style="border-collapse: collapse; width: 100%; font-size: 13px;">
+ <tr>
+ <th>Nama Produk</th>
+ <th>Brand</th>
+ <th>Harga Unit dalam PO</th>
+ <th>Harga Unit dalam Purchase Pricelist</th>
+ </tr>
+ % for line in object.order_line:
+ % if line.price_vendor != 0 and line.price_unit != line.price_vendor
+ <tr>
+ <td>${line.product_id.name}</td>
+ <td>${line.product_id.x_manufacture.x_name}</td>
+ <td>Rp ${'{:,.2f}'.format(line.price_unit)}</td>
+ <td>Rp ${'{:,.2f}'.format(line.price_vendor)}</td>
+ </tr>
+ % endif
+ % endfor
+ </table>
+ <div>
+ Silahkan periksa dan lakukan koreksi jika diperlukan.
+ <br /><br />
+ Terima kasih.
+ </div>
+ </td>
+ </tr>
</table>
</td>
</tr>
diff --git a/indoteknik_custom/views/procurement_monitoring_detail.xml b/indoteknik_custom/views/procurement_monitoring_detail.xml
index 8f3827c1..e4939213 100644
--- a/indoteknik_custom/views/procurement_monitoring_detail.xml
+++ b/indoteknik_custom/views/procurement_monitoring_detail.xml
@@ -17,10 +17,11 @@
<field name="po_ids" widget="many2many_tags"/>
<field name="qty_po"/>
<field name="status"
- widget="badge"
- decoration-danger="status == 'harus beli'"
- decoration-success="status == 'cukup'"
+ widget="badge"
+ decoration-danger="status == 'harus beli'"
+ decoration-success="status == 'cukup'"
/>
+ <field name="note" optional="hide"/>
</tree>
</field>
</record>