Compare commits

...

3 Commits

Author SHA1 Message Date
Mathieu
8e0357a8fc [IMP] _compute_date_next_reception 2024-07-04 10:48:16 +02:00
Mathieu
37d41d20b7 [IMP] code review 2024-06-25 14:13:36 +02:00
Mathieu
4b2dcb4a86 [ADD] sale_order_line_date_next_reception 2024-06-24 17:34:58 +02:00
9 changed files with 127 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,24 @@
# 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", compute_sudo=True)
def _compute_date_next_reception(self):
for line in self:
line.date_next_reception = False
qty_available = line.product_id.with_context(warehouse=line.order_id.warehouse_id.id).qty_available
if qty_available <=0 and line.state not in ['done', 'cancel']:
picking_model = self.env["stock.picking"]
picking_id = picking_model.search([
('product_id', '=', line.product_id.id),
("picking_type_id.code", "=", "incoming"),
('state', 'in', ['ready', 'waiting', 'assigned'])
])
line.date_next_reception = picking_id and picking_id[0].scheduled_date.date()

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>