diff options
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 30 | ||||
| -rwxr-xr-x | indoteknik_custom/views/sale_order.xml | 1 |
2 files changed, 29 insertions, 2 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 5c9266a0..4768f31c 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -71,6 +71,7 @@ class SaleOrder(models.Model): date_doc_kirim = fields.Datetime(string='Tanggal Kirim di SJ', help="Tanggal Kirim di cetakan SJ yang terakhir, tidak berpengaruh ke Accounting") payment_type = fields.Char(string='Payment Type', help='Jenis pembayaran dengan Midtrans') gross_amount = fields.Float(string='Gross Amount', help='Jumlah pembayaran yang dilakukan dengan Midtrans') + notification = fields.Char(string='Notification', help='Dapat membantu error dari approval') @api.model def _generate_so_access_token(self, limit=50): @@ -195,7 +196,6 @@ class SaleOrder(models.Model): def check_due(self): """To show the due amount and warning stage""" for order in self: - # partner_id = 0aku if order.partner_id.parent_id: partner_id = order.partner_id.parent_id else: @@ -255,7 +255,9 @@ class SaleOrder(models.Model): raise UserError(_('Isi Vendor dan Harga Beli sebelum Request Approval')) if order.total_percent_margin <= 15 and not self.env.user.is_leader: order.approval_status = 'pengajuan2' - elif order.total_percent_margin <= 25 and not self.env.user.is_leader and not self.env.user.is_sales_manager: + elif order.total_percent_margin <= 22 and not self.env.user.is_leader and not self.env.user.is_sales_manager: + order.approval_status = 'pengajuan1' + elif order._have_outstanding_invoices() and not self.env.user.is_leader and not self.env.user.is_sales_manager: order.approval_status = 'pengajuan1' else: raise UserError("Bisa langsung Confirm") @@ -293,12 +295,36 @@ class SaleOrder(models.Model): raise UserError("Harus diapprove oleh Pimpinan") elif order.total_percent_margin <= 22 and not self.env.user.is_leader and not self.env.user.is_sales_manager: raise UserError("Harus diapprove oleh Manager") + elif order._have_outstanding_invoices() and not self.env.user.is_leader and not self.env.user.is_sales_manager: + raise UserError("Ada invoice due date, harus diapprove oleh Manager") else: order.approval_status = 'approved' order.calculate_line_no() return res + def _have_outstanding_invoices(self): + partner_id = self.partner_id + if self.partner_id.parent_id: + partner_id = self.partner_id + partners = [] + partners += partner_id.child_ids + partners.append(partner_id) + for partner in partners: + query = [ + ('partner_id', '=', partner.id), + ('state', '=', 'posted'), + ('move_type', '=', 'out_invoice'), + ('amount_residual_signed', '>', 0) + ] + invoices = self.env['account.move'].search(query) + for invoice in invoices: + if invoice.invoice_day_to_due < 0: + self.notification = 'Ada %s yang sudah jatuh tempo dan belum lunas' % invoice.name + # self.env.cr.commit() + return True + + def compute_total_margin(self): for order in self: total_margin = total_percent_margin = 0 diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 203b2d13..a1120137 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -33,6 +33,7 @@ </field> <field name="source_id" position="after"> <field name="date_doc_kirim" readonly="1"/> + <field name="notification" readonly="1"/> </field> <xpath expr="//form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='price_unit']" position="attributes"> <attribute name="attrs"> |
