-
-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[14.0][ADD] delivery_line_qty_delivered
Changes the Delivered Quantity (qty_delivered) of a delivery sale.order.line if one other sale.order.line is delivered the qty_deliverd of the delvivery line is changed to its Quantity (product_uom_qty)
- Loading branch information
1 parent
835506f
commit 2e57b42
Showing
10 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2022 Michael Tietz (MT Software) <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "delivery_line_qty_delivered", | ||
"summary": "Changes the Delivered Quantity (qty_delivered) of a delivery sale.order.line" | ||
"if one other sale.order.line is delivered the qty_delivered of the delivery line" | ||
"is changed to its Quantity (product_uom_qty)", | ||
"version": "14.0.1.0.0", | ||
"license": "AGPL-3", | ||
"author": "Michael Tietz (MT Software) <[email protected]>," | ||
"Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/delivery-carrier", | ||
"depends": [ | ||
"delivery", | ||
"sale_delivery_state", | ||
], | ||
"installable": True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import sale_order | ||
from . import sale_order_line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright 2022 Michael Tietz (MT Software) <[email protected]> | ||
# 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2022 Michael Tietz (MT Software) <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class SaleOrderLine(models.Model): | ||
_inherit = "sale.order.line" | ||
|
||
qty_delivered_method = fields.Selection(selection_add=[("delivery", "Delivery")]) | ||
|
||
@api.depends("product_id", "is_delivery") | ||
def _compute_qty_delivered_method(self): | ||
super(SaleOrderLine, self)._compute_qty_delivered_method() | ||
for line in self: | ||
if line._is_delivery() and line.product_id.type == "service": | ||
line.qty_delivered_method = "delivery" | ||
|
||
def _get_delivery_qty_delivered(self): | ||
self.ensure_one() | ||
if ( | ||
self.product_id.invoice_policy == "delivery" | ||
and self.order_id.delivery_state in ["done", "partially"] | ||
): | ||
return self.product_uom_qty | ||
return 0.0 | ||
|
||
def _compute_qty_delivered(self): | ||
super(SaleOrderLine, self)._compute_qty_delivered() | ||
for line in self: | ||
if line.qty_delivered_method != "delivery": | ||
continue | ||
line.qty_delivered = line._get_delivery_qty_delivered() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_delivery_line_qty_delivered |
110 changes: 110 additions & 0 deletions
110
delivery_line_qty_delivered/tests/test_delivery_line_qty_delivered.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# Copyright 2022 Michael Tietz (MT Software) <[email protected]> | ||
|
||
from odoo.tests import Form, tagged | ||
|
||
from odoo.addons.sale.tests.common import TestSaleCommonBase | ||
from odoo.addons.stock_account.tests.test_anglo_saxon_valuation_reconciliation_common import ( | ||
ValuationReconciliationTestCommon, | ||
) | ||
|
||
|
||
@tagged("post_install", "-at_install") | ||
class TestDeliveryLineQtyDelivered( | ||
TestSaleCommonBase, ValuationReconciliationTestCommon | ||
): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.product = cls.env["product.product"].create( | ||
{"name": "Stockable", "type": "product", "invoice_policy": "delivery"} | ||
) | ||
cls.delivery = cls.product.create( | ||
{"name": "Delivery", "type": "service", "invoice_policy": "delivery"} | ||
) | ||
|
||
def _new_sale_order(self): | ||
warehouse = self.company_data["default_warehouse"] | ||
self.env["stock.quant"]._update_available_quantity( | ||
self.product, warehouse.lot_stock_id, 10 | ||
) | ||
self.so = self.env["sale.order"].create( | ||
{ | ||
"partner_id": self.env.ref("base.main_partner").id, | ||
"order_line": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"product_id": self.product.id, | ||
"product_uom_qty": 1, | ||
"product_uom": self.product.uom_id.id, | ||
"price_unit": 1, | ||
}, | ||
), | ||
( | ||
0, | ||
0, | ||
{ | ||
"product_id": self.delivery.id, | ||
"product_uom_qty": 1, | ||
"product_uom": self.delivery.uom_id.id, | ||
"price_unit": 1, | ||
"is_delivery": True, | ||
}, | ||
), | ||
], | ||
"picking_policy": "direct", | ||
} | ||
) | ||
|
||
def _check_qty_delivered(self, sum_qty_delivered): | ||
self.so.flush() | ||
self.so.order_line.flush() | ||
self.assertEqual( | ||
sum(self.so.order_line.mapped("qty_delivered")), sum_qty_delivered | ||
) | ||
|
||
def _deliver_order(self): | ||
pick = self.so.picking_ids | ||
pick.move_lines.write({"quantity_done": 1}) | ||
pick.button_validate() | ||
|
||
def _return_order(self): | ||
# Create return picking | ||
stock_return_picking_form = Form( | ||
self.env["stock.return.picking"].with_context( | ||
active_ids=self.so.picking_ids.ids, | ||
active_id=self.so.picking_ids.id, | ||
active_model="stock.picking", | ||
) | ||
) | ||
return_wiz = stock_return_picking_form.save() | ||
return_wiz.product_return_moves.quantity = 1.0 | ||
return_wiz.product_return_moves.to_refund = True | ||
res = return_wiz.create_returns() | ||
return_pick = self.env["stock.picking"].browse(res["res_id"]) | ||
|
||
# Validate picking | ||
return_pick.move_lines.write({"quantity_done": 1}) | ||
return_pick.button_validate() | ||
|
||
def test_delivery_qty_delivered(self): | ||
self._new_sale_order() | ||
self._check_qty_delivered(0) | ||
|
||
self.so.action_confirm() | ||
self._check_qty_delivered(0) | ||
|
||
self._deliver_order() | ||
self._check_qty_delivered(2) | ||
|
||
self._return_order() | ||
self._check_qty_delivered(0) | ||
|
||
def test_delivery_qty_delivered_policy_order(self): | ||
self.delivery.invoice_policy = "order" | ||
self._new_sale_order() | ||
self._check_qty_delivered(0) | ||
|
||
self.so.action_confirm() | ||
self._check_qty_delivered(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# See https://github.com/OCA/odoo-community.org/blob/master/website/Contribution/CONTRIBUTING.rst#oca_dependencies-txt | ||
partner-contact | ||
sale-workflow |
1 change: 1 addition & 0 deletions
1
setup/delivery_line_qty_delivered/odoo/addons/delivery_line_qty_delivered
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../delivery_line_qty_delivered |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |