Skip to content

Commit

Permalink
[IMP] rma_purchase: add test return_and_refund_diff_price
Browse files Browse the repository at this point in the history
  • Loading branch information
mariadforgeflow authored and AaronHForgeFlow committed Aug 8, 2024
1 parent 2db61b2 commit b712dec
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions rma_purchase/tests/test_rma_stock_account_purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def setUpClass(cls):
cls.rma_operation_supplier_refund = cls.env.ref(
"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):
"""
Expand Down Expand Up @@ -146,3 +150,77 @@ def test_02_return_and_refund_ref_po(self):
)
self.assertEqual(sum(grni_amls.mapped("balance")), 0.0)
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)

0 comments on commit b712dec

Please sign in to comment.