Skip to content

Commit 2e48cf3

Browse files
[ADD] sale_line_service_qty_delivered: Set qty_delivered of service lines
As soon as a sale.order.line is delivered the qty_delivered of the siblings service lines is set to its max qty
1 parent 9924aff commit 2e48cf3

14 files changed

Lines changed: 792 additions & 0 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
===============================
2+
sale_line_service_qty_delivered
3+
===============================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:37fdf76093b09b35865f89b170505be32ad5ae2a82e4eac4fadb052ea2621a8e
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github
20+
:target: https://github.com/OCA/sale-workflow/tree/14.0/sale_line_service_qty_delivered
21+
:alt: OCA/sale-workflow
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/sale-workflow-14-0/sale-workflow-14-0-sale_line_service_qty_delivered
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=14.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This addon automatically increases or decreases the delivered quantity
32+
for sale.order.lines where a service product with a invoice policy delivery is set.
33+
An order line's delivered quantity is increased to its max as soon as another line with a stock product is delivered or if there is no line with stock product.
34+
An order line's delivered quantity is decreased to zero when all lines with stock product are entirely returned.
35+
36+
**Table of contents**
37+
38+
.. contents::
39+
:local:
40+
41+
Bug Tracker
42+
===========
43+
44+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/issues>`_.
45+
In case of trouble, please check there if your issue has already been reported.
46+
If you spotted it first, help us to smash it by providing a detailed and welcomed
47+
`feedback <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_line_service_qty_delivered%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
48+
49+
Do not contact contributors directly about support or help with technical issues.
50+
51+
Credits
52+
=======
53+
54+
Authors
55+
~~~~~~~
56+
57+
* Michael Tietz (MT Software) <mtietz@mt-software.de>
58+
59+
Contributors
60+
~~~~~~~~~~~~
61+
62+
* Michael Tietz (MT Software) <mtietz@mt-software.de>
63+
64+
Maintainers
65+
~~~~~~~~~~~
66+
67+
This module is maintained by the OCA.
68+
69+
.. image:: https://odoo-community.org/logo.png
70+
:alt: Odoo Community Association
71+
:target: https://odoo-community.org
72+
73+
OCA, or the Odoo Community Association, is a nonprofit organization whose
74+
mission is to support the collaborative development of Odoo features and
75+
promote its widespread use.
76+
77+
This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/14.0/sale_line_service_qty_delivered>`_ project on GitHub.
78+
79+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
{
5+
"name": "sale_line_service_qty_delivered",
6+
"summary": "Changes the Delivered Quantity (qty_delivered) of a service sale.order.line"
7+
"if one other sale.order.line is delivered the qty_delivered of the service line"
8+
"is changed to its Quantity (product_uom_qty)",
9+
"version": "14.0.1.0.0",
10+
"license": "AGPL-3",
11+
"author": "Michael Tietz (MT Software) <mtietz@mt-software.de>,"
12+
"Odoo Community Association (OCA)",
13+
"website": "https://github.com/OCA/sale-workflow",
14+
"depends": [
15+
"delivery",
16+
],
17+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import sale_order_line
2+
from . import sale_order
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import models
5+
6+
7+
class SaleOrderLine(models.Model):
8+
_inherit = "sale.order"
9+
10+
def _get_invoice_status(self):
11+
super()._get_invoice_status()
12+
to_invoice_status = "to invoice"
13+
no_invoice_status = "no"
14+
for order in self:
15+
if (
16+
order.state not in ("sale", "done")
17+
or order.invoice_status != no_invoice_status
18+
):
19+
continue
20+
21+
invoice_status = no_invoice_status
22+
for line in order.order_line:
23+
if not line._is_delivered_method_delivery():
24+
continue
25+
if line.invoice_status == to_invoice_status:
26+
invoice_status = to_invoice_status
27+
break
28+
29+
if invoice_status == to_invoice_status:
30+
order.invoice_status = to_invoice_status
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
from odoo.tools import float_is_zero
6+
7+
8+
class SaleOrderLine(models.Model):
9+
_inherit = "sale.order.line"
10+
11+
qty_delivered_method = fields.Selection(selection_add=[("delivery", "Delivery")])
12+
13+
def _is_delivered_method_delivery(self):
14+
self.ensure_one()
15+
service_type = self.product_id.service_type
16+
return (
17+
self.product_id.type == "service"
18+
and (not service_type or service_type == "manual")
19+
and self.product_id.invoice_policy == "delivery"
20+
)
21+
22+
def _compute_qty_delivered_method(self):
23+
super()._compute_qty_delivered_method()
24+
for line in self:
25+
if line._is_delivered_method_delivery():
26+
line.qty_delivered_method = "delivery"
27+
28+
def _get_delivery_qty_delivered(self):
29+
self.ensure_one()
30+
precision = self.env["decimal.precision"].precision_get(
31+
"Product Unit of Measure"
32+
)
33+
qty_delivered = 0
34+
contains_stock_move_sale_line = False
35+
is_delivered = False
36+
for line in self.order_id.order_line:
37+
if (
38+
line.qty_delivered_method != "stock_move"
39+
or line.product_id.invoice_policy != "delivery"
40+
):
41+
continue
42+
contains_stock_move_sale_line = True
43+
if not float_is_zero(line.qty_delivered, precision):
44+
is_delivered = True
45+
break
46+
# Only return a delivered qty if there is something delivered
47+
# or if the sale.order does not contains a sale.order.line
48+
# with a delivered_method = stock_move
49+
if is_delivered or not contains_stock_move_sale_line:
50+
qty_delivered = self.product_uom_qty
51+
return qty_delivered
52+
53+
def _compute_qty_delivered_delivery_method(self):
54+
for line in self.order_id.order_line:
55+
if line.qty_delivered_method != "delivery":
56+
continue
57+
line.qty_delivered = line._get_delivery_qty_delivered()
58+
59+
def _compute_qty_delivered(self):
60+
super()._compute_qty_delivered()
61+
self._compute_qty_delivered_delivery_method()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Michael Tietz (MT Software) <mtietz@mt-software.de>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This addon automatically increases or decreases the delivered quantity
2+
for sale.order.lines where a service product with a invoice policy delivery is set.
3+
An order line's delivered quantity is increased to its max as soon as another line with a stock product is delivered or if there is no line with stock product.
4+
An order line's delivered quantity is decreased to zero when all lines with stock product are entirely returned.

0 commit comments

Comments
 (0)