[ADD] sale_order_line_date_next_reception

This commit is contained in:
Mathieu
2024-06-24 17:34:58 +02:00
parent 29b8ebb779
commit 4b2dcb4a86
9 changed files with 121 additions and 0 deletions

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -0,0 +1,24 @@
# Copyright 2024 Akretion (https://www.akretion.com).
# @author Mathieu DELVA <mathieu.delva@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "sale_order_line_date_next_reception",
"summary": "Next reception Date on sale order line",
"version": "14.0.1.0.0",
"category": "Sale",
"author": "Akretion",
"website": "https://github.com/akretion/odoo-usability",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"sale",
"purchase",
"stock"
],
"data": [
"views/sale_order_view.xml",
],
}

View File

@@ -0,0 +1 @@
from . import sale_order_line

View File

@@ -0,0 +1,18 @@
# Copyright 2024 Akretion (http://www.akretion.com).
# @author Mathieu DELVA <mathieu.delva@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
date_next_reception = fields.Date(compute="_compute_date_next_reception")
def _compute_date_next_reception(self):
for line in self:
line.date_next_reception = False
if not(line.product_id.qty_available):
purchase_order_lines = line.product_id.purchase_order_line_ids
line.date_next_reception = purchase_order_lines and purchase_order_lines[0].date_planned

View File

@@ -0,0 +1 @@
* Mathieu Delva <mathieu.delva@akretion.com>

View File

@@ -0,0 +1 @@
This module displays the date of receipt of the product on the sale order line when the product is no longer in stock and there is a purchase in progress

View File

@@ -0,0 +1,2 @@
# from . import test_sale_line_number
from . import test_sale_line_reception_date

View File

@@ -0,0 +1,58 @@
# Copyright 2024 Akretion (http://www.akretion.com).
# @author Mathieu DELVA <mathieu.delva@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import TransactionCase
from datetime import datetime
from dateutil.relativedelta import relativedelta
class TestSaleLineReceptionDate(TransactionCase):
def setUp(self):
super().setUp()
self.partner = self.env.ref("base.res_partner_12")
self.product_id = self.env.ref("product.product_product_5")
self.purchase_order = self.env["purchase.order"].create(
{
"partner_id": self.partner.id,
"date_order": datetime.today() + relativedelta(days=10),
"order_line": [(0, 0, {
"product_id": self.product_id.id,
"product_qty": 5,
})]
})
def test_date_next_reception(self):
self.purchase_order.button_confirm()
self.sale_order = self.env["sale.order"].create(
{
"partner_id": self.partner.id,
"order_line": [(0, 0, {
"product_id": self.product_id.id,
"product_uom_qty": 2
})]
})
self.assertEqual(self.purchase_order.date_planned.date(), self.sale_order.order_line.date_next_reception)
def test_2_date_next_reception(self):
self.purchase_order.button_confirm()
self.purchase_order2 = self.env["purchase.order"].create(
{
"partner_id": self.partner.id,
"date_order": datetime.today() + relativedelta(days=4),
"order_line": [(0, 0, {
"product_id": self.product_id.id,
"product_qty": 5,
})]
})
self.sale_order = self.env["sale.order"].create(
{
"partner_id": self.partner.id,
"order_line": [(0, 0, {
"product_id": self.product_id.id,
"product_uom_qty": 2
})]
})
self.purchase_order2.button_confirm()
self.assertEqual(self.purchase_order2.date_planned.date(), self.sale_order.order_line.date_next_reception)

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="sale_order_view_form" model="ir.ui.view">
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form" />
<field name="arch" type="xml">
<xpath
expr="//field[@name='order_line']/tree/field[@name='price_unit']"
position="before"
>
<field name="date_next_reception" optional="hide"/>
</xpath>
</field>
</record>
</odoo>