Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
1404 Lượt xem

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...

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhấ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.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 10 15
4668
1
thg 3 15
6649
1
thg 1 20
5152
2
thg 3 15
6784
1
thg 5 25
1315