diff options
Diffstat (limited to 'indoteknik_custom/models/sale_order.py')
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 759329b0..b7578da0 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -88,6 +88,11 @@ class SaleOrder(models.Model): picking_iu_id = fields.Many2one('stock.picking', 'Picking IU') helper_by_id = fields.Many2one('res.users', 'Helper By') eta_date = fields.Datetime(string='ETA Date', copy=False, compute='_compute_eta_date') + web_approval = fields.Selection([ + ('company', 'Company'), + ('cust_manager', 'Customer Manager'), + ('cust_director', 'Customer Director') + ], string='Web Approval', copy=False) def _compute_eta_date(self): max_leadtime = 0 @@ -445,6 +450,13 @@ class SaleOrder(models.Model): order._validate_order() order.order_line.validate_line() + main_parent = order.partner_id.get_main_parent() + SYSTEM_UID = 25 + FROM_WEBSITE = order.create_uid.id == SYSTEM_UID + + if FROM_WEBSITE and main_parent.use_so_approval and order.web_approval != 'cust_director': + raise UserError("This order not yet approved by customer director") + if order.validate_partner_invoice_due(): return self._create_notification_action('Notification', 'Terdapat invoice yang telah melewati batas waktu, mohon perbarui pada dokumen Due Extension') @@ -472,6 +484,9 @@ class SaleOrder(models.Model): raise UserError("Invoice harus di Cancel dahulu") elif self.have_outstanding_picking: raise UserError("DO harus di Cancel dahulu") + + if not self.web_approval: + self.web_approval = 'company' # elif self.have_outstanding_po: # raise UserError("PO harus di Cancel dahulu") @@ -631,7 +646,23 @@ class SaleOrder(models.Model): line.discount = line.initial_discount line.initial_discount = False - + def action_web_approve(self): + if self.env.uid != self.partner_id.user_id.id: + raise UserError('You are not authorized to approve this order. Only %s can approve this order.' % self.partner_id.user_id.name) + + self.web_approval = 'company' + template = self.env.ref('indoteknik_custom.mail_template_sale_order_web_approve_notification') + template.send_mail(self.id, force_send=True) + + return { + 'type': 'ir.actions.client', + 'tag': 'display_notification', + 'params': { + 'title': 'Notification', + 'message': 'Berhasil approve web order', + 'next': {'type': 'ir.actions.act_window_close'}, + } + } |
