[FIX] Move some field from onchange to compute fields to avoid issues in views

This commit is contained in:
Florian da Costa
2022-12-01 17:23:25 +01:00
parent e9fdac75d3
commit 71df4774e8
2 changed files with 25 additions and 4 deletions

View File

@@ -301,6 +301,9 @@ class RmaOrderLine(models.Model):
string="Unit of Measure", string="Unit of Measure",
required=True, required=True,
readonly=True, readonly=True,
compute="_compute_uom_id",
precompute=True,
store=True,
states={"draft": [("readonly", False)]}, states={"draft": [("readonly", False)]},
) )
price_unit = fields.Monetary( price_unit = fields.Monetary(
@@ -377,6 +380,9 @@ class RmaOrderLine(models.Model):
required=True, required=True,
domain=[("rma_selectable", "=", True)], domain=[("rma_selectable", "=", True)],
readonly=True, readonly=True,
compute="_compute_in_route_id",
precompute=True,
store=True,
states={"draft": [("readonly", False)]}, states={"draft": [("readonly", False)]},
) )
out_route_id = fields.Many2one( out_route_id = fields.Many2one(
@@ -385,6 +391,9 @@ class RmaOrderLine(models.Model):
required=True, required=True,
domain=[("rma_selectable", "=", True)], domain=[("rma_selectable", "=", True)],
readonly=True, readonly=True,
compute="_compute_out_route_id",
precompute=True,
store=True,
states={"draft": [("readonly", False)]}, states={"draft": [("readonly", False)]},
) )
in_warehouse_id = fields.Many2one( in_warehouse_id = fields.Many2one(
@@ -688,10 +697,18 @@ class RmaOrderLine(models.Model):
) )
self.customer_to_supplier = self.operation_id.customer_to_supplier self.customer_to_supplier = self.operation_id.customer_to_supplier
self.supplier_to_customer = self.operation_id.supplier_to_customer self.supplier_to_customer = self.operation_id.supplier_to_customer
self.in_route_id = self.operation_id.in_route_id
self.out_route_id = self.operation_id.out_route_id
return result return result
@api.depends("operation_id")
def _compute_in_route_id(self):
for rec in self:
rec.in_route_id = rec.operation_id.in_route_id
@api.depends("operation_id")
def _compute_out_route_id(self):
for rec in self:
rec.out_route_id = rec.operation_id.out_route_id
@api.onchange("customer_to_supplier", "type") @api.onchange("customer_to_supplier", "type")
def _onchange_receipt_policy(self): def _onchange_receipt_policy(self):
if self.type == "supplier" and self.customer_to_supplier: if self.type == "supplier" and self.customer_to_supplier:
@@ -704,7 +721,12 @@ class RmaOrderLine(models.Model):
product = self.lot_id.product_id product = self.lot_id.product_id
if product: if product:
self.product_id = product self.product_id = product
self.uom_id = product.uom_id
@api.depends("product_id")
def _compute_uom_id(self):
for rec in self:
if rec.product_id:
rec.uom_id = rec.product_id.uom_id
def action_view_in_shipments(self): def action_view_in_shipments(self):
action = self.env.ref("stock.action_picking_tree_all") action = self.env.ref("stock.action_picking_tree_all")

View File

@@ -95,7 +95,6 @@
name="partner_id" name="partner_id"
context="{'res_partner_search_mode': 'customer'}" context="{'res_partner_search_mode': 'customer'}"
string="Customer" string="Customer"
colspan="4"
/> />
<field <field
name="date_rma" name="date_rma"