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.py102
1 files changed, 89 insertions, 13 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index 82ca3108..99d79072 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -46,12 +46,65 @@ 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)
responsible_ids = fields.Many2many('res.users', string='Responsibles', compute='_compute_responsibles')
status_paid_cbd = fields.Boolean(string='Paid Status', tracking=3, help='Field ini diisi secara manual oleh Finance AP dan hanya untuk status PO CBD')
+ revisi_po = fields.Boolean(string='Revisi', tracking=3)
+
+ @api.model
+ def action_multi_cancel(self):
+ for purchase in self:
+ purchase.update({
+ 'state': 'cancel',
+ })
+
+ if purchase.state == 'cancel':
+ purchase.update({
+ 'approval_status': False,
+ })
+
+ def open_form_multi_cancel(self):
+ action = self.env['ir.actions.act_window']._for_xml_id('indoteknik_custom.action_po_multi_cancel')
+ action['context'] = {
+ 'purchase_ids': [x.id for x in self]
+ }
+ return action
+
+ def delete_line(self):
+ lines_to_delete = self.order_line.filtered(lambda line: line.suggest == 'masih cukup')
+ if not lines_to_delete:
+ raise UserError('Tidak ada item yang masih cukup')
+ lines_to_delete.unlink()
+
+ def open_form_multi_confirm_po(self):
+ action = self.env['ir.actions.act_window']._for_xml_id('indoteknik_custom.action_purchase_order_multi_confirm')
+ action['context'] = {
+ 'order_ids': [x.id for x in self]
+ }
+ return action
+
+ def action_multi_update_paid_status(self):
+ for purchase in self:
+ purchase.update({
+ 'status_paid_cbd': True,
+ })
+
+ def action_multi_confirm_po(self):
+ for purchase in self:
+ if purchase.state != 'draft':
+ continue
+
+ purchase.button_confirm()
+
+ def open_form_multi_update_paid_status(self):
+ action = self.env['ir.actions.act_window']._for_xml_id('indoteknik_custom.action_purchase_order_multi_update')
+ action['context'] = {
+ 'purchase_ids': [x.id for x in self]
+ }
+ return action
def _compute_responsibles(self):
for purchase in self:
@@ -70,15 +123,19 @@ class PurchaseOrder(models.Model):
for line in self.order_line:
i += 1
current_time = datetime.utcnow()
- print(i, len(self.order_line))
+ # print(i, len(self.order_line))
+
price_unit = line.price_unit
taxes = line.taxes_id
- for tax in taxes:
- tax_include = tax.price_include
- tax_amt = tax.amount
- if taxes:
- if not tax_include:
- price_unit = price_unit + (price_unit * tax_amt / 100)
+ # for tax in taxes:
+ # tax_include = tax.price_include
+ # if taxes:
+ # if tax_include:
+ # price_unit = price_unit
+ # else:
+ # price_unit = price_unit + (price_unit * 11 / 100)
+ # else:
+ # price_unit = price_unit + (price_unit * 11 / 100)
purchase_pricelist = self.env['purchase.pricelist'].search([
('product_id', '=', line.product_id.id),
@@ -89,21 +146,24 @@ class PurchaseOrder(models.Model):
purchase_pricelist.create([{
'vendor_id': line.order_id.partner_id.id,
'product_id': line.product_id.id,
- 'product_price': 0.00,
+ 'product_price': 0,
+ 'taxes_system_id': taxes.id,
'system_price': price_unit,
- 'system_last_update': current_time,
+ 'system_last_update': current_time
}])
else:
purchase_pricelist.write({
'system_last_update': current_time,
+ 'taxes_system_id': taxes.id,
'system_price': price_unit
})
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:
@@ -209,6 +269,8 @@ class PurchaseOrder(models.Model):
self.order_line.unlink()
for order_line in self.sale_order_id.order_line:
+ if order_line.vendor_id != self.partner_id:
+ continue
if order_line.product_id.id and order_line.product_id.id not in products_exception:
qty_available = order_line.product_id.qty_onhand_bandengan + order_line.product_id.qty_incoming_bandengan - order_line.product_id.outgoing_qty
@@ -249,8 +311,16 @@ 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:
+ if picking.state in ['done', 'cancel']:
+ continue
+ picking.scheduled_date = self.date_planned
+ picking.date_deadline = self.date_planned
+
def button_confirm(self):
res = super(PurchaseOrder, self).button_confirm()
+ current_time = datetime.now()
if self.total_percent_margin < self.total_so_percent_margin and not self.env.user.is_purchasing_manager and not self.env.user.is_leader:
raise UserError("Beda Margin dengan Sales, harus approval Manager")
@@ -268,6 +338,11 @@ class PurchaseOrder(models.Model):
if send_email:
self._send_mail()
+
+ if self.revisi_po:
+ delta_time = current_time - timedelta(days=2)
+ delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
+ self.date_approve = delta_time
self.approval_status = 'approved'
self.po_status = 'menunggu'
@@ -275,10 +350,11 @@ class PurchaseOrder(models.Model):
self.calculate_line_no()
# override date planned added with two days
- current_time = datetime.now()
- delta_time = current_time + timedelta(days=2)
+ leadtime = self.partner_id.leadtime
+ 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