[FIX] stock_account: create AML for SML owned by company

If a picking is owned by the company and if the user receives a FIFO
product, a SVL will be created without any journal entry

To reproduce the issue:
(Need account_accountant)
1. In Settings, enable "Consignment"
2. Create a product category PC:
    - Costing Method: FIFO
    - Inventory Valuation: Automated
3. Create a product P:
    - Type: Storable
    - Category: PC
    - Cost: 1
4. Create and validate a receipt:
    - Owner: <The company of the picking>
    - With: 1 x P
5. Open the generated SVL

Error: There isn't any journal entry associated with the SVL

When validating the picking, a method filters the SML that will be
considered during the SVL creation process. This method filters out the
SML that has an owner and if this owner is not the company:
https://github.com/odoo/odoo/blob/f8e2f2a4836d23fe507cad3bd5cac92d41ca91a3/addons/stock_account/models/stock_move.py#L69-L70

However, the filter in the journal entries creation is not that accurate
and does not correspond to its comment line:
https://github.com/odoo/odoo/blob/f8e2f2a4836d23fe507cad3bd5cac92d41ca91a3/addons/stock_account/models/stock_move.py#L475-L476

OPW-2859144

closes odoo/odoo#92716

X-original-commit: 13d4963d10e14c0295a1c7abeefd52b070cd4a58
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Adrien Widart <awt@odoo.com>
This commit is contained in:
Adrien Widart
2022-06-02 08:57:59 +02:00
parent ed586dfc68
commit 064ce8dcfe
2 changed files with 32 additions and 1 deletions
+1 -1
View File
@@ -531,7 +531,7 @@ class StockMove(models.Model):
if self.product_id.type != 'product':
# no stock valuation for consumable products
return am_vals
if self.restrict_partner_id:
if self.restrict_partner_id and self.restrict_partner_id != self.company_id.partner_id:
# if the move isn't owned by the company, we don't make any valuation
return am_vals
@@ -3904,3 +3904,34 @@ class TestStockValuation(TransactionCase):
report_value_2 = report_for_company_2._get_report_values(docids=self.product1.ids)
self.assertEqual(report_value_1['docs']['value'], "U 50.00")
self.assertEqual(report_value_2['docs']['value'], "48.00 DD")
def test_fifo_and_sml_owned_by_company(self):
"""
When receiving a FIFO product, if the picking is owned by the company,
there should be a SVL and an account move linked to the product SM
"""
self.product1.categ_id.property_cost_method = 'fifo'
receipt = self.env['stock.picking'].create({
'location_id': self.supplier_location.id,
'location_dest_id': self.stock_location.id,
'picking_type_id': self.env.ref('stock.picking_type_in').id,
'owner_id': self.env.company.partner_id.id,
})
move = self.env['stock.move'].create({
'picking_id': receipt.id,
'name': 'IN 1 @ 10',
'location_id': self.supplier_location.id,
'location_dest_id': self.stock_location.id,
'product_id': self.product1.id,
'product_uom': self.uom_unit.id,
'product_uom_qty': 1.0,
'price_unit': 10,
})
receipt.action_confirm()
move.quantity_done = 1
receipt.button_validate()
self.assertEqual(move.stock_valuation_layer_ids.value, 10)
self.assertEqual(move.stock_valuation_layer_ids.account_move_id.amount_total, 10)