77
88from lxml import etree
99
10- from odoo import _ , api , fields , models
10+ from odoo import api , fields , models
1111from odoo .exceptions import UserError
1212from odoo .osv import expression
1313
@@ -53,18 +53,17 @@ def create_document_from_xml(self, xml_content, voxel_filename, company):
5353 xml_content , voxel_filename , error_msgs , company
5454 )
5555 # Add internal note to the created sale order
56- create_msg = _ ("Created automatically via voxel import (%s)." ) % voxel_filename
56+ create_msg = (
57+ self .env ._ ("Created automatically via voxel import (%s)." ) % voxel_filename
58+ )
5759 if error_msgs :
5860 str_error_msgs = ""
5961 for error_msg in error_msgs :
60- str_error_msgs += "<li>%s</li>" % error_msg
61- create_msg += (
62- _ (
63- "<br/><span style='font-weight: bold;'>"
64- "The following errors were found:</span><br/>"
65- "<ul>%s</ul>"
66- )
67- % str_error_msgs
62+ str_error_msgs += f"<li>{ error_msg } </li>"
63+ create_msg += self .env ._ (
64+ "<br/><span style='font-weight: bold;'>"
65+ "The following errors were found:</span><br/>"
66+ f"<ul>{ str_error_msgs } </ul>"
6867 )
6968 order .message_post (body = create_msg )
7069 return order
@@ -77,15 +76,20 @@ def _parse_voxel_order(self, order_file, order_filename, error_msgs, company):
7776 try :
7877 xml_root = etree .fromstring (order_file )
7978 except Exception as exc :
80- raise UserError (_ ("This XML file is not XML-compliant" )) from exc
79+ raise UserError (
80+ self .env ._ ("This XML file is not XML-compliant" )
81+ ) from exc
8182 else :
82- raise UserError (_ ("'%s' is not recognised as an XML file" ) % order_filename )
83- _logger .debug ("Starting to import:%s" % (order_filename ))
83+ raise UserError (
84+ self .env ._ (f"'{ order_filename } ' is not recognised as an XML file" )
85+ )
86+ _logger .debug (f"Starting to import:{ order_filename } " )
8487 try :
8588 return self ._parse_xml_order (xml_root , error_msgs , company )
8689 except Exception as exc :
8790 raise UserError (
88- _ ("Error creating the order" ) + f"\n \n File contents:\n { order_file } "
91+ self .env ._ ("Error creating the order" )
92+ + f"\n \n File contents:\n { order_file } "
8993 ) from exc
9094
9195 def _parse_xml_order (self , xml_root , error_msgs , company ):
@@ -150,13 +154,12 @@ def _parse_supplier_data_voxel(self, vals, xml_root, error_msgs):
150154 # Add error message to error_msgs list
151155 msg_fields = self ._get_voxel_msg_fields ("res.partner" , partner_data )
152156 error_msgs .append (
153- _ (
157+ self . env . _ (
154158 "Couldn't find any <b>Company</b> corresponding to "
155159 "the following information extracted from the Voxel "
156160 "document:<br/>"
157- "<ul>%s </ul>"
161+ f "<ul>{ msg_fields } </ul>"
158162 )
159- % (msg_fields )
160163 )
161164
162165 def _parse_client_data_voxel (self , vals , xml_root , error_msgs ):
@@ -199,13 +202,12 @@ def _parse_customers_data_voxel(self, vals, xml_root, error_msgs):
199202 # Add error message to error_msgs list
200203 msg_fields = self ._get_voxel_msg_fields ("res.partner" , partner_data )
201204 error_msgs .append (
202- _ (
205+ self . env . _ (
203206 "Couldn't find any <b>Delivery Address</b> "
204207 "corresponding to the following information extracted "
205208 "from the Voxel document:<br/>"
206- "<ul>%s </ul>"
209+ f "<ul>{ msg_fields } </ul>"
207210 )
208- % (msg_fields )
209211 )
210212
211213 def _parse_partner_data_voxel (self , data , raise_error = True ):
@@ -236,7 +238,7 @@ def _parse_partner_data_voxel(self, data, raise_error=True):
236238 return partner # return the unique partner matching
237239 if raise_error :
238240 raise UserError (
239- _ (
241+ self . env . _ (
240242 "Can't find a suitable partner for this data:\n \n %(data)s"
241243 "\n Results: %(partner_count)s" ,
242244 data = data ,
@@ -283,13 +285,16 @@ def _parse_product_voxel(self, line_vals, line_element):
283285 self .env ["sale.order" ].browse (line_vals ["order_id" ]).partner_id
284286 )
285287 customerinfo = self .env ["product.customerinfo" ].search (
286- [("name" , "=" , partner .id ), ("product_code" , "=" , supplier_sku )],
288+ [
289+ ("partner_id" , "=" , partner .id ),
290+ ("product_code" , "=" , supplier_sku ),
291+ ],
287292 limit = 1 ,
288293 )
289294 if not customerinfo :
290295 customerinfo = self .env ["product.customerinfo" ].search (
291296 [
292- ("name " , "=" , partner .commercial_partner_id .id ),
297+ ("partner_id " , "=" , partner .commercial_partner_id .id ),
293298 ("product_code" , "=" , supplier_sku ),
294299 ],
295300 limit = 1 ,
@@ -306,11 +311,9 @@ def _parse_product_voxel(self, line_vals, line_element):
306311 product = self .env ["product.product" ].search (domain )
307312 if len (product ) != 1 :
308313 raise UserError (
309- _ (
310- "Can't find a suitable product for this data:\n \n %(product_data)s"
311- "\n Results: %(product_count)s" ,
312- product_data = product_data ,
313- product_count = len (product ),
314+ self .env ._ (
315+ f"Can't find a suitable product for this data:\n \n { product_data } "
316+ f"\n Results: { len (product )} " ,
314317 )
315318 )
316319 line_vals .update (product_id = product .id )
@@ -322,11 +325,10 @@ def _parse_qty_uom_voxel(self, line_vals, line_element):
322325 product_uom = self .env ["uom.uom" ].search ([("voxel_code" , "=" , mu )])
323326 if len (product_uom ) != 1 :
324327 raise UserError (
325- _ (
326- "Can't find a suitable Unit of Measure for this data:\n \n %(product_data)s"
327- "\n Results: %(product_uom_count)s" ,
328- product_data = product_data ,
329- product_uom_count = len (product_uom ),
328+ self .env ._ (
329+ "Can't find a suitable Unit of Measure for this data:"
330+ f"\n \n { product_data } "
331+ f"\n Results: { len (product_uom )} "
330332 )
331333 )
332334 line_vals .update (product_uom_qty = qty , product_uom = product_uom .id )
@@ -360,13 +362,12 @@ def _parse_taxes_product_voxel(self, line_vals, line_element, error_msgs):
360362 tax_data = {"voxel_tax_code" : voxel_tax_code , "amount" : amount }
361363 msg_fields = self ._get_voxel_msg_fields ("account.tax" , tax_data )
362364 error_msgs .append (
363- _ (
365+ self . env . _ (
364366 "Couldn't find any <b>Tax</b> corresponding to "
365367 "the following information extracted from the Voxel "
366368 "document:<br/>"
367- "<ul>%s </ul>"
369+ f "<ul>{ msg_fields } </ul>"
368370 )
369- % (msg_fields )
370371 )
371372
372373 def _get_partner_data_voxel (self , data ):
0 commit comments