Skip to content

Commit 0830d08

Browse files
weinni2000claude
andcommitted
[FIX] product_customerinfo_picking: support variant-level customer info
- Check `product_id.customer_ids` instead of `product_tmpl_id.customer_ids` in the guard condition to correctly reflect variant-level records - Add `product_tmpl_id` filter to template-level lookup to avoid cross-template false matches - Look up `variant_customer_ids` after template-level and let it override, so variant-specific customerinfo takes precedence over template-level Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7a60d26 commit 0830d08

1 file changed

Lines changed: 24 additions & 14 deletions

File tree

product_customerinfo_picking/models/stock_move.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
class StockMove(models.Model):
77
_inherit = "stock.move"
88

9+
product_customer_code = fields.Char(
10+
compute="_compute_product_customer_code",
11+
)
12+
product_customer_name = fields.Char(
13+
compute="_compute_product_customer_code",
14+
)
15+
916
@api.depends(
1017
"picking_id.partner_id",
1118
"product_id",
@@ -19,21 +26,24 @@ def _compute_product_customer_code(self):
1926
if (
2027
move.picking_id
2128
and move.picking_id.partner_id
22-
and move.product_tmpl_id.customer_ids
29+
and move.product_id.customer_ids
2330
):
24-
customer = fields.first(
25-
move.product_tmpl_id.customer_ids.filtered(
26-
lambda m, mo=move: m.partner_id == mo.picking_id.partner_id
27-
)
31+
customer_info_ids = move.product_tmpl_id.customer_ids.filtered(
32+
lambda m, mo=move: m.partner_id == mo.picking_id.partner_id
33+
and m.product_tmpl_id == mo.product_tmpl_id
34+
)
35+
for customer_info_id in customer_info_ids:
36+
product_customer_code = customer_info_id.product_code
37+
product_customer_name = customer_info_id.product_name
38+
break
39+
customer_ids = move.product_id.variant_customer_ids.filtered(
40+
lambda m, mo=move: m.partner_id == mo.picking_id.partner_id
41+
and m.product_id == mo.product_id
2842
)
29-
product_customer_code = customer.product_code
30-
product_customer_name = customer.product_name
43+
for customer_id in customer_ids:
44+
if customer_id.partner_id == move.picking_id.partner_id:
45+
product_customer_code = customer_id.product_code
46+
product_customer_name = customer_id.product_name
47+
break
3148
move.product_customer_code = product_customer_code
3249
move.product_customer_name = product_customer_name
33-
34-
product_customer_code = fields.Char(
35-
compute="_compute_product_customer_code",
36-
)
37-
product_customer_name = fields.Char(
38-
compute="_compute_product_customer_code",
39-
)

0 commit comments

Comments
 (0)