Skip to Content
Menu
This question has been flagged
1 Reply
731 Views

hi every one 

in odoo 18 I want to edit the stock.picking form and if I select partner

the products in the Operations tab must be shown like this the user try to pick a product he see only the products that have the same partner in his vendor list

and I try this code 

class StockPickingCo(models.Model):
_inherit = 'stock.picking'

@api.onchange('partner_id')
def _onchange_partner_id_filter_products(self):
print("_onchange_partner_id_filter_products")
if self.partner_id:
return {
'domain': {
'move_ids_without_package.product_id': [
('seller_ids.partner_id', '=', self.partner_id.id)
]
}
}
return {
'domain': {
'move_ids_without_package.product_id': []
}
}

and this 

 

class StockMove(models.Model):
_inherit = 'stock.move'

@api.onchange('product_id')
def _onchange_product_id_domain(self):
print("_onchange_product_id_domain")
if self.picking_id and self.picking_id.partner_id:
print("_onchange_product_id_domain - 0", self.picking_id)
return {
'domain': {
'product_id': [
('seller_ids.partner_id', '=', self.picking_id.partner_id.id)
]
}
}
return {}

but it's not working can any one help me on this or giving me any idea to make it working 

Avatar
Discard
Best Answer

Hi,

Please check the code below:


Python:

from odoo import api, fields, models


class StockMove(models.Model):
_inherit = 'stock.move'

vendor_product_ids = fields.Many2many(
'product.product', string="Vendor's Product",
compute="_compute_vendor_product_ids")
product_id = fields.Many2one(
'product.product', 'Product',
check_company=True,
domain="[('id', 'in', vendor_product_ids)]", index=True, required=True)

@api.depends('picking_id.partner_id')
def _compute_vendor_product_ids(self):
for rec in self:
if rec.picking_id.picking_type_code == 'incoming':
rec.vendor_product_ids = self.env['product.product'].sudo().search([
('type', '=', 'consu')]).filtered(
lambda l: self.picking_id.partner_id.id in
l.seller_ids.partner_id.ids)
else:
rec.vendor_product_ids = self.env[
'product.product'].sudo().search([('type', '=', 'consu')]).idsPolishAlt + H


Hope it helps.

Avatar
Discard
Related Posts Replies Views Activity
0
May 25
450
1
Jun 25
1010
0
Mar 25
812
2
Aug 24
924
1
Sep 17
7437