Skip to content

Commit

Permalink
[FIX] sale: correctly send field data
Browse files Browse the repository at this point in the history
Since f0beddf, the crud rights of
readonly fields is not sent to the client anymore.

In most cases, it has no impact, but for fields readonly server-side
and specified as editable in the xml, the client will consider
relational fields as always creatable and writable.

See:
* many2one_field.js where canCreate and canWrite are undefined in this
situation because the server doesn't send the crud data.

* owl library, where undefined props fallback on the default props
value, which is true for Many2OneField canCreate and canWrite.

After investigation, it has been concluded that modifying the data sent
to the client was too heavy for such a rare usecase that we don't want
to support anymore.

This commit fixes the only know case where a readonly field was supposed
to be editable client side, by converting it to a compute editable,
s.t. the server doesn't consider it as a readonly field and correctly
sends all the necessary information to the client for this field.

It also allows users to disable product templates creation & update in
the lines of a Sales Order (and makes sure that if it's enabled, you have
the creation/edit rights to see 'Create' & 'Create & Edit' dropdown choices).

opw-3144319
opw-3140988
opw-3080838

closes #111506

Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
  • Loading branch information
Feyensv committed Jan 31, 2023
1 parent 1d47c3c commit dbc56c6
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion addons/sale/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ class SaleOrderLine(models.Model):
domain="[('sale_ok', '=', True), '|', ('company_id', '=', False), ('company_id', '=', company_id)]")
product_template_id = fields.Many2one(
string="Product Template",
related='product_id.product_tmpl_id',
comodel_name='product.template',
compute='_compute_product_template_id',
readonly=False,
search='_search_product_template_id',
# previously related='product_id.product_tmpl_id'
# not anymore since the field must be considered editable for product configurator logic
# without modifying the related product_id when updated.
domain=[('sale_ok', '=', True)])
product_uom_category_id = fields.Many2one(related='product_id.uom_id.category_id', depends=['product_id'])

Expand Down Expand Up @@ -259,6 +265,14 @@ class SaleOrderLine(models.Model):

#=== COMPUTE METHODS ===#

@api.depends('product_id')
def _compute_product_template_id(self):
for line in self:
line.product_template_id = line.product_id.product_tmpl_id

def _search_product_template_id(self, operator, value):
return [('product_id.product_tmpl_id', operator, value)]

@api.depends('product_id')
def _compute_custom_attribute_values(self):
for line in self:
Expand Down

0 comments on commit dbc56c6

Please sign in to comment.