Skip to Content
Menu
This question has been flagged
1 Reply
1107 Views

class SaleOrder(models.Model):    _inherit = 'sale.order'        state = fields.Selection(selection_add=[        ('so_hold', 'SO Hold')    ])

    def _action_confirm(self):        """Check if the customer's or their parent's due amount exceeds the available blocking limit."""

        unpaid_invoices = self.env['account.move'].search([            ('partner_id.parent_id', '=', self.partner_id.parent_id.id),            ('state', '=', 'posted'),            ('amount_residual', '>', 0),            ('move_type', 'in', ['out_invoice', 'out_refund'])        ])

        total_unpaid = sum(unpaid_invoices.mapped('amount_residual'))        blocking_limit = self.partner_id.parent_id.blocking_stage        available_credit = blocking_limit - total_unpaid

        _logger.info("blocking_limit: %.2f", blocking_limit)        _logger.info("total_unpaid: %.2f", total_unpaid)        _logger.info("available_credit: %.2f", available_credit)

        if self.partner_id.active_limit and self.partner_id.enable_credit_limit:            to_invoice = self._get_sale_invoice_parent()            required_credit = self.amount_total + to_invoice

            _logger.info("required_credit: %.2f", required_credit)

            if required_credit > available_credit and not self.approval_credit_limit:                _logger.warning("Order exceeds available credit: blocking")                self.over_credit_limit_block = True                self.state = 'so_hold'  # Change state to "so hold"                raise UserError(_(                    "The customer %s is in Blocking Stage. The available credit (%.2f) is not enough to cover the total due "                    "(%.2f).") % (self.partner_id.name, available_credit, required_credit))

        return super(SaleOrder, self)._action_confirm()


I want to change the status, if I click the confirm button then a warning appears then the status changes to SO Hold di odoo 15. I've tried but it doesn't work. can anyone help me...

Avatar
Discard
Best Answer

You can change the button XML view to call a popup as a warning every time the confirm button is clicked in the sale order.

<button name="action_confirm" data-hotkey="v" string="Confirm" type="object" attrs="{'invisible': [('state', 'not in', ['draft'])] }" confirm="ENTER MESSAGE"/>

If you want to call a popup for warning only on a particular condition for the sale order, you can create a wizard for that in which you can just use the popup for warning and close the wizard on the call or OK button.

Avatar
Discard
Related Posts Replies Views Activity
0
Oct 15
4376
1
Mar 15
6157
1
Jan 20
4742
2
Mar 15
6355
1
May 25
896