Skip to Content
Menu
This question has been flagged
2 Replies
3416 Views

Hi,


In the sale order form, i want to have a specific field for the customer sale number. By default, this field should be filled with the Odoo sale number, generated after press on the record button. But if a value is specified manually, i don't want to copy the Odoo sale number.

So this is my current code :

<field name="pricelist_id" position="after">    
    <field name="customer_sale_number" readonly="0" />
</field>
--
@api.one@api.depends('name')
def compute_default_customer_sale_number(self):
    if self.customer_sale_number == '/' or self.customer_sale_number is False:
        self.customer_sale_number = self.name

customer_sale_number = fields.Char('Customer reference', compute='compute_default_customer_sale_number', store=True)

This code works but if a value is specified manually, it is overwritten by the Odoo sale number.

Where is my mistake ?

Avatar
Discard
Best Answer

1) Default field value is defined as ... fields.Char(  default=

2) In this case it is impossible.  With your solution the value is not default but always computed. 

3)  compute_default_customer_sale_number is triggered when ... depends('name')  ... so if any of the change is made in the name, in next step value self.customer_sale_number  is calculated,  but ... at this point, what the value of self.customer_sale_number???  (is stored now with new value or no? you enable _logger an verify the value)

4)  Probably for you is better to use @api.onchange and not computed field.

Avatar
Discard
Author Best Answer

Thank you Zbik.

I will try with a standard field (with non compute...) and with @api.onchange.

Avatar
Discard
Related Posts Replies Views Activity
0
Jul 24
192
2
Dec 22
12868
1
Nov 21
3145
0
Jan 21
1072
8
May 20
6252