summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-08-13 14:08:29 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-08-13 14:08:29 +0700
commit7772fcd29c37b03ba0b23c233aa8e030a82a0d81 (patch)
tree0de5a561389902af5a0d420f707954b1564e98c0 /indoteknik_custom/models
parent1fb90f4b0ea75ca0b9eb723924a2ba4ea27a5a65 (diff)
approval date doc
Diffstat (limited to 'indoteknik_custom/models')
-rwxr-xr-xindoteknik_custom/models/__init__.py1
-rw-r--r--indoteknik_custom/models/approval_date_doc.py49
2 files changed, 50 insertions, 0 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index 116354d6..e9ce587c 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -124,3 +124,4 @@ from . import report_logbook_bill
from . import sale_order_multi_uangmuka_penjualan
from . import shipment_group
from . import sales_order_reject
+from . import approval_date_doc
diff --git a/indoteknik_custom/models/approval_date_doc.py b/indoteknik_custom/models/approval_date_doc.py
new file mode 100644
index 00000000..e00b7416
--- /dev/null
+++ b/indoteknik_custom/models/approval_date_doc.py
@@ -0,0 +1,49 @@
+from odoo import models, api, fields
+from odoo.exceptions import AccessError, UserError, ValidationError
+from datetime import timedelta, date, datetime
+import logging
+
+_logger = logging.getLogger(__name__)
+
+class ApprovalDateDoc(models.Model):
+ _name = "approval.date.doc"
+ _description = "Approval Date Doc"
+ _rec_name = 'number'
+
+ picking_id = fields.Many2one('stock.picking', string='Picking')
+ number = fields.Char(string='Document No', index=True, copy=False, readonly=True, tracking=True)
+ driver_departure_date = fields.Datetime(
+ string='Driver Departure Date',
+ copy=False
+ )
+ state = fields.Selection([('draft', 'Draft'), ('done', 'Done')], string='State', default='draft', tracking=True)
+ approve_date = fields.Datetime(string='Approve Date', copy=False)
+ approve_by = fields.Many2one('res.users', string='Approve By', copy=False)
+ sale_id = fields.Many2one('sale.order', string='Sale Order')
+
+ @api.onchange('picking_id')
+ def onchange_picking_id(self):
+ if self.picking_id:
+ self.sale_id = self.picking_id.sale_id.id
+
+ def check_invoice_so_picking(self):
+ for rec in self:
+ invoice = self.env['account.move'].search_count([('sale_id', '=', rec.picking_id.sale_id.id)])
+
+ if invoice < 1:
+ raise UserError("Sales Order Belum Memiliki Invoice, Anda Bisa Edit Di DO nya langsung")
+
+ def button_approve(self):
+ if not self.env.user.is_accounting:
+ raise UserError("Hanya Accounting Yang Bisa Approve")
+ self.check_invoice_so_picking
+ self.picking_id.driver_departure_date = self.driver_departure_date
+ self.state = 'done'
+ self.approve_date = datetime.utcnow()
+ self.approve_by = self.env.user.id
+
+ @api.model
+ def create(self, vals):
+ vals['number'] = self.env['ir.sequence'].next_by_code('approval.date.doc') or '0'
+ result = super(ApprovalDateDoc, self).create(vals)
+ return result