Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sale.Order readonly boolean field #107

Open
Attila-Alz opened this issue Nov 7, 2024 · 0 comments
Open

Sale.Order readonly boolean field #107

Attila-Alz opened this issue Nov 7, 2024 · 0 comments

Comments

@Attila-Alz
Copy link

Hello,

I have a non stored, computed field "is_expired" which is also readonly by default when the model is generated. So I get the error "{Odoo Server Error, 'sale.order' object attribute 'is_expired' is read-only}".
Adding "readonly=True" in order.sale.py doesn't solve this problem, it does however change the summary text to ReadOnly: False when generating the model again.

...
            //var tableName = "sale.order";
            //var modelResult = await odooClient.GetModelAsync(tableName);
            //var model = OdooModelMapper.GetDotNetModel(tableName, modelResult.Value);

            var saleOrderRepository = new OdooRepository<SaleOrderOdooModel>(config);
            var saleOrders = await saleOrderRepository.Query()
                .Where(x=>x.OrderNumber, OdooOperator.EqualsTo, orderNumber)
                .ToListAsync();
...

C# Model (generated):

...
        /// <summary>
        /// is_expired - boolean  <br />
        /// Required: False, Readonly: True, Store: False, Sortable: False <br />
        /// </summary>
        [JsonProperty("is_expired")]
        public bool? IsExpired { get; set; }
...

Odoo sale_order.py file:

...
is_expired = fields.Boolean(string="Is Expired", compute='_compute_is_expired') **//Adding readonly=True doesn't solve the problem**
...
def _compute_is_expired(self):
    today = fields.Date.today()
    for order in self:
        order.is_expired = order.state == 'sent' and order.validity_date and order.validity_date < today
...

How can I make this work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant