summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/purchase_order.py
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models/purchase_order.py')
-rwxr-xr-xindoteknik_custom/models/purchase_order.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index 9e851ef9..c968ed53 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -2,6 +2,7 @@ from odoo import fields, models, api, _
from odoo.exceptions import AccessError, UserError, ValidationError
from datetime import datetime, timedelta
import logging
+from pytz import timezone
_logger = logging.getLogger(__name__)
@@ -40,6 +41,31 @@ class PurchaseOrder(models.Model):
count_line_product = fields.Float('Total Item', compute='compute_count_line_product')
note_description = fields.Char(string='Note', help='bisa diisi sebagai informasi indent barang tertentu atau apapun')
+ 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')
+
+ purchase_pricelist = self.env['purchase.pricelist'].search([
+ ('product_id', '=', line.product_id.id),
+ ('vendor_id', '=', line.order_id.partner_id.id)
+ ])
+ purchase_pricelist = purchase_pricelist.with_context(update_by='system')
+ if not purchase_pricelist:
+ purchase_pricelist.create([{
+ 'vendor_id': line.order_id.partner_id.id,
+ 'product_id': line.product_id.id,
+ 'product_price': 0.00,
+ 'system_price': line.price_unit,
+ 'system_last_update': current_time,
+ }])
+ return True
+
+ for pricelist in purchase_pricelist:
+ pricelist.write({
+ 'system_last_update': current_time,
+ 'system_price': line.price_unit
+ })
+
def _compute_date_planned(self):
for order in self:
if order.date_approve:
@@ -196,12 +222,15 @@ class PurchaseOrder(models.Model):
for line in self.order_line:
if not line.product_id.purchase_ok:
raise UserError("Terdapat barang yang tidak bisa diproses")
+ if line.product_id:
+ self.add_product_to_pricelist()
if line.price_unit != line.price_vendor:
send_email = True
break
if send_email:
self._send_mail()
+
self.approval_status = 'approved'
self.po_status = 'menunggu'