# Check if the value of reference field is -1

**URL:** https://discuss.tryton.org/t/check-if-the-value-of-reference-field-is-1/1402
**Category:** Developer
**Created:** [May 20, 2019, 5:02pm UTC](https://discuss.tryton.org/t/check-if-the-value-of-reference-field-is-1/1402 "2019-05-20T17:02:30Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![iehoshia](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/iehoshia/32/243_2.png) [@iehoshia](https://discuss.tryton.org/u/iehoshia)
#### Post date: [May 20, 2019, 5:02pm UTC](https://discuss.tryton.org/t/check-if-the-value-of-reference-field-is-1/1402/1 "2019-05-20T17:02:30Z")

</div>

Hi,

I was a common issue with reference field, specially with origin of account.move. When only the model is filled but not the record, tryton stores it as -1. Is there a way to validate a field before to save making the model and record required?

 ![image](https://discuss-cdn.tryton.org/uploads/default/original/1X/7a4c12dc07e5b0c0c3ac7b79b33873e67ae7b5f9.png)

Thanks in advance!

---

<div class="post-metadata">

### Author: ![mono](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/mono/32/289_2.png) [@mono](https://discuss.tryton.org/u/mono)
#### Post date: [May 20, 2019, 5:54pm UTC](https://discuss.tryton.org/t/check-if-the-value-of-reference-field-is-1/1402/2 "2019-05-20T17:54:21Z")

</div>

> [@iehoshia](#):
>
> Is there a way to validate a field before to save

- On client:  
[http://docs.tryton.org/projects/server/en/latest/ref/models/models.html#trytond.model.Model.pre\_validate](http://docs.tryton.org/projects/server/en/latest/ref/models/models.html#trytond.model.Model.pre_validate)
- overwrite model **write** method. A example:  
[http://hg.tryton.org/modules/party/file/tip/contact\_mechanism.py#l231](http://hg.tryton.org/modules/party/file/tip/contact_mechanism.py#l231)

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [May 20, 2019, 8:33pm UTC](https://discuss.tryton.org/t/check-if-the-value-of-reference-field-is-1/1402/3 "2019-05-20T20:33:54Z")

</div>

> [@iehoshia](#):
>
> Is there a way to validate a field before to save making the model and record required?

Required works as you would expect [http://hg.tryton.org/trytond/rev/a6ba95b555c3](http://hg.tryton.org/trytond/rev/a6ba95b555c3)

---

<div class="post-metadata">

### Author: ![iehoshia](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/iehoshia/32/243_2.png) [@iehoshia](https://discuss.tryton.org/u/iehoshia)
#### Post date: [May 20, 2019, 9:05pm UTC](https://discuss.tryton.org/t/check-if-the-value-of-reference-field-is-1/1402/4 "2019-05-20T21:05:19Z")

</div>

> [@ced](#):
>
> Required works as you would expect

I would expect that if I modify model I require to add a record, but at the moment I can only edit the model without the need to add a record.

---

<div class="post-metadata">

### Author: ![iehoshia](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/iehoshia/32/243_2.png) [@iehoshia](https://discuss.tryton.org/u/iehoshia)
#### Post date: [May 20, 2019, 9:06pm UTC](https://discuss.tryton.org/t/check-if-the-value-of-reference-field-is-1/1402/5 "2019-05-20T21:06:02Z")

</div>

I found a working example in [sale\_advance\_payment/sale.py at f7ef932d3f274b988f4dedb8e727fc17b21b8e2f · tryton/sale\_advance\_payment · GitHub](https://github.com/tryton/sale_advance_payment/blob/f7ef932d3f274b988f4dedb8e727fc17b21b8e2f/sale.py#L87)

I will try with it.

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [May 21, 2019, 7:45am UTC](https://discuss.tryton.org/t/check-if-the-value-of-reference-field-is-1/1402/6 "2019-05-21T07:45:04Z")

</div>

> [@iehoshia](#):
>
> I would expect that if I modify model I require to add a record

Only if the field is required.
