summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/approval_date_doc.py
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-08-14 16:12:14 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-08-14 16:12:14 +0700
commitd47eb069978ce67bce1a19b6c824a53ca3d68801 (patch)
tree2427f680d68c8b136531d392eb36cf4262c7d35b /indoteknik_custom/models/approval_date_doc.py
parent2513b765773fca587dbd298e77732d2d005949c8 (diff)
parentd4df708e5195e1c0c3b8e0ad90b7518e5d4d48c2 (diff)
<iman> Merge branch 'production' of https://bitbucket.org/altafixco/indoteknik-addons into feature/tracking-order
# Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
Diffstat (limited to 'indoteknik_custom/models/approval_date_doc.py')
-rw-r--r--indoteknik_custom/models/approval_date_doc.py49
1 files changed, 49 insertions, 0 deletions
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