summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-01-09 14:11:04 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-01-09 14:11:04 +0700
commit3615748eafd2d2cfd81f6ddc95d50a7bc347798d (patch)
tree774208714a7239c74e2133872fba43917218141a
parent8be31f0f44c2fde870c7c85e27379f88e1b38d7c (diff)
ETA on sales dan purchase order
-rwxr-xr-xindoteknik_custom/models/purchase_order.py14
-rw-r--r--indoteknik_custom/models/res_partner.py1
-rwxr-xr-xindoteknik_custom/models/sale_order.py25
-rw-r--r--indoteknik_custom/views/res_partner.xml3
-rwxr-xr-xindoteknik_custom/views/sale_order.xml3
5 files changed, 41 insertions, 5 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index 6641e204..ba6b6c41 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -45,7 +45,7 @@ class PurchaseOrder(models.Model):
summary_qty_po = fields.Float('Total Qty', compute='_compute_summary_qty')
summary_qty_receipt = fields.Float('Summary Qty Receipt', compute='_compute_summary_qty')
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')
+ note_description = fields.Char(string='Noteman', help='bisa diisi sebagai informasi indent barang tertentu atau apapun')
has_active_invoice = fields.Boolean(string='Has Active Invoice', compute='_compute_has_active_invoice')
description = fields.Char(string='Description', help='bisa diisi sebagai informasi indent barang tertentu atau apapun')
purchase_order_lines = fields.One2many('purchase.order.line', 'order_id', string='Indent', auto_join=True)
@@ -114,8 +114,9 @@ class PurchaseOrder(models.Model):
def _compute_date_planned(self):
for order in self:
if order.date_approve:
+ leadtime = order.partner_id.leadtime
current_time = order.date_approve
- delta_time = current_time + timedelta(days=2)
+ delta_time = current_time + timedelta(days=leadtime)
delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
order.date_planned = delta_time
else:
@@ -261,6 +262,11 @@ class PurchaseOrder(models.Model):
amount += line.price_total
order.delivery_amount = amount
+ def date_deadline_ref_date_planned(self):
+ for picking in self.picking_ids:
+ picking.scheduled_date = self.date_planned
+ picking.date_deadline = self.date_planned
+
def button_confirm(self):
res = super(PurchaseOrder, self).button_confirm()
@@ -287,10 +293,12 @@ class PurchaseOrder(models.Model):
self.calculate_line_no()
# override date planned added with two days
+ leadtime = self.partner_id.leadtime
current_time = datetime.now()
- delta_time = current_time + timedelta(days=2)
+ delta_time = current_time + timedelta(days=leadtime)
delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
self.date_planned = delta_time
+ self.date_deadline_ref_date_planned()
return res
diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py
index fcde9369..a7302245 100644
--- a/indoteknik_custom/models/res_partner.py
+++ b/indoteknik_custom/models/res_partner.py
@@ -19,6 +19,7 @@ class ResPartner(models.Model):
])
sppkp = fields.Char(string="SPPKP")
counter = fields.Integer(string="Counter", default=0)
+ leadtime = fields.Integer(string="Leadtime", default=0)
digital_invoice_tax = fields.Boolean(string="Digital Invoice & Faktur Pajak")
is_potential = fields.Boolean(string='Potential')
pakta_integritas = fields.Boolean(string='Pakta Integritas')
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 95cbf8ce..07fd60fc 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -1,6 +1,6 @@
from odoo import fields, models, api, _
from odoo.exceptions import UserError, ValidationError
-from datetime import datetime
+from datetime import datetime, timedelta
import logging, random, string, requests, math, json, re
_logger = logging.getLogger(__name__)
@@ -82,7 +82,28 @@ class SaleOrder(models.Model):
email = fields.Char(string='Email')
picking_iu_id = fields.Many2one('stock.picking', 'Picking IU')
helper_by_id = fields.Many2one('res.users', 'Helper By')
- # picking_ids = fields.Many2many('stock.picking', string='Pickings', compute='_get_pickings', readonly=True, copy=False, search="_search_picking_ids")
+ eta_date = fields.Datetime(string='ETA Date', tracking=3, copy=False, compute='_compute_eta_date')
+
+ def _compute_eta_date(self):
+ unique_partner_ids = set()
+ total_leadtime = 0
+ total_orders = 0
+
+ for line in self.order_line:
+ vendor_id = line.vendor_id.id
+ if vendor_id not in unique_partner_ids:
+ unique_partner_ids.add(vendor_id)
+ leadtime = line.vendor_id.leadtime
+ total_leadtime += leadtime
+ total_orders += 1
+
+ if total_orders > 0 and self.date_order and self.state not in ['cancel', 'draft']:
+ average_leadtime = total_leadtime / total_orders
+ rounded_average_leadtime = round(average_leadtime)
+ eta_date = self.date_order + timedelta(days=rounded_average_leadtime)
+ self.eta_date = eta_date
+ else:
+ self.eta_date = False
def _prepare_invoice(self):
"""
diff --git a/indoteknik_custom/views/res_partner.xml b/indoteknik_custom/views/res_partner.xml
index 58fff00a..da2dec99 100644
--- a/indoteknik_custom/views/res_partner.xml
+++ b/indoteknik_custom/views/res_partner.xml
@@ -23,6 +23,9 @@
<field name="is_berikat" position="after">
<field name="pakta_integritas"/>
</field>
+ <group name="purchase" position="inside">
+ <field name="leadtime"/>
+ </group>
</field>
</record>
</data>
diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml
index 18ae4c51..696cedc4 100755
--- a/indoteknik_custom/views/sale_order.xml
+++ b/indoteknik_custom/views/sale_order.xml
@@ -44,6 +44,9 @@
<field name="user_id" position="after">
<field name="helper_by_id" readonly="1"/>
</field>
+ <field name="tag_ids" position="after">
+ <field name="eta_date" readonly="1"/>
+ </field>
<field name="analytic_account_id" position="after">
<field name="customer_type" required="1"/>
<field name="npwp" placeholder='99.999.999.9-999.999' required="1"/>