[REM] sale: unused field
The price_reduce field is not shown to the users, and was not useful for business computations because of its digits specification (losing decimal data when we only want to round the total amounts, not the price before taxes). This commit removes the field to reduce the table size, remove useless computation, avoid misuses of the field and clean code. Task-3018371 closes odoo/odoo#103611 Related: odoo/upgrade#3977 Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
@@ -142,11 +142,6 @@ class SaleOrderLine(models.Model):
|
||||
digits='Discount',
|
||||
store=True, readonly=False, precompute=True)
|
||||
|
||||
price_reduce = fields.Float(
|
||||
string="Price Reduce",
|
||||
compute='_compute_price_reduce',
|
||||
digits='Product Price',
|
||||
store=True, precompute=True)
|
||||
price_subtotal = fields.Monetary(
|
||||
string="Subtotal",
|
||||
compute='_compute_amount',
|
||||
@@ -563,11 +558,6 @@ class SaleOrderLine(models.Model):
|
||||
# otherwise it's a surcharge which shouldn't be shown to the customer
|
||||
line.discount = discount
|
||||
|
||||
@api.depends('price_unit', 'discount')
|
||||
def _compute_price_reduce(self):
|
||||
for line in self:
|
||||
line.price_reduce = line.price_unit * (1.0 - line.discount / 100.0)
|
||||
|
||||
def _convert_to_tax_base_line_dict(self):
|
||||
""" Convert the current record to a dictionary in order to use the generic taxes computation method
|
||||
defined on account.tax.
|
||||
@@ -593,7 +583,9 @@ class SaleOrderLine(models.Model):
|
||||
Compute the amounts of the SO line.
|
||||
"""
|
||||
for line in self:
|
||||
tax_results = self.env['account.tax']._compute_taxes([line._convert_to_tax_base_line_dict()])
|
||||
tax_results = self.env['account.tax']._compute_taxes([
|
||||
line._convert_to_tax_base_line_dict()
|
||||
])
|
||||
totals = list(tax_results['totals'].values())[0]
|
||||
amount_untaxed = totals['amount_untaxed']
|
||||
amount_tax = totals['amount_tax']
|
||||
@@ -827,7 +819,7 @@ class SaleOrderLine(models.Model):
|
||||
amount_invoiced -= invoice_line.currency_id._convert(invoice_line.price_subtotal, line.currency_id, line.company_id, invoice_date)
|
||||
line.untaxed_amount_invoiced = amount_invoiced
|
||||
|
||||
@api.depends('state', 'price_reduce', 'product_id', 'untaxed_amount_invoiced', 'qty_delivered', 'product_uom_qty')
|
||||
@api.depends('state', 'product_id', 'untaxed_amount_invoiced', 'qty_delivered', 'product_uom_qty')
|
||||
def _compute_untaxed_amount_to_invoice(self):
|
||||
""" Total of remaining amount to invoice on the sale order line (taxes excl.) as
|
||||
total_sol - amount already invoiced
|
||||
|
||||
@@ -33,14 +33,12 @@ class TestSaleCommon(SaleCommon):
|
||||
|
||||
self.assertFalse(consumable_line.pricelist_item_id)
|
||||
self.assertEqual(consumable_line.price_unit, 20.0)
|
||||
self.assertEqual(consumable_line.price_reduce, 20.0)
|
||||
self.assertFalse(consumable_line.discount)
|
||||
self.assertEqual(consumable_line.product_uom, self.uom_unit)
|
||||
self.assertEqual(consumable_line.price_total, 5.0 * 20.0)
|
||||
|
||||
self.assertFalse(service_line.pricelist_item_id)
|
||||
self.assertEqual(service_line.price_unit, 50.0)
|
||||
self.assertEqual(service_line.price_reduce, 50.0)
|
||||
self.assertFalse(service_line.discount)
|
||||
self.assertEqual(service_line.product_uom, self.uom_unit)
|
||||
self.assertEqual(service_line.price_total, 12.5 * 50)
|
||||
|
||||
@@ -181,8 +181,14 @@ class TestSaleToInvoice(TestSaleCommon):
|
||||
for line in self.sale_order.order_line:
|
||||
self.assertTrue(float_is_zero(line.untaxed_amount_invoiced, precision_digits=2), "The invoiced amount should be zero, as the line is in draft state")
|
||||
|
||||
self.assertEqual(self.sol_serv_order.untaxed_amount_to_invoice, 297, "The untaxed amount to invoice is wrong")
|
||||
self.assertEqual(self.sol_serv_deliver.untaxed_amount_to_invoice, self.sol_serv_deliver.qty_delivered * self.sol_serv_deliver.price_reduce, "The untaxed amount to invoice should be qty deli * price reduce, so 4 * (180 - 36)")
|
||||
self.assertEqual(
|
||||
self.sol_serv_order.untaxed_amount_to_invoice,
|
||||
297,
|
||||
"The untaxed amount to invoice is wrong")
|
||||
self.assertEqual(
|
||||
self.sol_serv_deliver.untaxed_amount_to_invoice,
|
||||
576,
|
||||
"The untaxed amount to invoice should be qty deli * price reduce, so 4 * (180 - 36)")
|
||||
# 'untaxed_amount_to_invoice' is invalid when 'sale_stock' is installed.
|
||||
# self.assertEqual(self.sol_prod_deliver.untaxed_amount_to_invoice, 140, "The untaxed amount to invoice should be qty deli * price reduce, so 4 * (180 - 36)")
|
||||
|
||||
|
||||
@@ -236,7 +236,7 @@ class TestWebsitePriceList(TransactionCase):
|
||||
with MockRequest(self.env, website=current_website, sale_order_id=so.id):
|
||||
so._cart_update(product_id=product.id, line_id=sol.id, set_qty=500)
|
||||
self.assertEqual(sol.price_unit, 37.0, 'Both reductions should be applied')
|
||||
self.assertEqual(sol.price_reduce, 27.75, 'Both reductions should be applied')
|
||||
self.assertEqual(sol.discount, 25.0, 'Both reductions should be applied')
|
||||
self.assertEqual(sol.price_total, 13875)
|
||||
|
||||
def test_pricelist_with_no_list_price(self):
|
||||
@@ -274,7 +274,7 @@ class TestWebsitePriceList(TransactionCase):
|
||||
with MockRequest(self.env, website=current_website, sale_order_id=so.id):
|
||||
so._cart_update(product_id=product.id, line_id=sol.id, set_qty=6)
|
||||
self.assertEqual(sol.price_unit, 10.0, 'Pricelist price should be applied')
|
||||
self.assertEqual(sol.price_reduce, 10.0, 'Pricelist price should be applied')
|
||||
self.assertEqual(sol.discount, 0, 'Pricelist price should be applied')
|
||||
self.assertEqual(sol.price_total, 60.0)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user