0
votes

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 ?

1

1 Answers

0
votes

You can try it by replacing the following code to solve your problem.

@api.one
@api.depends('name')
def compute_default_customer_sale_number(self):
    self.customer_sale_number = self.customer_sale_number or self.name

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

Thanks