summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-10-14 21:36:32 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-10-14 21:36:32 +0700
commit8685a05ab59c53dfaf3ab70798b1d5abb5c0bdaf (patch)
tree3dfe16c621f3e4330dbd6dadc8870599a4a3519c
parentdf06e1a954db64dffecf732deb2548acf28dccc3 (diff)
add so cancel validation if have invoice, do, or po
-rwxr-xr-xindoteknik_custom/models/sale_order.py79
1 files changed, 64 insertions, 15 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 00574bd8..a366881d 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -32,6 +32,52 @@ class SaleOrder(models.Model):
], string='Shipping Paid by', help='Siapa yang talangin dulu Biaya ekspedisi-nya?', copy=False)
sales_tax_id = fields.Many2one('account.tax', string='Tax',
domain=['|', ('active', '=', False), ('active', '=', True)])
+ have_outstanding_invoice = fields.Boolean('Have Outstanding Invoice', compute='_have_outstanding_invoice')
+ have_outstanding_picking = fields.Boolean('Have Outstanding Picking', compute='_have_outstanding_picking')
+ have_outstanding_po = fields.Boolean('Have Outstanding PO', compute='_have_outstanding_po')
+ purchase_ids = fields.Many2many('purchase.order', string='Purchases', compute='_get_purchases')
+
+ def _get_purchases(self):
+ po_state = ['done', 'draft', 'purchase']
+ for order in self:
+ purchases = self.env['purchase.order'].search([
+ ('sale_order_id', '=', order.id),
+ ('state', 'in', po_state)
+ ])
+ order.purchase_ids = purchases
+
+ def _have_outstanding_invoice(self):
+ invoice_state = ['posted', 'draft']
+ for order in self:
+ if not order.invoice_ids:
+ order.have_outstanding_invoice = False
+ for invoice in order.invoice_ids:
+ if invoice.state in invoice_state:
+ order.have_outstanding_invoice = True
+ else:
+ order.have_outstanding_invoice = False
+
+ def _have_outstanding_picking(self):
+ picking_state = ['done', 'confirmed', 'draft', 'cancel']
+ for order in self:
+ if not order.picking_ids:
+ order.have_outstanding_picking = False
+ for picking in order.picking_ids:
+ if picking in picking_state:
+ order.have_outstanding_picking = True
+ else:
+ order.have_outstanding_picking = False
+
+ def _have_outstanding_po(self):
+ po_state = ['done', 'draft', 'purchase']
+ for order in self:
+ if not order.purchase_ids:
+ order.have_outstanding_po = False
+ for purchase in order.purchase_ids:
+ if purchase.state in po_state:
+ order.have_outstanding_po = True
+ else:
+ order.have_outstanding_po = False
def _compute_have_visit_service(self):
limit = 20000000
@@ -44,16 +90,20 @@ class SaleOrder(models.Model):
for order in self:
if order.state == 'cancel' or order.state == 'done' or order.state == 'sale':
raise UserError("Status harus draft atau sent")
- # if not order.partner_id.property_payment_term_id:
- # raise UserError("Payment Term pada Master Data Customer harus diisi")
- # TODO must look credit limit and payment term parent partner
- # if not order.partner_id.active_limit:
- # raise UserError("Credit Limit pada Master Data Customer harus diisi")
+ if order.partner_id.parent_id:
+ if not order.partner_id.parent_id.property_payment_term_id:
+ raise UserError("Payment Term pada Master Data Customer harus diisi")
+ if not order.partner_id.parent_id.active_limit:
+ raise UserError("Credit Limit pada Master Data Customer harus diisi")
+ else:
+ if not order.partner_id.property_payment_term_id:
+ raise UserError("Payment Term pada Master Data Customer harus diisi")
+ if not order.partner_id.active_limit:
+ raise UserError("Credit Limit pada Master Data Customer harus diisi")
if not order.sales_tax_id:
raise UserError("Tax di Header harus diisi")
if not order.carrier_id:
raise UserError("Shipping Method harus diisi")
- # approval1 = approval2 = 0
for line in order.order_line:
if not line.product_id or line.product_id.type == 'service':
continue
@@ -69,6 +119,14 @@ class SaleOrder(models.Model):
raise UserError("Bisa langsung Confirm")
def action_cancel(self):
+ # TODO stephan prevent cancel if have invoice, do, and po
+ if self.have_outstanding_invoice:
+ raise UserError("Invoice harus di Cancel dahulu")
+ elif self.have_outstanding_picking:
+ raise UserError("DO harus di Cancel dahulu")
+ elif self.have_outstanding_po:
+ raise UserError("PO harus di Cancel dahulu")
+
self.approval_status = False
return super(SaleOrder, self).action_cancel()
@@ -87,15 +145,6 @@ class SaleOrder(models.Model):
raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara'))
if not line.vendor_id or not line.purchase_price or not line.purchase_tax_id:
raise UserError(_('Isi Vendor, Harga Beli, dan Tax sebelum Request Approval'))
- # if line.item_percent_margin <= 15 and not self.env.user.is_leader:
- # approval2 += 1
- # elif line.item_percent_margin <= 25 and not self.env.user.is_leader and not self.env.user.is_sales_manager:
- # approval1 += 1
- # if approval2 > 0:
- # raise UserError("Harus diapprove oleh Pimpinan")
- # elif approval1 > 0:
- # raise UserError("Harus diapprove oleh Manager")
- # order.approval_status = 'approved'
if order.total_percent_margin <= 15 and not self.env.user.is_leader:
raise UserError("Harus diapprove oleh Pimpinan")
elif order.total_percent_margin <= 25 and not self.env.user.is_leader and not self.env.user.is_sales_manager: