From 8235459183024c9c4d781b6bfbe888f18e6a38d5 Mon Sep 17 00:00:00 2001 From: Hardik Suthar Date: Mon, 28 Aug 2023 17:26:19 +0530 Subject: [PATCH] [IMP] Delivery - Credit Hold --- osi_partner_credit_limit/models/sale_order.py | 18 +++++++++++++----- .../models/stock_picking.py | 14 ++++++++------ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/osi_partner_credit_limit/models/sale_order.py b/osi_partner_credit_limit/models/sale_order.py index 0301ebc19..3ae5a0b32 100644 --- a/osi_partner_credit_limit/models/sale_order.py +++ b/osi_partner_credit_limit/models/sale_order.py @@ -43,9 +43,9 @@ def action_confirm(self): message = _("""Cannot confirm Order! The customer is on sales hold.""") # Display that the customer is on sales hold raise ValidationError(message) - elif self.ship_hold and not self.credit_override: + elif not self.credit_override and self.partner_id.with_context(from_sale_order=True).check_limit(self): message = _( - """Cannot confirm Order! \nThe customer exceed available credit limit and is on ship hold.""" + """The customer exceeds the available credit limit. Cannot confirm Sales Order""" ) raise ValidationError(message) else: @@ -60,12 +60,20 @@ def action_confirm(self): self.state = prev_state self.ship_hold = True message = _( - """Cannot confirm Order! \nThis will exceed allowed Credit Limit. - \nTo Override, check Override Sales/Credit/Delivery Hold""" + """The customer exceeds the available credit limit. Cannot confirm Sales Order.""" ) raise ValidationError(message) return super(SaleOrder, self).action_confirm() def write(self, vals): vals.update({"ship_hold": self.partner_id.ship_hold}) - return super(SaleOrder, self).write(vals) \ No newline at end of file + return super(SaleOrder, self).write(vals) + + def create(self, vals): + res = super(SaleOrder, self).create(vals) + if res.partner_id.ship_hold: + res.ship_hold = self.partner_id.ship_hold + if res.partner_id.sales_hold and not res.credit_override: + message = _("""Cannot confirm Order! The customer is on sales hold.""") + raise ValidationError(message) + return res diff --git a/osi_partner_credit_limit/models/stock_picking.py b/osi_partner_credit_limit/models/stock_picking.py index f57b441df..089211fcc 100644 --- a/osi_partner_credit_limit/models/stock_picking.py +++ b/osi_partner_credit_limit/models/stock_picking.py @@ -19,18 +19,22 @@ def _compute_allow_transfer(self): "cancel", ): # Sales person has a hold + if ( record.sale_id.sales_hold or record.sale_id.credit_hold - or record.sale_id.ship_hold or record.partner_id.ship_hold + or record.sale_id.ship_hold ): hold_value = True - # Partner will exceed limit with current # Sale order or is over-due if record.sale_id.partner_id.check_limit(record.sale_id): hold_value = True + # Override applied on Ship Hold on Partner Change + if not record.partner_id.ship_hold: + hold_value = False + # Override applied on sale order if record.sale_id.credit_override: hold_value = False @@ -44,13 +48,11 @@ def _compute_allow_transfer(self): def button_validate(self): # Only outgoing picking - if self.picking_type_code == "outgoing" and self.partner_id.ship_hold: + if self.picking_type_code == "outgoing": if self.dont_allow_transfer: raise UserError( _( - """Customer has a Credit hold.\n\nContact - Sales/Accounting to verify - sales hold/credit hold/overdue payments.""" + """Customer has a delivery hold. Please contact Accounting.""" ) ) else: