콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
1428 화면

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

아바타
취소
베스트 답변

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.

아바타
취소
관련 게시물 답글 화면 활동
0
10월 15
4694
1
3월 15
6668
1
1월 20
5184
2
3월 15
6831
1
5월 25
1365