summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
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 /indoteknik_custom/models
parent40b3ae941bce5c822d7297c8ccfc1c752409e21c (diff)
mail po & note
Diffstat (limited to 'indoteknik_custom/models')
-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
5 files changed, 93 insertions, 8 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