Hello everyone,
At the moment I can see all the PCs entered in my list, regardless of which customer is selected in the column. However, I would like the PCs to be loaded and displayed only for the selected customers when I click on the x_studio_pc field. How do I do this? Do I have to use OWL? If so, how do I do this? I have no experience with OWL so far.
class ProductTemplate(models.Model):
_inherit = 'product.template'
x_studio_pc_liste = fields.One2many('product.template.line', 'x_product_template_id', string='PC Liste')
class ProductTemplateLine(models.Model):
_name = 'product.template.line'
_description = 'Product Template Line Modul'
_order = 'x_product_template_id, x_studio_sequence, id'
_rec_name = 'x_name'
x_product_template_id = fields.Many2one('product.template', string='X Product Template', ondelete='cascade')
x_studio_info = fields.Char(string='Info', default='Please enter the PC in Name', required=True)
x_studio_sequence = fields.Integer(string='Sequence', default=10)
x_name = fields.Char(string='Description', required=True)
x_studio_distribution = fields.Selection(
[
('5575', 'Test1'),
('5581', 'Test2'),
('5559', 'Test3'),
],
string='Distribution',
required=True
)
x_studio_note = fields.Text(string='Note')
class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'
x_studio_pc = fields.Many2one(
'product.template.line',
string='PC'
)
@api.onchange('product_id')
def _onchange_product_id_set_pc_domain(self):
tmpl = self.product_id.product_tmpl_id
if tmpl and hasattr(tmpl, 'x_pc_liste') and tmpl.x_pc_liste:
pc_ids = tmpl.x_pc_liste.ids
return {
'domain': {
'x_studio_pc': [('id', 'in', pc_ids)]
}
}
else:
return {
'domain': {
'x_studio_pc': []
}
}