from odoo import models,fields class ProductionLine(models.Model): _name = 'sf.production.line' _description = '生产线' def _get_code(self): """ 自动生成编码 :return: """ fixture_material = self.env['sf.production.line'].sudo().search( [('code', '!=', '')], limit=1, order="id desc") if not fixture_material: num = "%03d" % 1 else: m = int(fixture_material.code) + 1 num = "%03d" % m return num mrp_workcenter_ids = fields.One2many('mrp.workcenter', 'production_line_id', '工作中心') name = fields.Char('生产线', size=20, required=True) code = fields.Char('编码', default=_get_code, readonly=True) remark = fields.Char('备注')