From dc24d3621bcfd9779ff8a2d2ed277cdbb84db01d Mon Sep 17 00:00:00 2001 From: Michael Tietz Date: Mon, 12 Dec 2022 20:21:08 +0100 Subject: [PATCH] update --- delivery_line_qty_delivered/__manifest__.py | 1 - .../models/__init__.py | 1 - .../models/sale_order.py | 17 ------------- .../models/sale_order_line.py | 25 +++++++++++++------ oca_dependencies.txt | 1 - 5 files changed, 17 insertions(+), 28 deletions(-) delete mode 100644 delivery_line_qty_delivered/models/sale_order.py diff --git a/delivery_line_qty_delivered/__manifest__.py b/delivery_line_qty_delivered/__manifest__.py index 26a558b765..0ff88f0c45 100644 --- a/delivery_line_qty_delivered/__manifest__.py +++ b/delivery_line_qty_delivered/__manifest__.py @@ -13,7 +13,6 @@ "website": "https://github.com/OCA/delivery-carrier", "depends": [ "delivery", - "sale_delivery_state", ], "installable": True, } diff --git a/delivery_line_qty_delivered/models/__init__.py b/delivery_line_qty_delivered/models/__init__.py index 2d7ee6c3dc..8eb9d1d404 100644 --- a/delivery_line_qty_delivered/models/__init__.py +++ b/delivery_line_qty_delivered/models/__init__.py @@ -1,2 +1 @@ -from . import sale_order from . import sale_order_line diff --git a/delivery_line_qty_delivered/models/sale_order.py b/delivery_line_qty_delivered/models/sale_order.py deleted file mode 100644 index 5abe68f785..0000000000 --- a/delivery_line_qty_delivered/models/sale_order.py +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2022 Michael Tietz (MT Software) -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - -from odoo import models - - -class SaleOrder(models.Model): - _inherit = "sale.order" - - def _compute_sale_delivery_state(self): - super()._compute_sale_delivery_state() - for sale in self: - delivery_lines = sale.order_line.filtered(lambda line: line._is_delivery()) - if delivery_lines: - # delivery_lines.modified(["qty_delivered_manual"]) - # delivery_lines.recompute(["qty_delivered"], delivery_lines) - delivery_lines._compute_qty_delivered() diff --git a/delivery_line_qty_delivered/models/sale_order_line.py b/delivery_line_qty_delivered/models/sale_order_line.py index c3f97a0da1..2ffab1fdac 100644 --- a/delivery_line_qty_delivered/models/sale_order_line.py +++ b/delivery_line_qty_delivered/models/sale_order_line.py @@ -2,6 +2,7 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo import api, fields, models +from odoo.tools import float_is_zero, groupby class SaleOrderLine(models.Model): @@ -16,18 +17,26 @@ def _compute_qty_delivered_method(self): if line._is_delivery() and line.product_id.type == "service": line.qty_delivered_method = "delivery" - def _get_delivery_qty_delivered(self): + def _get_delivery_qty_delivered(self, delivered): self.ensure_one() - if ( - self.product_id.invoice_policy == "delivery" - and self.order_id.delivery_state in ["done", "partially"] - ): + if delivered: return self.product_uom_qty return 0.0 + # @api.depends("qty_delivered_manual") def _compute_qty_delivered(self): super(SaleOrderLine, self)._compute_qty_delivered() - for line in self: - if line.qty_delivered_method != "delivery": + precision = self.env["decimal.precision"].precision_get( + "Product Unit of Measure" + ) + lines_grouped = groupby(self, lambda l: l.order_id) + for order, lines in lines_grouped: + lines = dict(groupby(order.order_line, lambda l: l.qty_delivered_method)) + if "delivery" not in lines or "stock_move" not in lines: continue - line.qty_delivered = line._get_delivery_qty_delivered() + delivered = any( + not float_is_zero(line.qty_delivered, precision) + for line in lines["stock_move"] + ) + for line in lines["delivery"]: + line.qty_delivered = line._get_delivery_qty_delivered(delivered) diff --git a/oca_dependencies.txt b/oca_dependencies.txt index 4e393cc4c1..915f441fc9 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -1,3 +1,2 @@ # See https://github.com/OCA/odoo-community.org/blob/master/website/Contribution/CONTRIBUTING.rst#oca_dependencies-txt partner-contact -sale-workflow