Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
382 Zobrazení

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': []

                }

            }

Avatar
Zrušit
Nejlepší odpověď

Hi,

Please refer to the code below:


Model: Product template line

- Added new field for customer.

from odoo import models, fields

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='Product Template', ondelete='cascade')
partner_id = fields.Many2one('res.partner', string='Customer') #ADD THIS LINE
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')

Model: purchase order line

from odoo import models, fields, api

class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'

x_studio_pc = fields.Many2one('product.template.line', string='PC')

@api.onchange('product_id', 'order_id.partner_id')
def _onchange_product_or_partner(self):
"""
Dynamically filters the available options for the 'x_studio_pc' field
based on the selected product and customer.

Only shows PC entries (product.template.line records) that are linked
to both the selected product template and the selected customer (partner).
If either is not selected, the PC dropdown is emptied.
"""
if self.product_id and self.order_id.partner_id:
tmpl = self.product_id.product_tmpl_id
partner = self.order_id.partner_id
pc_ids = self.env['product.template.line'].search([
('x_product_template_id', '=', tmpl.id),
('partner_id', '=', partner.id)
]).ids
return {'domain': {'x_studio_pc': [('id', 'in', pc_ids)]}}
else:
return {'domain': {'x_studio_pc': []}}

Hope it helps.

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
čvc 25
354
2
úno 25
2427
0
bře 15
3738
3
srp 25
484
1
srp 25
164