[FIX] stock_landed_costs: reconcile LC after posting the bill
Steps to reproduce: - Create a PO (fifo automated product) - Recieve product - Create the bill and add the landed cost product to it - Create the landed cost before posting the bill - Post the bill Bug: when creating the landed costs if the bill is already posted the created amls are reconciled otherwise they aren't Fix: reconcile the landed costs amls after posting the bill opw-3377088 closes odoo/odoo#134170 X-original-commit: 07666e46b658dd9c55abfcd2d94f1c033ac9c04f Signed-off-by: William Henrotin (whe) <whe@odoo.com> Signed-off-by: Walid Hanniche (waha) <waha@odoo.com>16.0
parent
0d67107ab2
commit
1f32740505
|
@ -46,6 +46,11 @@ class AccountMove(models.Model):
|
|||
views = [(self.env.ref('stock_landed_costs.view_stock_landed_cost_tree2').id, 'tree'), (False, 'form'), (False, 'kanban')]
|
||||
return dict(action, domain=domain, context=context, views=views)
|
||||
|
||||
def _post(self, soft=True):
|
||||
posted = super()._post(soft)
|
||||
posted.sudo().landed_costs_ids.reconcile_landed_cost()
|
||||
return posted
|
||||
|
||||
|
||||
class AccountMoveLine(models.Model):
|
||||
_inherit = 'account.move.line'
|
||||
|
|
|
@ -177,7 +177,11 @@ class StockLandedCost(models.Model):
|
|||
cost.write(cost_vals)
|
||||
if cost.account_move_id:
|
||||
move._post()
|
||||
cost.reconcile_landed_cost()
|
||||
return True
|
||||
|
||||
def reconcile_landed_cost(self):
|
||||
for cost in self:
|
||||
if cost.vendor_bill_id and cost.vendor_bill_id.state == 'posted' and cost.company_id.anglo_saxon_accounting:
|
||||
all_amls = cost.vendor_bill_id.line_ids | cost.account_move_id.line_ids
|
||||
for product in cost.cost_lines.product_id:
|
||||
|
@ -185,8 +189,6 @@ class StockLandedCost(models.Model):
|
|||
input_account = accounts['stock_input']
|
||||
all_amls.filtered(lambda aml: aml.account_id == input_account and not aml.reconciled).reconcile()
|
||||
|
||||
return True
|
||||
|
||||
def get_valuation_lines(self):
|
||||
self.ensure_one()
|
||||
lines = []
|
||||
|
|
|
@ -5,6 +5,7 @@ from odoo.addons.stock_landed_costs.tests.common import TestStockLandedCostsComm
|
|||
from odoo.addons.stock_landed_costs.tests.test_stockvaluationlayer import TestStockValuationLCCommon
|
||||
from odoo.addons.stock_account.tests.test_stockvaluation import _create_accounting_data
|
||||
|
||||
from odoo.fields import Date
|
||||
from odoo.tests import tagged, Form
|
||||
|
||||
|
||||
|
@ -429,3 +430,70 @@ class TestLandedCostsWithPurchaseAndInv(TestStockValuationLCCommon):
|
|||
# Check nothing was posted in the stock valuation account.
|
||||
price_diff_aml = self.env['account.move.line'].search([('account_id', '=', stock_valuation_account.id), ('move_id', '=', move.id)])
|
||||
self.assertEqual(len(price_diff_aml), 0, "No line should have been generated in the stock valuation account about the price difference.")
|
||||
|
||||
def test_invoice_after_lc_amls(self):
|
||||
self.env.company.anglo_saxon_accounting = True
|
||||
self.landed_cost.landed_cost_ok = True
|
||||
self.landed_cost.categ_id.property_cost_method = 'fifo'
|
||||
self.landed_cost.categ_id.property_valuation = 'real_time'
|
||||
|
||||
# Create PO
|
||||
po = self.env['purchase.order'].create({
|
||||
'partner_id': self.partner_a.id,
|
||||
'currency_id': self.company_data['currency'].id,
|
||||
'order_line': [
|
||||
(0, 0, {
|
||||
'name': self.product_a.name,
|
||||
'product_id': self.product_a.id,
|
||||
'product_qty': 1.0,
|
||||
'product_uom': self.product_a.uom_po_id.id,
|
||||
'price_unit': 100.0,
|
||||
'taxes_id': False,
|
||||
}),
|
||||
(0, 0, {
|
||||
'name': self.landed_cost.name,
|
||||
'product_id': self.landed_cost.id,
|
||||
'product_qty': 1.0,
|
||||
'price_unit': 100.0,
|
||||
}),
|
||||
],
|
||||
})
|
||||
po.button_confirm()
|
||||
|
||||
receipt = po.picking_ids
|
||||
receipt.move_ids.quantity_done = 1
|
||||
receipt.button_validate()
|
||||
po.order_line[1].qty_received = 1
|
||||
|
||||
po.action_create_invoice()
|
||||
bill = po.invoice_ids
|
||||
|
||||
# Create and validate LC
|
||||
lc = self.env['stock.landed.cost'].create(dict(
|
||||
picking_ids=[(6, 0, [receipt.id])],
|
||||
account_journal_id=self.stock_journal.id,
|
||||
cost_lines=[
|
||||
(0, 0, {
|
||||
'name': 'equal split',
|
||||
'split_method': 'equal',
|
||||
'price_unit': 100,
|
||||
'product_id': self.landed_cost.id,
|
||||
}),
|
||||
],
|
||||
))
|
||||
lc.compute_landed_cost()
|
||||
lc.button_validate()
|
||||
|
||||
user = self.env['res.users'].create({
|
||||
'name': 'User h',
|
||||
'login': 'usher',
|
||||
'email': 'usher@yourcompany.com',
|
||||
'groups_id': [(6, 0, [self.env.ref('account.group_account_invoice').id])]
|
||||
})
|
||||
# Post the bill
|
||||
bill.landed_costs_ids = [(6, 0, lc.id)]
|
||||
bill.invoice_date = Date.today()
|
||||
bill.with_user(user)._post()
|
||||
|
||||
landed_cost_aml = bill.invoice_line_ids.filtered(lambda l: l.product_id == self.landed_cost)
|
||||
self.assertTrue(landed_cost_aml.reconciled)
|
||||
|
|
Loading…
Reference in New Issue