odoo部分知识点注解2
1.1qc_inspection.py
@api.multi
def _links_get(self):
link_obj = self.env[‘res.request.link’]
return [(r.object, r.name) for r in link_obj.search([])]
object_id = fields.Reference(
string=‘Reference’, selection=_links_get, readonly=True,
states={‘draft’: [(‘readonly’, False)]}, ondelete=“set null”)
@api.depends(‘object_id’)
def _compute_product_id(self):
for i in self:
if i.object_id and i.object_id._name == ‘product.product’:
i.product_id = i.object_id
else:
i.product_id = False
product_id = fields.Many2one(
comodel_name=“product.product”, compute="_compute_product_id",
store=True, help=“Product associated with the inspection”,
oldname=‘product’)
1.2qc_inspection_view.py
1.3前端
2.1qc_inspection.py
@api.depends(‘inspection_lines’, ‘inspection_lines.success’)
def _compute_success(self):
for i in self:
i.success = all([x.success for x in i.inspection_lines])
inspection_lines = fields.One2many(
comodel_name=‘qc.inspection.line’, inverse_name=‘inspection_id’,
string=‘Inspection lines’, readonly=True,
states={‘ready’: [(‘readonly’, False)]})
success = fields.Boolean(
compute="_compute_success", string=‘Success’,
help=‘This field will be marked if all tests have succeeded.’,
store=True)