Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ

Is there a way to block the edition of quality checks once they have been filled?


We use quality controls using both spreadsheets and worksheets. 

We would like to block them after the information has been filled, to avoid any type of changes.

Is there a way to do this?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

By default in Odoo Quality, a quality.check record stays editable even after it has a result (Pass/Fail) or worksheet data. Odoo doesn’t automatically lock them. 

3 ways:

1. Security Group:

You can create a record rule that prevents write access on quality.check once certain conditions are met.

Example condition: only allow editing if quality_state = 'none' (not yet processed).

<record id="rule_quality_check_no_edit_done" model="ir.rule">

    <field name="name">No edit on done quality checks</field>

    <field name="model_id" ref="quality_control.model_quality_check"/>

    <field name="groups" eval="[(4, ref('quality_control.group_quality_user'))]"/>

    <field name="domain_force">[('quality_state', '!=', 'none')]</field>

    <field name="perm_read" eval="True"/>

    <field name="perm_write" eval="False"/>

    <field name="perm_create" eval="True"/>

    <field name="perm_unlink" eval="False"/>

</record>


Or

2. Python Code

Override the write method in a custom module, and raise an error if someone tries to edit a filled check:

from odoo import models, exceptions, _


class QualityCheck(models.Model):

    _inherit = "quality.check"


    def write(self, vals):

        for rec in self:

            if rec.quality_state != 'none':  # already processed

                raise exceptions.UserError(

                    _("You cannot modify a quality check once it has been filled.")

                )

        return super().write(vals)


Or

3. View Customization

You can make the form view read-only once filled by using a domain in Readonly:

<field name="quality_state" readonly="quality_state != 'none'"/>



Hope it helps.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 8 25
545
2
thg 2 25
53
0
thg 10 23
1628
2
thg 12 19
5514
0
thg 3 15
4847