[FIX] stock_account: prevent reconcile move_lines in draft

Steps to reproduce:
- create two storable products (Great Product - Super Product) - automated avco
- create rfq with the two products - confirm -receive products
- create Bill - set qty of one Great Product to 0 -> save
- create bill for the Great Product - confirm

Issue:
User Error You can only reconcile posted entries

Cause:

`_get_all_related_aml()` fetches all aml related to the `stock_moves` with the product in the bill we want to post.
It retrieves the aml of the bill in which we have put the product quantity to 0 but that it is still in draft.
And we try to reconcile this draft move_line in
https://github.com/odoo/odoo/blob/d0fdc38385f5f259da259d21e9137494e6d7c17d/addons/account/models/account_move_line.py#L2308

Solution:
filter the `product_account_moves(_lines)` so we don't take into account moves that are still in draft

opw-3180209

closes odoo/odoo#114328

X-original-commit: b1a74a1841c05e4e37643e17f6b97dfff11555cd
Signed-off-by: Adrien Widart <awt@odoo.com>
This commit is contained in:
Yolann Sabaux
2023-03-03 17:05:43 +01:00
parent f2c0bc321b
commit c823f477aa
2 changed files with 53 additions and 2 deletions
@@ -5,7 +5,7 @@ from freezegun import freeze_time
from odoo.addons.stock_account.tests.test_anglo_saxon_valuation_reconciliation_common import ValuationReconciliationTestCommon
from odoo.tests.common import Form, tagged
from odoo import fields
from odoo import Command, fields
@@ -391,3 +391,54 @@ class TestValuationReconciliation(ValuationReconciliationTestCommon):
{'debit': 0.0, 'credit': 50.0, 'amount_currency': -100.0, 'account_id': cash_basis_transfer_account.id},
{'debit': 50.0, 'credit': 0.0, 'amount_currency': 100.0, 'account_id': tax_account_1.id},
])
def test_reconciliation_differed_billing(self):
"""
Test whether products received billed at different time will be correctly reconciled
valuation: automated
- create a rfq
- receive products
- create bill - set quantity of product A = 0 - save
- create bill - confirm
-> the reconciliation should not take into account the lines of the first bill
"""
date_po_and_delivery = '2022-03-02'
self.product_a.write({
'categ_id': self.stock_account_product_categ,
'detailed_type': 'product',
})
self.product_b.write({
'categ_id': self.stock_account_product_categ,
'detailed_type': 'product',
})
purchase_order = self.env['purchase.order'].create({
'currency_id': self.currency_data['currency'].id,
'order_line': [
Command.create({
'name': self.product_a.name,
'product_id': self.product_a.id,
'product_qty': 1,
}),
Command.create({
'name': self.product_b.name,
'product_id': self.product_b.id,
'product_qty': 1,
}),
],
'partner_id': self.partner_a.id,
})
purchase_order.button_confirm()
self._process_pickings(purchase_order.picking_ids, date=date_po_and_delivery)
bill_1 = self._create_invoice_for_po(purchase_order, date_po_and_delivery)
move_form = Form(bill_1)
with move_form.invoice_line_ids.edit(0) as line_form:
line_form.quantity = 0
move_form.save()
bill_2 = self._create_invoice_for_po(purchase_order, date=date_po_and_delivery)
bill_2.action_post()
aml = bill_2.line_ids.filtered(lambda line: line.display_type == "product")
pol = purchase_order.order_line
self.assertRecordValues(pol, [{'qty_invoiced': line.qty_received} for line in pol])
self.assertRecordValues(aml, [{'reconciled': True} for line in aml])
+1 -1
View File
@@ -233,7 +233,7 @@ class AccountMove(models.Model):
# Search for anglo-saxon lines linked to the product in the stock moves.
product_stock_moves = stock_moves.filtered(lambda stock_move: stock_move.product_id == prod)
product_account_moves |= product_stock_moves._get_all_related_aml().filtered(
lambda line: line.account_id == product_interim_account and not line.reconciled
lambda line: line.account_id == product_interim_account and not line.reconciled and line.move_id.state == "posted"
)
# Reconcile.