beriliox
beriliox

Reputation: 267

How to display the value of a field only when the Save button is pressed in Odoo?

I have a computed field that generates a sequence when a product selects . But I don't want the sequence to be generated at the time that the product to Form view is added. What I want is that only the value is added to the sequence when the Save button is pressed the header .

Is it possible to do that?

Is there any way to validate a field if a button is pressed or not?

The following image shows that when I add an element to the form , the sequence is created. But I want the sequence is created only when the save button is pressed.

Image: http://es.zimagez.com/zimage/image1d001867bb69d2ffa90c65209e81976cc.php

And this is the field and function. But only the sequence is generated when the save button is pressed:

  niu = fields.Char(string="NIU", compute="_niu_validation", readonly=True, store=True)

    @api.depends('product_id.product_tmpl_id.type')
    def _niu_validation(self):
        for recordset in self:
            if rec.product_id.product_tmpl_id.type == 'product' and not rec.niu:
                    rec.niu = self.env['ir.sequence'].next_by_code('sale.order.line')

I hope you understand what I really mean.

Thanks for all.

Upvotes: 0

Views: 720

Answers (2)

Charif DZ
Charif DZ

Reputation: 14751

i think i'am late but if you don't want to show any field in view when the user is still editing give it class="oe_readonly".

Upvotes: 0

Obj3ctiv3_C_88
Obj3ctiv3_C_88

Reputation: 1528

That would be something better suited to jquery and very simple. First, either within the css or on the element itself set display=none. Then within a script add this:

$('#save_button).click(function(this){
    $(this).preventdefault();
    $('#thing_youre_hiding').toggle();
    $(this).submit();
});

Upvotes: 0

Related Questions