Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions purchase_request/models/purchase_request_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,12 @@ def _calc_new_qty(self, request_line, po_line=None, new_pr_line=False):
supplierinfo_min_qty = self._get_supplier_min_qty(
po_line.product_id, po_line.order_id.partner_id
)

rl_qty = 0.0
# Recompute quantity by adding existing running procurements.
for rl in po_line.purchase_request_lines:
rl_qty += rl.product_uom_id._compute_quantity(rl.product_qty, purchase_uom)
# At this point, the current request_line is already linked to the po_line
unique_rls = po_line.purchase_request_lines.exists()
rl_qty = sum(
rl.product_uom_id._compute_quantity(rl.product_qty, purchase_uom)
for rl in unique_rls
)
qty = max(rl_qty, supplierinfo_min_qty)
return qty

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ def make_purchase_order(self):
if available_po_lines and not item.keep_description:
new_pr_line = False
po_line = available_po_lines[0]
po_line.purchase_request_lines = [(4, line.id)]
po_line.move_dest_ids |= line.move_dest_ids
po_line_product_uom_qty = po_line.product_uom_id._compute_quantity(
po_line.product_uom_qty, alloc_uom
Expand Down Expand Up @@ -286,6 +285,9 @@ def make_purchase_order(self):
# we enforce to save the datetime value in the current tz of the user
date_planned = self._get_date_with_user_tz(date_required)
po_line.write({"product_qty": new_qty, "date_planned": date_planned})
# Now link the PR line to the PO line (if not already linked)
if line.id not in po_line.purchase_request_lines.ids:
po_line.purchase_request_lines = [(4, line.id)]
res.append(purchase.id)

purchase_requests = self.item_ids.mapped("request_id")
Expand Down
Loading