summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwan <wan@odoo.com>2019-07-30 12:35:22 +0000
committerwan <wan@odoo.com>2019-07-31 14:04:15 +0000
commit13a535a0918f6f75d8c631a465fbc9238ea954bf (patch)
treeba26c5ab3cc65e1b548d63dc2a0b1b3c13cc3251
parent22930162727a22db9cb6cb300eaa0852e3f5085a (diff)
[FIX] point_of_sale: anglosaxon prices werent correctly calcuated
Reproduce: 1. I create a product with fifo and real_time valuation (make sure the invoicing policy is 'delivered' and make it available in pos). 2. set the cost of the product to be 5.0 and sale price to be 10.0. 3. I update its inventory and set 5 items. -> total valuation of 25. 4. I change the cost of the product to 1.0. 5. I update again the quantity to 10, making the valuation of the product to 30.0. 6. I configure point of sale to allow invoicing. 7. Open a pos session then sell 7 items of the product (invoice the order). 8. Since the product is fifo, this means that the cost of goods sold is 5 * 5.0 + 2 * 1.0 = 27.0. 9. The correct expense account line should have balance of 27.0. 10. The correct output account line should have balance of -27.0 However, instead of 27.0 as stock valuation amount, the value in the pos.order invoice is currently 7 * 2.0 = 14 -- and this is wrong. It is not taking into account the value of the previous stock Solution: Missing refactoring from https://github.com/odoo/odoo/commit/14812f41710282f9923078f6764323086500ae85 closes odoo/odoo#35335 Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
-rw-r--r--addons/point_of_sale/models/pos_order.py14
-rw-r--r--addons/point_of_sale/tests/test_anglo_saxon.py59
2 files changed, 63 insertions, 10 deletions
diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py
index 99acaa84e9a..3803396d69d 100644
--- a/addons/point_of_sale/models/pos_order.py
+++ b/addons/point_of_sale/models/pos_order.py
@@ -446,15 +446,11 @@ class PosOrder(models.Model):
return True
def _get_pos_anglo_saxon_price_unit(self, product, partner_id, quantity):
- price_unit = product._stock_account_get_anglo_saxon_price_unit()
- if product._get_invoice_policy() == "delivery":
- moves = self.filtered(lambda o: o.partner_id.id == partner_id)\
- .mapped('picking_id.move_lines')\
- .filtered(lambda m: m.product_id.id == product.id)\
- .sorted(lambda x: x.date)
- average_price_unit = product._compute_average_price(0, quantity, moves)
- price_unit = average_price_unit or price_unit
- # In the SO part, the entries will be inverted by function compute_invoice_totals
+ moves = self.filtered(lambda o: o.partner_id.id == partner_id)\
+ .mapped('picking_id.move_lines')\
+ .filtered(lambda m: m.product_id.id == product.id)\
+ .sorted(lambda x: x.date)
+ price_unit = product._compute_average_price(0, quantity, moves)
return - price_unit
def _reconcile_payments(self):
diff --git a/addons/point_of_sale/tests/test_anglo_saxon.py b/addons/point_of_sale/tests/test_anglo_saxon.py
index 2020121cc45..aea6a6c44bc 100644
--- a/addons/point_of_sale/tests/test_anglo_saxon.py
+++ b/addons/point_of_sale/tests/test_anglo_saxon.py
@@ -15,6 +15,7 @@ class TestAngloSaxonCommon(common.TransactionCase):
self.PosOrder = self.env['pos.order']
self.Statement = self.env['account.bank.statement']
self.company = self.env.ref('base.main_company')
+ self.warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1)
self.product = self.env.ref('product.product_product_3')
self.partner = self.env.ref('base.res_partner_1')
self.category = self.env.ref('product.product_category_1')
@@ -113,4 +114,60 @@ class TestAngloSaxonFlow(TestAngloSaxonCommon):
aml_output = aml.filtered(lambda l: l.account_id.id == account_output.id)
aml_expense = aml.filtered(lambda l: l.account_id.id == expense_account.id)
self.assertEqual(aml_output.credit, self.product.standard_price, "Cost of Good Sold entry missing or mismatching")
- self.assertEqual(aml_expense.debit, self.product.standard_price, "Cost of Good Sold entry missing or mismatching") \ No newline at end of file
+ self.assertEqual(aml_expense.debit, self.product.standard_price, "Cost of Good Sold entry missing or mismatching")
+
+ def test_2041208(self):
+ # check fifo Costing Method of product.category
+ self.product.categ_id.property_cost_method = 'fifo'
+ self.product.standard_price = 5.0
+ self.env['stock.quant'].with_context(inventory_mode=True).create({
+ 'product_id': self.product.id,
+ 'inventory_quantity': 5.0,
+ 'location_id': self.warehouse.lot_stock_id.id,
+ })
+ self.product.standard_price = 1.0
+ self.env['stock.quant'].with_context(inventory_mode=True).create({
+ 'product_id': self.product.id,
+ 'inventory_quantity': 10.0,
+ 'location_id': self.warehouse.lot_stock_id.id,
+ })
+ self.assertEqual(self.product.value_svl, 30, "Value should be (5*5 + 5*1) = 30")
+ self.assertEqual(self.product.quantity_svl, 10)
+
+ self.pos_config.open_session_cb()
+ self.pos_config.module_account = True
+
+ self.pos_order_pos0 = self.PosOrder.create({
+ 'company_id': self.company.id,
+ 'partner_id': self.partner.id,
+ 'pricelist_id': self.company.partner_id.property_product_pricelist.id,
+ 'session_id': self.pos_config.current_session_id.id,
+ 'lines': [(0, 0, {
+ 'name': "OL/0001",
+ 'product_id': self.product.id,
+ 'price_unit': 450,
+ 'discount': 0.0,
+ 'qty': 7.0,
+ 'price_subtotal': 7 * 450,
+ 'price_subtotal_incl': 7 * 450,
+ })],
+ 'amount_total': 7 * 450,
+ 'amount_tax': 0,
+ 'amount_paid': 0,
+ 'amount_return': 0,
+ })
+
+ context_make_payment = {"active_ids": [self.pos_order_pos0.id], "active_id": self.pos_order_pos0.id}
+ self.pos_make_payment_0 = self.PosMakePayment.with_context(context_make_payment).create({
+ 'amount': 7 * 450.0,
+ 'journal_id': self.cash_journal.id,
+ })
+
+ # I click on the validate button to register the payment.
+ context_payment = {'active_id': self.pos_order_pos0.id}
+ self.pos_make_payment_0.with_context(context_payment).check()
+ current_session_id = self.pos_config.current_session_id
+ current_session_id.action_pos_session_validate()
+
+ line = self.pos_order_pos0.account_move.line_ids.filtered(lambda l: l.debit and l.account_id == self.category.property_account_expense_categ_id)
+ self.assertEqual(line.debit, 27, 'As it is a fifo product, the move\'s value should be 5*5 + 2*1')