Skip to content

Commit

Permalink
Merge pull request #560 from ursais/hs_imp_delivery_credit_hold
Browse files Browse the repository at this point in the history
[IMP] Delivery - Credit Hold
  • Loading branch information
agyamuta authored Aug 28, 2023
2 parents 5880822 + 8235459 commit e6fb569
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
18 changes: 13 additions & 5 deletions osi_partner_credit_limit/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
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
14 changes: 8 additions & 6 deletions osi_partner_credit_limit/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit e6fb569

Please sign in to comment.