@@ -25,7 +25,11 @@ class ProductTemplate(models.Model):
2525 help = 'Planned Price. This value depends on Planned Price Type" an other parameters.' ,
2626 )
2727 list_price_type = fields .Selection (
28- [("manual" , "Fixed value" ), ("by_margin" , "By Margin" ), ("other_currency" , "Currency exchange" )],
28+ [
29+ ("manual" , "Fixed value" ),
30+ ("by_margin" , "By Margin" ),
31+ ("other_currency" , "Currency exchange" ),
32+ ],
2933 string = "Planned Price Type" ,
3034 # we make it optional
3135 # required=True,
@@ -94,7 +98,10 @@ def cron_update_prices_from_planned(self, batch_size=1000):
9498 last_updated_param = self .env ["ir.config_parameter" ].sudo ().create ({"key" : parameter_name , "value" : "0" })
9599
96100 # Obtiene los registros ordenados por id
97- domain = [("list_price_type" , "!=" , False ), ("id" , ">" , int (last_updated_param .value ))]
101+ domain = [
102+ ("list_price_type" , "!=" , False ),
103+ ("id" , ">" , int (last_updated_param .value )),
104+ ]
98105 records = self .with_context (prefetch_fields = False ).search (domain , order = "id asc" )
99106
100107 records [:batch_size ].with_context (bypass_base_automation = True )._update_prices_from_planned ()
@@ -105,7 +112,8 @@ def cron_update_prices_from_planned(self, batch_size=1000):
105112 last_updated_id = 0
106113
107114 self .env .cr .execute (
108- "UPDATE ir_config_parameter set value = %s where id = %s" , (str (last_updated_id ), last_updated_param .id )
115+ "UPDATE ir_config_parameter set value = %s where id = %s" ,
116+ (str (last_updated_id ), last_updated_param .id ),
109117 )
110118 # Uso directo de cr.commit(). Buscar alternativa menos riesgosa
111119 self .env .cr .commit () # pragma pylint: disable=invalid-commit
@@ -127,15 +135,16 @@ def _update_prices_from_planned(self):
127135 """
128136 prec = self .env ["decimal.precision" ].precision_get ("Product Price" )
129137
130- cr = self ._cr
138+ cr = self .env . cr
131139 for rec in self .with_context (prefetch_fields = False ).filtered (
132140 lambda x : x .list_price_type
133141 and x .computed_list_price
134142 and not float_is_zero (x .computed_list_price - x .list_price , precision_digits = prec )
135143 ):
136144 # es mucho mas rapido hacerlo por sql directo
137145 cr .execute (
138- "UPDATE product_template SET list_price=%s WHERE id=%s" , (rec .computed_list_price or 0.0 , rec .id )
146+ "UPDATE product_template SET list_price=%s WHERE id=%s" ,
147+ (rec .computed_list_price or 0.0 , rec .id ),
139148 )
140149 return True
141150
@@ -161,15 +170,22 @@ def _compute_computed_list_price(self):
161170 )
162171 elif rec .list_price_type == "other_currency" and rec .currency_id :
163172 computed_list_price = rec .other_currency_id .sudo ()._convert (
164- rec .other_currency_list_price , rec .currency_id , rec .main_company_id , date , round = False
173+ rec .other_currency_list_price ,
174+ rec .currency_id ,
175+ rec .main_company_id ,
176+ date ,
177+ round = False ,
165178 )
166179
167180 # if product has taxes with price_include, add the tax to the
168181 # sale price
169182 inc_taxes = rec .taxes_id .filtered ("price_include" )
170183 if inc_taxes :
171184 computed_list_price = inc_taxes .compute_all (
172- computed_list_price , rec .currency_id , product = rec , handle_price_include = False
185+ computed_list_price ,
186+ rec .currency_id ,
187+ product = rec ,
188+ handle_price_include = False ,
173189 )["total_included" ]
174190
175191 rec .update (
@@ -184,25 +200,26 @@ def price_compute(self, price_type, uom=False, currency=False, company=False, da
184200 be based on the planned, you can do it by sending use_planned_price
185201 in the context
186202 """
187- if self ._context .get ("use_planned_price" ) and price_type == "list_price" :
203+ if self .env . context .get ("use_planned_price" ) and price_type == "list_price" :
188204 price_type = "computed_list_price"
189205 return super ().price_compute (price_type , uom = uom , currency = currency , company = company , date = date )
190206
191207 @api .onchange ("list_price_type" )
192208 def _compute_warnings_price (self ):
193209 if self .env ["res.company" ].sudo ().search_count ([]) > 1 :
194- msg = _ ("The values correspond to the replenishment cost to the company: %s." , self .main_company_id .name )
195- warnings = {
196- "company_info" : {
210+ msg = _ (
211+ "The values correspond to the replenishment cost to the company: %s." ,
212+ self .main_company_id .name ,
213+ )
214+ warnings = [
215+ {
197216 "message" : msg ,
198- "action_text" : False ,
199- "action" : False ,
200217 "level" : "info" ,
201218 }
202- }
219+ ]
203220 fixed = self .filtered (lambda x : x .list_price_type == "manual" )
204221 # para los fixed no damos warning ya que no suma valor
205- fixed .warnings_price = {}
222+ fixed .warnings_price = False
206223 (self - fixed ).warnings_price = warnings
207224 else :
208- self .warnings_price = {}
225+ self .warnings_price = False
0 commit comments