Skip to content

Commit

Permalink
[FIX] stock_landed_costs: reconciliation with vendor bill
Browse files Browse the repository at this point in the history
in anglo saxon accounting
- receipt products through an rfq
- when creating the vendor bill of the rfq, directly add a landed costs
  product
- post the vendor bill then create the landed cost, validate the landed
  cost
- the aml of the LC is not reconciled with the aml of the vendor bill
  for the lc product because the "You are trying to reconcile some
  entries that are already reconciled." error.

We fix this by filtering out the already reconciled aml.
Not that the flow is behaving as expected if the landed cost is created
in another vendor bill, such as the tests were doing. We thus add
another test.

opw-2184988
  • Loading branch information
sle-odoo committed Feb 5, 2020
1 parent 980d1b1 commit d8c34c6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion addons/stock_landed_costs/models/stock_landed_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def button_validate(self):
for product in cost.cost_lines.product_id:
accounts = product.product_tmpl_id.get_product_accounts()
input_account = accounts['stock_input']
all_amls.filtered(lambda aml: aml.account_id == input_account).reconcile()
all_amls.filtered(lambda aml: aml.account_id == input_account and not aml.full_reconcile_id).reconcile()
return True

def _check_sum(self):
Expand Down
52 changes: 52 additions & 0 deletions addons/stock_landed_costs/tests/test_stockvaluationlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,58 @@ def test_vendor_bill_flow_anglo_saxon_1(self):
self.assertEqual(self.product1.quantity_svl, 10)
self.assertEqual(self.product1.value_svl, 150)

def test_vendor_bill_flow_anglo_saxon_2(self):
"""In anglo saxon accounting, receive 10@10 and invoice with the addition of 1@50 as a
landed costs and create a linked landed costs record.
"""
self.env.company.anglo_saxon_accounting = True

# Create an RFQ for self.product1, 10@10
rfq = Form(self.env['purchase.order'])
rfq.partner_id = self.vendor1

with rfq.order_line.new() as po_line:
po_line.product_id = self.product1
po_line.price_unit = 10
po_line.product_qty = 10
po_line.taxes_id.clear()

rfq = rfq.save()
rfq.button_confirm()

# Process the receipt
receipt = rfq.picking_ids
wiz = receipt.button_validate()
wiz = self.env['stock.immediate.transfer'].browse(wiz['res_id']).process()
self.assertEqual(rfq.order_line.qty_received, 10)

input_aml = self._get_stock_input_move_lines()[-1]
self.assertEqual(input_aml.debit, 0)
self.assertEqual(input_aml.credit, 100)
valuation_aml = self._get_stock_valuation_move_lines()[-1]
self.assertEqual(valuation_aml.debit, 100)
self.assertEqual(valuation_aml.credit, 0)

# Create a vebdor bill for the RFQ and add to it the landed cost
action = rfq.action_view_invoice()
vb = Form(self.env['account.move'].with_context(action['context']))
with vb.invoice_line_ids.new() as inv_line:
inv_line.product_id = self.productlc1
inv_line.price_unit = 50
inv_line.is_landed_costs_line = True
vb = vb.save()
vb.post()

action = vb.button_create_landed_costs()
lc = Form(self.env[action['res_model']].browse(action['res_id']))
lc.picking_ids.add(receipt)
lc = lc.save()
lc.button_validate()

# Check reconciliation of input aml of lc
lc_input_aml = lc.account_move_id.line_ids.filtered(lambda aml: aml.account_id == self.stock_input_account)
self.assertTrue(len(lc_input_aml.full_reconcile_id), 1)

def test_vendor_bill_flow_continental_1(self):
"""In continental accounting, receive 10@10 and invoice. Then invoice 1@50 as a landed costs
and create a linked landed costs record.
Expand Down

0 comments on commit d8c34c6

Please sign in to comment.