from odoo import models, fields, api, _ class SfStockRoute(models.Model): _inherit = 'stock.route' demand_plan_selectable = fields.Boolean("需求计划行") stock_route_group_ids = fields.Many2many('stock.route.group', 'route_to_group', string='路线组') demand_plan_ids = fields.Many2many('sf.production.demand.plan', 'stock_route_demand_plan', 'route_id', 'demand_plan_id', '需求计划', copy=False, compute='_compute_demand_plan_ids', store=True) @api.depends('demand_plan_selectable', 'stock_route_group_ids') def _compute_demand_plan_ids(self): for sr in self: if sr.demand_plan_selectable: stock_route_group = [srg.code for srg in sr.stock_route_group_ids] demand_plan_ids = self.env['sf.production.demand.plan'].sudo().search( [('supply_method', 'in', stock_route_group)]) if demand_plan_ids: sr.demand_plan_ids = demand_plan_ids.ids continue sr.demand_plan_ids = None # def name_get(self): # res = super().name_get() # if self.env.context.get('demand_plan_search_stock_route_id'): # demand_plan_id = self.env['sf.production.demand.plan'].sudo().browse( # int(self.env.context.get('demand_plan_search_stock_route_id'))) # if demand_plan_id and demand_plan_id.supply_method: # supply_method = self._set_supply_method(demand_plan_id.supply_method) # res = [(item[0], f'{item[1]}-{supply_method}') for item in res if len(item) == 2] # return res # # def _set_supply_method(self, supply_method): # return { # 'automation': "自动化产线加工", # 'manual': "人工线下加工", # 'purchase': "外购", # 'outsourcing': "委外加工" # }.get(supply_method) class SfStockRouteGroup(models.Model): _name = 'stock.route.group' _description = '路线组' name = fields.Char('名称') code = fields.Char('编码')