from odoo import api, fields, _, models class saleOrder(models.Model): _inherit = 'sale.order' warehouse_location_id = fields.Many2one('stock.location', related="warehouse_id.lot_stock_id", store=True) vehicle_no = fields.Char(string="Vehicle No") landed_cost_ids = fields.Many2many('stock.landed.cost', compute="_compute_landed_cost_ids") @api.depends('picking_ids') def _compute_landed_cost_ids(self): for rec in self: if rec.picking_ids: rec.landed_cost_ids = self.env['stock.landed.cost'].sudo().search([('picking_ids','in',rec.picking_ids.ids)]).ids else: rec.landed_cost_ids = False def action_open_landing_cost(self): for rec in self: return { 'name': _('Landing Cost'), 'view_mode': 'form', 'view_id': self.env.ref('aui_custom_module.view_stock_landed_cost_form_2').id, 'res_model': 'stock.landed.cost', 'type': 'ir.actions.act_window', 'context': { 'default_picking_ids': [(6, 0, rec.picking_ids.filtered(lambda picking: picking.move_ids.stock_valuation_layer_ids != False and picking.state == 'done' and picking.company_id == self.env.company).ids)], 'picking_domain_ids': rec.picking_ids.ids, 'bill_domain_ids': rec.invoice_ids.ids, }, 'target': 'new', }