mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[IMP] rma_purchase: add test return_and_refund_diff_price
This commit is contained in:
committed by
JasminSForgeFlow
parent
d77729f400
commit
76dd218b57
@@ -17,6 +17,10 @@ class TestRmaStockAccountPurchase(TestRmaStockAccount):
|
|||||||
cls.rma_operation_supplier_refund = cls.env.ref(
|
cls.rma_operation_supplier_refund = cls.env.ref(
|
||||||
"rma_account.rma_operation_supplier_refund"
|
"rma_account.rma_operation_supplier_refund"
|
||||||
)
|
)
|
||||||
|
acc_type = cls._create_account_type("expense", "other")
|
||||||
|
cls.account_price_diff = cls._create_account(
|
||||||
|
acc_type, "Refund Price Difference Expense", "rpde", cls.company, False
|
||||||
|
)
|
||||||
|
|
||||||
def test_01_cost_from_po_move(self):
|
def test_01_cost_from_po_move(self):
|
||||||
"""
|
"""
|
||||||
@@ -146,3 +150,77 @@ class TestRmaStockAccountPurchase(TestRmaStockAccount):
|
|||||||
)
|
)
|
||||||
self.assertEqual(sum(grni_amls.mapped("balance")), 0.0)
|
self.assertEqual(sum(grni_amls.mapped("balance")), 0.0)
|
||||||
self.assertTrue(all(grni_amls.mapped("reconciled")))
|
self.assertTrue(all(grni_amls.mapped("reconciled")))
|
||||||
|
|
||||||
|
def test_03_return_and_refund_diff_price(self):
|
||||||
|
"""
|
||||||
|
Purchase a product.
|
||||||
|
Then create an RMA to return it and get the refund from the supplier with
|
||||||
|
a different price than the original purchase price
|
||||||
|
"""
|
||||||
|
self.product_fifo_1.categ_id.update(
|
||||||
|
{
|
||||||
|
"property_account_creditor_price_difference_categ": self.account_price_diff
|
||||||
|
}
|
||||||
|
)
|
||||||
|
self.product_fifo_1.standard_price = 1234
|
||||||
|
po = self.po_model.create(
|
||||||
|
{
|
||||||
|
"partner_id": self.partner_id.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
pol_1 = self.pol_model.create(
|
||||||
|
{
|
||||||
|
"name": self.product_fifo_1.name,
|
||||||
|
"order_id": po.id,
|
||||||
|
"product_id": self.product_fifo_1.id,
|
||||||
|
"product_qty": 10.0,
|
||||||
|
"product_uom": self.product_fifo_1.uom_id.id,
|
||||||
|
"price_unit": 100.0,
|
||||||
|
"date_planned": Datetime.now(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
po.button_confirm()
|
||||||
|
self._do_picking(po.picking_ids)
|
||||||
|
self.product_fifo_1.standard_price = 1234 # this should not be taken
|
||||||
|
supplier_view = self.env.ref("rma_purchase.view_rma_line_form")
|
||||||
|
rma_line = Form(
|
||||||
|
self.rma_line.with_context(supplier=1).with_user(self.rma_basic_user),
|
||||||
|
view=supplier_view.id,
|
||||||
|
)
|
||||||
|
rma_line.partner_id = po.partner_id
|
||||||
|
rma_line.purchase_order_line_id = pol_1
|
||||||
|
rma_line.price_unit = 4356
|
||||||
|
rma_line.operation_id = self.rma_operation_supplier_refund
|
||||||
|
rma_line = rma_line.save()
|
||||||
|
rma_line.action_rma_to_approve()
|
||||||
|
self._deliver_rma(rma_line)
|
||||||
|
|
||||||
|
with Form(
|
||||||
|
self.env["account.move"].with_context(default_move_type="in_refund")
|
||||||
|
) as bill_form:
|
||||||
|
bill_form.partner_id = rma_line.partner_id
|
||||||
|
bill_form.invoice_date = Date.today()
|
||||||
|
bill_form.add_rma_line_id = rma_line
|
||||||
|
bill = bill_form.save()
|
||||||
|
bill_form = Form(bill)
|
||||||
|
with bill_form.invoice_line_ids.edit(0) as line_form:
|
||||||
|
line_form.price_unit = 110
|
||||||
|
bill = bill_form.save()
|
||||||
|
bill.action_post()
|
||||||
|
self.assertEqual(len(bill.invoice_line_ids), 1)
|
||||||
|
self.assertEqual(bill.invoice_line_ids.rma_line_id, rma_line)
|
||||||
|
grni_amls = self.env["account.move.line"].search(
|
||||||
|
[
|
||||||
|
("account_id", "=", self.account_grni.id),
|
||||||
|
("rma_line_id", "=", rma_line.id),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
self.assertEqual(sum(grni_amls.mapped("balance")), 0.0)
|
||||||
|
self.assertTrue(all(grni_amls.mapped("reconciled")))
|
||||||
|
price_diff_amls = self.env["account.move.line"].search(
|
||||||
|
[
|
||||||
|
("account_id", "=", self.account_price_diff.id),
|
||||||
|
("rma_line_id", "=", rma_line.id),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
self.assertEqual(sum(price_diff_amls.mapped("balance")), -100)
|
||||||
|
|||||||
Reference in New Issue
Block a user