Hello I am modifying the stock.picking view form by adding the pre-existing sale_id field, which will link the picking form to a sale order. When I add or change products in the Operations field and click save the Sale_id field is emptied and the link to the sale order is removed. I was wondering if anyone could help me locate which function in StockMove or StockPicking does this so I can override it. I am using Odoo v14.
This is my code if anyone wants to try:
from odoo import models, fields, api
from odoo.exceptions import ValidationError
class StockPickingInherit(models.Model):
_inherit = "stock.picking"
@api.onchange('partner_id')
def onchange_partner_id(self):
return {'domain': {'sale_id': [('partner_id', 'in', self.get_partner_ids())]}}
def get_partner_ids(self):
res = []
root_id = self.partner_id
if self.partner_id.parent_id.id != False:
root_id = self.partner_id.parent_id
res.append(root_id.id)
for child_id in root_id.child_ids:
res.append(child_id.id)
return res
"id="stock_picking_form_view_inherit" model="ir.ui.view">
name="name">stock.picking.form.view.inherit
name="model">stock.picking
name="inherit_id" ref="stock.view_picking_form"/>
name="arch" type="xml">
name="origin" position="after">
name="sale_id"/>
name="product_uom_qty" position="attributes">
name="invisible">0
"