diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-06-07 11:41:11 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-06-07 11:41:11 +0700 |
| commit | 242bac3811359cdf80954fd3ef82a04a2537410b (patch) | |
| tree | 34846848da473229a848cb834d50a8701dc2bb38 | |
| parent | 48474fcef12509f736be0cb6af47618601dbfe61 (diff) | |
add validation can sell product in sale order
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 735a467c..1bdc7f7d 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -228,7 +228,7 @@ class SaleOrder(models.Model): order.have_outstanding_invoice = False def _have_outstanding_picking(self): - picking_state = ['done', 'confirmed', 'draft', 'cancel'] + picking_state = ['done', 'confirmed', 'draft'] for order in self: if not order.picking_ids: order.have_outstanding_picking = False @@ -309,6 +309,9 @@ class SaleOrder(models.Model): if not order.carrier_id: raise UserError("Shipping Method harus diisi") for line in order.order_line: + # must add product can sell validation + if not line.product_id.product_tmpl_id.sale_ok: + raise UserError('Product ini belum bisa dijual, harap hubungi finance') if not line.product_id or line.product_id.type == 'service': continue if line.product_id.id == 232383: @@ -326,12 +329,15 @@ class SaleOrder(models.Model): def action_cancel(self): # TODO stephan prevent cancel if have invoice, do, and po + if self._name != 'sale.order': + return super(SaleOrder, self).action_cancel() + 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") + 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() @@ -347,6 +353,9 @@ class SaleOrder(models.Model): raise UserError("Shipping Method harus diisi") # approval1 = approval2 = 0 for line in order.order_line: + # must add product can sell validation + if not line.product_id.product_tmpl_id.sale_ok: + raise UserError('Product ini belum bisa dijual, harap hubungi finance') if not line.product_id or line.product_id.type == 'service': continue if line.product_id.id == 232383: @@ -485,15 +494,15 @@ class SaleOrderLine(models.Model): if not self.product_id or self.product_id.type == 'service': return elif self.product_id.categ_id.id == 34: # finish good / manufacturing only - print('a') - bom = self.env['mrp.bom'].search( - [('product_tmpl_id', '=', self.product_id.product_tmpl_id.id)] - , limit=1) - cost = 0 - for line in bom.bom_line_ids: - purchase_price = self.env['purchase.pricelist'].search( - [('vendor_id', '=', self.vendor_id.id), ('product_id', '=', line.product_id.id)], limit=1) - cost += purchase_price.product_price + # bom = self.env['mrp.bom'].search( + # [('product_tmpl_id', '=', self.product_id.product_tmpl_id.id)] + # , limit=1) + # cost = 0 + # for line in bom.bom_line_ids: + # purchase_price = self.env['purchase.pricelist'].search( + # [('vendor_id', '=', self.vendor_id.id), ('product_id', '=', line.product_id.id)], limit=1) + # cost += purchase_price.product_price + cost = self.product_id.standard_price self.purchase_price = cost else: purchase_price = self.env['purchase.pricelist'].search( |
