@@ -208,35 +208,48 @@ def _prepare_invoice_line(self, **optional_values):
208208 """
209209 self .ensure_one ()
210210
211- product_name = self .sale_line_id .name
212- if self .company_id .use_dn_product_name_in_invoice :
213- product_name = self .name
214-
215- price_unit = self .sale_line_id .price_unit
216- if self .company_id .use_dn_price_unit_in_invoice :
217- price_unit = self .price_unit
218-
219211 res = {
220- "display_type" : "product" ,
221- "name" : product_name ,
222- "product_id" : self .product_id .id ,
223- "product_uom_id" : self .product_uom_id .id ,
224- "quantity" : self .product_qty ,
225- "discount" : self .discount ,
226- "price_unit" : price_unit ,
227- "tax_ids" : [Command .set (self .tax_ids .ids )],
228- "sale_line_ids" : [Command .link (self .sale_line_id .id )],
212+ "display_type" : self .display_type or "product" ,
229213 "delivery_note_line_id" : self .id ,
230214 }
215+
216+ if self .display_type :
217+ res .update (
218+ {
219+ "name" : self .name ,
220+ "quantity" : 0 ,
221+ "account_id" : False ,
222+ }
223+ )
224+ else :
225+ product_name = self .sale_line_id .name
226+ if self .company_id .use_dn_product_name_in_invoice :
227+ product_name = self .name
228+
229+ price_unit = self .sale_line_id .price_unit
230+ if self .company_id .use_dn_price_unit_in_invoice :
231+ price_unit = self .price_unit
232+
233+ res .update (
234+ {
235+ "name" : product_name ,
236+ "product_id" : self .product_id .id ,
237+ "product_uom_id" : self .product_uom_id .id ,
238+ "quantity" : self .product_qty ,
239+ "discount" : self .discount ,
240+ "price_unit" : price_unit ,
241+ "tax_ids" : [Command .set (self .tax_ids .ids )],
242+ "sale_line_ids" : [Command .link (self .sale_line_id .id )],
243+ }
244+ )
245+ if (
246+ self .sale_line_id .analytic_distribution
247+ and not self .sale_line_id .display_type
248+ ):
249+ res ["analytic_distribution" ] = self .sale_line_id .analytic_distribution
250+
231251 if optional_values .get ("sequence" ):
232252 res ["sequence" ] = optional_values ["sequence" ]
233- if (
234- self .sale_line_id .analytic_distribution
235- and not self .sale_line_id .display_type
236- ):
237- res ["analytic_distribution" ] = self .sale_line_id .analytic_distribution
238253 if optional_values :
239254 res .update (optional_values )
240- if self .display_type :
241- res ["account_id" ] = False
242255 return res
0 commit comments