@@ -68,9 +68,9 @@ def _edifact_purchase_get_interchange(self):
6868 recipient = id_number .search ([("partner_id" , "=" , self .partner_id .id )], limit = 1 )
6969 # if current supplier does not have `Id number`
7070 # then check current supplier's parent
71- if not recipient and self .partner_id .parent_id :
71+ if not recipient and self .partner_id .commercial_partner_id :
7272 recipient = id_number .search (
73- [("partner_id" , "=" , self .partner_id .parent_id .id )], limit = 1
73+ [("partner_id" , "=" , self .partner_id .commercial_partner_id .id )], limit = 1
7474 )
7575 if not sender or not recipient :
7676 raise UserError (_ ("Partner is not allowed to use the feature." ))
@@ -82,6 +82,22 @@ def _edifact_purchase_get_interchange(self):
8282 sender_edifact , recipient_edifact , self .name , syntax_identifier
8383 )
8484
85+ def _edifact_purchase_get_supplier_code (self , product ):
86+ # Make it hookable and use the product.supplierinfo if a code is set
87+ supplierinfo = product .seller_ids .filtered_domain (
88+ [("name" , "=" , self .partner_id .id )]
89+ )
90+ if not supplierinfo :
91+ supplierinfo = product .seller_ids .filtered_domain (
92+ [("name" , "=" , self .partner_id .commercial_partner_id .id )]
93+ )
94+
95+ return supplierinfo [:1 ].product_code or product .default_code
96+
97+ def _edifact_purchase_get_barcode (self , product ):
98+ # Make it hookable for additional modules
99+ return product .barcode
100+
85101 def _edifact_purchase_get_address (self , partner ):
86102 # We apply the same logic as:
87103 # https://github.com/OCA/edi/blob/
@@ -122,9 +138,9 @@ def _edifact_purchase_get_header(self, exchange_record=None):
122138 [("partner_id" , "=" , self .company_id .partner_id .id )], limit = 1
123139 )
124140 seller_id_number = id_number .search ([("partner_id" , "=" , self .partner_id .id )])
125- if not seller_id_number and self .partner_id .parent_id :
141+ if not seller_id_number and self .partner_id .commercial_partner_id :
126142 seller_id_number = id_number .search (
127- [("partner_id" , "=" , self .partner_id .parent_id .id )], limit = 1
143+ [("partner_id" , "=" , self .partner_id .commercial_partner_id .id )], limit = 1
128144 )
129145 message_id = exchange_record .id if exchange_record else ""
130146 warehouse_name = (
@@ -200,11 +216,15 @@ def _edifact_purchase_get_product(self):
200216 product_type = "EN"
201217 if self .edifact_version == "d01b" :
202218 product_type = "SRV"
219+
220+ supplier_code = self ._edifact_purchase_get_supplier_code (product )
221+ barcode = self ._edifact_purchase_get_barcode (product )
222+
203223 product_seg = [
204224 # Line item number
205- ("LIN" , number , "" , [product . barcode , product_type ]),
225+ ("LIN" , number , "" , [barcode , product_type ]),
206226 # Product identification of Supplier's article number
207- ("PIA" , "1" , [product . default_code , "SA" , "" , "91" ]),
227+ ("PIA" , "1" , [supplier_code , "SA" , "" , "91" ]),
208228 # Product identification of Buyer's part number
209229 ("PIA" , "1" , [product .default_code , "BP" , "" , "92" ]),
210230 # Ordered quantity
0 commit comments