diff --git a/addons/event_sale/models/event_event.py b/addons/event_sale/models/event_event.py index cdb2cc3558f..4ab99bbe0ab 100644 --- a/addons/event_sale/models/event_event.py +++ b/addons/event_sale/models/event_event.py @@ -32,21 +32,22 @@ class Event(models.Model): we sell a single event ticket). """ date_now = fields.Datetime.now() event_subtotals = self.env['sale.order.line']._read_group( - [('event_id', 'in', self.ids), - ('price_subtotal', '!=', 0)], + [('event_id', 'in', self.ids), ('price_subtotal', '!=', 0)], ['event_id', 'currency_id'], ['price_subtotal:sum'], ) - - self.sale_price_subtotal = 0 + event_subtotals_mapping = dict.fromkeys(self._origin, 0) for event, currency, sum_price_subtotal in event_subtotals: - event.sale_price_subtotal += event.currency_id._convert( + event_subtotals_mapping[event] += event.currency_id._convert( sum_price_subtotal, currency, event.company_id or self.env.company, date_now, ) + for event in self: + event.sale_price_subtotal = event_subtotals_mapping.get(event._origin, 0) + def action_view_linked_orders(self): """ Redirects to the orders linked to the current events """ sale_order_action = self.env["ir.actions.actions"]._for_xml_id("sale.action_orders") diff --git a/addons/stock/models/product.py b/addons/stock/models/product.py index 3e816836b5f..acc3d8e6523 100644 --- a/addons/stock/models/product.py +++ b/addons/stock/models/product.py @@ -393,12 +393,13 @@ class Product(models.Model): return list(product_ids) def _compute_nbr_reordering_rules(self): - self.nbr_reordering_rules = self.reordering_min_qty = self.reordering_max_qty = 0 read_group_res = self.env['stock.warehouse.orderpoint']._read_group( [('product_id', 'in', self.ids)], ['product_id'], ['__count', 'product_min_qty:sum', 'product_max_qty:sum']) - for product, count, product_min_qty_sum, product_max_qty_sum in read_group_res: + mapped_res = {product: aggregates for product, *aggregates in read_group_res} + for product in self: + count, product_min_qty_sum, product_max_qty_sum = mapped_res.get(product._origin, (0, 0, 0)) product.nbr_reordering_rules = count product.reordering_min_qty = product_min_qty_sum product.reordering_max_qty = product_max_qty_sum diff --git a/addons/stock_account/models/product.py b/addons/stock_account/models/product.py index 2a0ae743616..43dd2a4556d 100644 --- a/addons/stock_account/models/product.py +++ b/addons/stock_account/models/product.py @@ -129,21 +129,16 @@ class ProductProduct(models.Model): groupby=['product_id'], aggregates=['value:sum', 'quantity:sum'], ) - remaining = self # Browse all products and compute products' quantities_dict in batch. - for product, value_sum, quantity_sum in groups: + group_mapping = {product: aggregates for product, *aggregates in groups} + for product in self: + value_sum, quantity_sum = group_mapping.get(product._origin, (0, 0)) value_svl = company_id.currency_id.round(value_sum) avg_cost = value_svl / quantity_sum if quantity_sum else 0 product.value_svl = value_svl product.quantity_svl = quantity_sum product.avg_cost = avg_cost product.total_value = avg_cost * product.sudo(False).qty_available - remaining -= product - - remaining.value_svl = 0 - remaining.quantity_svl = 0 - remaining.avg_cost = 0 - remaining.total_value = 0 # ------------------------------------------------------------------------- # Actions