Ecocentral/ecocentral#152: include in_refund invoices. rappel_pending readonly. vendor ref in invoice lines
This commit is contained in:
parent
4c07dd042d
commit
29ef56b800
5 changed files with 140 additions and 18 deletions
|
|
@ -69,7 +69,7 @@ class TestPurchaseRappel(AccountTestInvoicingCommon):
|
|||
}
|
||||
)
|
||||
|
||||
def _create_vendor_bill(self, partner, amount=1000.0, post=True):
|
||||
def _create_vendor_bill(self, partner, amount=1000.0, post=True, ref=None):
|
||||
move = self.init_invoice(
|
||||
"in_invoice",
|
||||
partner=partner,
|
||||
|
|
@ -77,6 +77,22 @@ class TestPurchaseRappel(AccountTestInvoicingCommon):
|
|||
post=False,
|
||||
)
|
||||
move.invoice_line_ids[0].price_unit = amount
|
||||
if ref is not None:
|
||||
move.ref = ref
|
||||
if post:
|
||||
move.action_post()
|
||||
return move
|
||||
|
||||
def _create_vendor_refund(self, partner, amount=200.0, post=True, ref=None):
|
||||
move = self.init_invoice(
|
||||
"in_refund",
|
||||
partner=partner,
|
||||
products=self.product_a,
|
||||
post=False,
|
||||
)
|
||||
move.invoice_line_ids[0].price_unit = amount
|
||||
if ref is not None:
|
||||
move.ref = ref
|
||||
if post:
|
||||
move.action_post()
|
||||
return move
|
||||
|
|
@ -236,3 +252,82 @@ class TestPurchaseRappel(AccountTestInvoicingCommon):
|
|||
)
|
||||
with self.assertRaises(UserError):
|
||||
wizard.action_create_rappel_invoices()
|
||||
|
||||
def test_wizard_vendor_ref_in_description(self):
|
||||
bill_with_ref = self._create_vendor_bill(
|
||||
self.vendor_rappel, amount=1000.0, ref="VENDOR-REF-001"
|
||||
)
|
||||
wizard = (
|
||||
self.env["account.move.rappel.wizard"]
|
||||
.with_context(active_ids=bill_with_ref.ids)
|
||||
.create({})
|
||||
)
|
||||
action = wizard.action_create_rappel_invoices()
|
||||
rappel_invoice = self.env["account.move"].browse(action["res_id"])
|
||||
line_name = rappel_invoice.invoice_line_ids[0].name
|
||||
self.assertIn("VENDOR-REF-001", line_name)
|
||||
self.assertNotIn(bill_with_ref.name, line_name)
|
||||
|
||||
bill_without_ref = self._create_vendor_bill(
|
||||
self.vendor_rappel, amount=1000.0, ref=None
|
||||
)
|
||||
wizard2 = (
|
||||
self.env["account.move.rappel.wizard"]
|
||||
.with_context(active_ids=bill_without_ref.ids)
|
||||
.create({})
|
||||
)
|
||||
action2 = wizard2.action_create_rappel_invoices()
|
||||
rappel_invoice2 = self.env["account.move"].browse(action2["res_id"])
|
||||
line_name2 = rappel_invoice2.invoice_line_ids[0].name
|
||||
self.assertIn(bill_without_ref.name, line_name2)
|
||||
|
||||
def test_wizard_includes_in_refund(self):
|
||||
bill = self._create_vendor_bill(self.vendor_rappel, amount=1000.0)
|
||||
refund = self._create_vendor_refund(self.vendor_rappel, amount=200.0)
|
||||
self.assertTrue(refund.rappel_pending)
|
||||
|
||||
wizard = (
|
||||
self.env["account.move.rappel.wizard"]
|
||||
.with_context(active_ids=(bill + refund).ids)
|
||||
.create({})
|
||||
)
|
||||
action = wizard.action_create_rappel_invoices()
|
||||
rappel_invoice = self.env["account.move"].browse(action["res_id"])
|
||||
|
||||
self.assertEqual(len(rappel_invoice.invoice_line_ids), 2)
|
||||
amounts = sorted(rappel_invoice.invoice_line_ids.mapped("price_unit"))
|
||||
self.assertEqual(amounts, [-10.0, 50.0])
|
||||
self.assertFalse(bill.rappel_pending)
|
||||
self.assertFalse(refund.rappel_pending)
|
||||
|
||||
def test_wizard_refund_subtracts_commission(self):
|
||||
bill = self._create_vendor_bill(self.vendor_rappel, amount=1000.0)
|
||||
refund = self._create_vendor_refund(self.vendor_rappel, amount=200.0)
|
||||
|
||||
wizard = (
|
||||
self.env["account.move.rappel.wizard"]
|
||||
.with_context(active_ids=(bill + refund).ids)
|
||||
.create({})
|
||||
)
|
||||
action = wizard.action_create_rappel_invoices()
|
||||
rappel_invoice = self.env["account.move"].browse(action["res_id"])
|
||||
|
||||
self.assertEqual(len(rappel_invoice.invoice_line_ids), 2)
|
||||
line_by_sign = {
|
||||
line.price_unit > 0: line for line in rappel_invoice.invoice_line_ids
|
||||
}
|
||||
self.assertEqual(line_by_sign[True].price_unit, 50.0)
|
||||
self.assertEqual(line_by_sign[False].price_unit, -10.0)
|
||||
self.assertEqual(rappel_invoice.amount_untaxed, 40.0)
|
||||
self.assertIn("Refund", line_by_sign[False].name)
|
||||
|
||||
def test_rappel_pending_set_on_refund_create(self):
|
||||
refund = self._create_vendor_refund(
|
||||
self.vendor_rappel, amount=200.0, post=False
|
||||
)
|
||||
self.assertTrue(refund.rappel_pending)
|
||||
|
||||
refund_no_rappel = self._create_vendor_refund(
|
||||
self.vendor_no_rappel, amount=200.0, post=False
|
||||
)
|
||||
self.assertFalse(refund_no_rappel.rappel_pending)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue