summaryrefslogtreecommitdiff
path: root/addons/sale_expense
diff options
context:
space:
mode:
authorAnh Thao Pham (pta) <pta@odoo.com>2020-11-20 07:29:43 +0000
committerAnh Thao Pham (pta) <pta@odoo.com>2020-11-20 07:29:43 +0000
commit0936e2da3e5c66e4050f27e994437eb219e3c85f (patch)
tree5dbe966b855b8708357ceb3af82dc41b34eecf05 /addons/sale_expense
parent84bc58fc06fb460b63907102ac29d0c295636584 (diff)
[FIX] sale_expense: Fix quantity on SOL when re-invoicing an expense
This is a backport of commit https://github.com/odoo/odoo/commit/b48111635b8f273f5a8b26960b110468908ed3c4 from master to 14.0 Currently, when reinvoicing an expense, a SOL with the expense product is added to the selected SO, but the 'quantity' field remains at 0. But when adding expense product to SO, we need to change the sales order price, because it will be charged to the customer in the end. So in this commit, we set the quantity on the SOL equal to the quantity set on the expense. opw-2377511 closes odoo/odoo#62057 Signed-off-by: Anh Thao PHAM <kitan191@users.noreply.github.com>
Diffstat (limited to 'addons/sale_expense')
-rw-r--r--addons/sale_expense/models/account_move.py8
-rw-r--r--addons/sale_expense/tests/test_reinvoice.py6
-rw-r--r--addons/sale_expense/tests/test_sale_expense.py4
3 files changed, 13 insertions, 5 deletions
diff --git a/addons/sale_expense/models/account_move.py b/addons/sale_expense/models/account_move.py
index 5420a3f3dc7..c2e90b800a0 100644
--- a/addons/sale_expense/models/account_move.py
+++ b/addons/sale_expense/models/account_move.py
@@ -29,3 +29,11 @@ class AccountMoveLine(models.Model):
mapping_from_invoice.update(mapping_from_expense)
return mapping_from_invoice
+
+ def _sale_prepare_sale_line_values(self, order, price):
+ # Add expense quantity to sales order line and update the sales order price because it will be charged to the customer in the end.
+ self.ensure_one()
+ res = super()._sale_prepare_sale_line_values(order, price)
+ if self.expense_id:
+ res.update({'product_uom_qty': self.expense_id.quantity})
+ return res
diff --git a/addons/sale_expense/tests/test_reinvoice.py b/addons/sale_expense/tests/test_reinvoice.py
index 0efe34c6dfb..c98b8e0ccaf 100644
--- a/addons/sale_expense/tests/test_reinvoice.py
+++ b/addons/sale_expense/tests/test_reinvoice.py
@@ -95,17 +95,17 @@ class TestReInvoice(TestExpenseCommon, TestSaleCommon):
# Expense lines:
{
'qty_delivered': 1.0,
- 'product_uom_qty': 0.0,
+ 'product_uom_qty': 1.0,
'is_expense': True,
},
{
'qty_delivered': 3.0,
- 'product_uom_qty': 0.0,
+ 'product_uom_qty': 1.0,
'is_expense': True,
},
{
'qty_delivered': 1.0,
- 'product_uom_qty': 0.0,
+ 'product_uom_qty': 1.0,
'is_expense': True,
},
])
diff --git a/addons/sale_expense/tests/test_sale_expense.py b/addons/sale_expense/tests/test_sale_expense.py
index 47a17cf6225..cb969636278 100644
--- a/addons/sale_expense/tests/test_sale_expense.py
+++ b/addons/sale_expense/tests/test_sale_expense.py
@@ -55,7 +55,7 @@ class TestSaleExpense(TestExpenseCommon, TestSaleCommon):
self.assertIn(self.company_data['product_delivery_cost'], so.mapped('order_line.product_id'), 'Sale Expense: expense product should be in so')
sol = so.order_line.filtered(lambda sol: sol.product_id.id == self.company_data['product_delivery_cost'].id)
self.assertEqual((sol.price_unit, sol.qty_delivered), (621.54, 1.0), 'Sale Expense: error when invoicing an expense at cost')
- self.assertEqual(so.amount_total, init_price, 'Sale Expense: price of so not updated after adding expense')
+ self.assertEqual(so.amount_total, init_price + sol.price_unit, 'Sale Expense: price of so should be updated after adding expense')
# create some expense and validate it (expense at sale price)
init_price = so.amount_total
@@ -94,7 +94,7 @@ class TestSaleExpense(TestExpenseCommon, TestSaleCommon):
self.assertIn(prod_exp_2, so.mapped('order_line.product_id'), 'Sale Expense: expense product should be in so')
sol = so.order_line.filtered(lambda sol: sol.product_id.id == prod_exp_2.id)
self.assertEqual((sol.price_unit, sol.qty_delivered), (prod_exp_2.list_price, 100.0), 'Sale Expense: error when invoicing an expense at cost')
- self.assertEqual(so.amount_total, init_price, 'Sale Expense: price of so not updated after adding expense')
+ self.assertEqual(so.amount_untaxed, init_price + (prod_exp_2.list_price * 100.0), 'Sale Expense: price of so should be updated after adding expense')
# self.assertTrue(so.invoice_status, 'no', 'Sale Expense: expenses should not impact the invoice_status of the so')
# both expenses should be invoiced