Skip to Content
Menu
This question has been flagged
1 Reply
4898 Views

Here is the case: I made a module so that inputted Sale Order can only be -3 days or +3 days from `datetime.datetime.now()`. On another module, I need to make a code that can only be ran in certain date in Sale Order. Let say, I need to have function `x()` to be ran on 2020-01-01 - 2020-01-02. On the mentioned date, it returns `1` otherwise it returns `0`.

In the unit test, to by pass the limitation made by the first module, I directly edit using SQL query:

```
self.env.cr.execute('UPDATE sale_order SET x_custom_date=%s WHERE id=%s;', ('2020-01-01 00:00:00', sale_order.id, ) )
```

I used to have the `x_custom_date` field changed according to the SQL query. But now, the SQL query does nothing.

Last time it works even without `self.env.commit()`. But now even `self.env.commit()` does not change the value of the `x_custom_date`.

Can someone point out any possible mistakes? The goal is to use `self.env.commit()` in unit test without commiting and change the mentioned value within the transaction.

Avatar
Discard
Author Best Answer

Got it done with:

```
self.env.cr.execute( 'UPDATE sale_order_line SET create_date=%s WHERE id=%s;', ( '2019-11-08 00:00:00', sale_order_line.id, ) ) sale_order.write({})
```

`sale_order.write({})` ---> This is the most important part.

Avatar
Discard
Related Posts Replies Views Activity
2
May 24
347
6
Dec 23
39580
0
Dec 15
3099
0
May 20
1999
1
Jul 19
4239