|
| 1 | +from odoo import models |
| 2 | + |
| 3 | + |
| 4 | +class ProductProduct(models.Model): |
| 5 | + _inherit = "product.product" |
| 6 | + |
| 7 | + def _get_pending_lines_domain(self, location_ids=False, warehouse_ids=False): |
| 8 | + domain = self._get_lines_domain(location_ids, warehouse_ids) |
| 9 | + for domain_part in domain: |
| 10 | + if ( |
| 11 | + isinstance(domain_part, tuple) |
| 12 | + and len(domain_part) == 3 |
| 13 | + and domain_part[0] == "state" |
| 14 | + ): |
| 15 | + domain_index = domain.index(domain_part) |
| 16 | + domain[domain_index] = ("state", "in", ("purchase", "done")) |
| 17 | + domain.insert(domain_index + 1, ("pending_to_receive", "=", True)) |
| 18 | + domain.insert(domain_index, "&") |
| 19 | + break |
| 20 | + return domain |
| 21 | + |
| 22 | + def _get_quantity_in_progress(self, location_ids=False, warehouse_ids=False): |
| 23 | + qty_by_product_location, qty_by_product_wh = super()._get_quantity_in_progress( |
| 24 | + location_ids, warehouse_ids |
| 25 | + ) |
| 26 | + domain = self._get_pending_lines_domain(location_ids, warehouse_ids) |
| 27 | + groups = self.env["purchase.order.line"]._read_group( |
| 28 | + domain, |
| 29 | + [ |
| 30 | + "product_id", |
| 31 | + "product_qty", |
| 32 | + "order_id", |
| 33 | + "product_uom", |
| 34 | + "orderpoint_id", |
| 35 | + "existing_qty", |
| 36 | + ], |
| 37 | + ["order_id", "product_id", "product_uom", "orderpoint_id"], |
| 38 | + lazy=False, |
| 39 | + ) |
| 40 | + for group in groups: |
| 41 | + if group.get("orderpoint_id"): |
| 42 | + location = ( |
| 43 | + self.env["stock.warehouse.orderpoint"] |
| 44 | + .browse(group["orderpoint_id"][:1]) |
| 45 | + .location_id |
| 46 | + ) |
| 47 | + else: |
| 48 | + order = self.env["purchase.order"].browse(group["order_id"][0]) |
| 49 | + location = order.picking_type_id.default_location_dest_id |
| 50 | + product = self.env["product.product"].browse(group["product_id"][0]) |
| 51 | + uom = self.env["uom.uom"].browse(group["product_uom"][0]) |
| 52 | + product_qty = uom._compute_quantity( |
| 53 | + group["product_qty"], product.uom_id, round=False |
| 54 | + ) |
| 55 | + remaining_qty = product_qty - group["existing_qty"] |
| 56 | + qty_by_product_location[(product.id, location.id)] += remaining_qty |
| 57 | + qty_by_product_wh[(product.id, location.warehouse_id.id)] += remaining_qty |
| 58 | + return qty_by_product_location, qty_by_product_wh |
0 commit comments