summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2024-03-12 04:56:55 +0000
committerIT Fixcomart <it@fixcomart.co.id>2024-03-12 04:56:55 +0000
commitf43c76e2e7fb1a2e46f6e698afb1da74961cad50 (patch)
tree18b80d3d6dd74022f01d0663d4a349be6c662193 /indoteknik_custom/models
parent41056a3fcf9cf80ac3609ab32223ffbac5b3ad83 (diff)
parentb7b71be97a73f454f2df9fd9a37f5017c82192ae (diff)
Merged in feature/web-sale-approval (pull request #136)
Feature/web sale approval
Diffstat (limited to 'indoteknik_custom/models')
-rw-r--r--indoteknik_custom/models/res_partner.py15
-rwxr-xr-xindoteknik_custom/models/sale_order.py33
2 files changed, 47 insertions, 1 deletions
diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py
index a7302245..467d3be9 100644
--- a/indoteknik_custom/models/res_partner.py
+++ b/indoteknik_custom/models/res_partner.py
@@ -23,6 +23,12 @@ class ResPartner(models.Model):
digital_invoice_tax = fields.Boolean(string="Digital Invoice & Faktur Pajak")
is_potential = fields.Boolean(string='Potential')
pakta_integritas = fields.Boolean(string='Pakta Integritas')
+
+ use_so_approval = fields.Boolean(string='Use SO Approval')
+ web_role = fields.Selection([
+ ('manager', 'Manager'),
+ ('director', 'Director')
+ ], string='Web Role')
def get_child_ids(self):
partner = self.env['res.partner'].search([('id', '=', self.id)], limit=1)
@@ -31,6 +37,15 @@ class ResPartner(models.Model):
partner_child_ids += [x['id'] for x in partner.parent_id.child_ids]
partner_child_ids += [partner.parent_id.id]
return partner_child_ids
+
+ def get_approve_partner_ids(self, type=False):
+ parent = self.parent_id or self
+ partners = self.search([('parent_id', '=', parent.id), ('web_role', 'in', ['manager', 'director'])])
+
+ if type == 'email_comma_sep':
+ return ",".join([x.email for x in partners])
+
+ return partners
@api.constrains('kota_id')
def update_product_solr_flag(self):
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'},
+ }
+ }