[FIX] sale: set a default qty_delivered on new sol

Steps to reproduce:

- Create an SO with an SOL and save the record.

** The `qty_delivered` of that SOL will be null in the DB. **

Cause of the issue:

Since the `qty_delivered` field is computed, the default value is set in
the DB comes from the `_compute_qty_delivered` method at record creation
However, no default value is set here when the `qty_delivered_method` is
not `'analytic'`.

Note:

In 15.0, a default value was set because of these lines:
https://github.com/odoo/odoo/blob/313418804ae5cb6a786488ffc174b8eebffb796e/addons/sale/models/sale_order_line.py#L350-L353
These were removed by this commit de4911a.

opw-3771589

closes odoo/odoo#163180

X-original-commit: 3e20e293771a252bbdcd395b5a12a2cef70f0218
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
lase@odoo.com
2024-04-25 11:21:54 +00:00
parent bf696b054e
commit 506a1c19be
2 changed files with 14 additions and 0 deletions
+1
View File
@@ -207,6 +207,7 @@ class SaleOrderLine(models.Model):
qty_delivered = fields.Float(
string="Delivery Quantity",
compute='_compute_qty_delivered',
default=0.0,
digits='Product Unit of Measure',
store=True, readonly=False, copy=False)
+13
View File
@@ -746,3 +746,16 @@ class TestSalesTeam(SaleCommon):
self.assertEqual(sale_order.team_id, crm_team0, "Sales team should change to partner's")
sale_order.with_user(self.user_not_in_team).write({'partner_id': partner_b.id})
self.assertEqual(sale_order.team_id, crm_team1, "Sales team should change to partner's")
def test_qty_delivered_on_creation(self):
"""Checks that the qty delivered of sol is automatically set to 0.0 when an so is created"""
sale_order = self.env['sale.order'].create({
'partner_id': self.partner.id,
'order_line': [
Command.create({
'product_id': self.product.id,
})],
})
# As we want to determine if the value is set in the DB we need to perform a search
self.assertFalse(self.env['sale.order.line'].search(['&', ('order_id', '=', sale_order.id), ('qty_delivered', '=', False)]))
self.assertEqual(self.env['sale.order.line'].search(['&', ('order_id', '=', sale_order.id), ('qty_delivered', '=', 0.0)]), sale_order.order_line)