İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
1222 Görünümler

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
Vazgeç
En İyi Yanıt

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
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
0
Eki 15
4483
1
Mar 15
6391
1
Oca 20
4953
2
Mar 15
6564
1
May 25
1067