Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] product_packaging_container_deposit: improve performance #1680

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
from functools import partial

from odoo import Command, _, models
from odoo import _, models

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -50,7 +50,8 @@ def update_order_container_deposit_quantity(self):
deposit_container_qties = (
lines_to_comp_deposit._get_order_lines_container_deposit_quantities()
)
values_lst = []
lines_to_update = {}
lines_to_create = []
for line in self[self._get_order_line_field()]:
if not line.is_container_deposit:
continue
Expand All @@ -67,30 +68,25 @@ def update_order_container_deposit_quantity(self):
# TODO: check if it is needed for UI only
new_vals["name"] = _("[DEL] %(name)s", name=line.name)
# else:
values_lst.append(
Command.update(
line.id,
new_vals,
)
)
lines_to_update[line.id] = new_vals

else:
values_lst.append(
Command.update(
line.id,
{
line._get_product_qty_field(): qty,
line._get_product_qty_delivered_received_field(): qty_dlvd_rcvd,
},
)
)
lines_to_update[line.id] = {
line._get_product_qty_field(): qty,
line._get_product_qty_delivered_received_field(): qty_dlvd_rcvd,
}
for product in deposit_container_qties:
if deposit_container_qties[product][0]:
values = order.prepare_deposit_container_line(
product, deposit_container_qties[product][0]
)
values_lst.append(Command.create(values))
order.write({self._get_order_line_field(): values_lst})
values["order_id"] = order.id
lines_to_create.append(values)
line_model = self._fields[self._get_order_line_field()].comodel_name
for line_id, values in lines_to_update.items():
self.env[line_model].browse(line_id).exists().write(values)
if lines_to_create:
self.env[line_model].create(lines_to_create)
# Schedule line to delete after commit to avoid caching issue w/ UI
if line_ids_to_delete:
self.env.cr.postcommit.add(
Expand Down
Loading