mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
@@ -221,6 +221,20 @@ class AccountPaymentOrder(models.Model):
|
||||
)
|
||||
)
|
||||
|
||||
@api.constrains("payment_line_ids")
|
||||
def _check_payment_lines(self):
|
||||
for order in self:
|
||||
move_line_ids = [x.move_line_id.id for x in order.payment_line_ids]
|
||||
if len(move_line_ids) != len(set(move_line_ids)):
|
||||
raise ValidationError(
|
||||
_(
|
||||
"There are several lines pointing to the same pending "
|
||||
"balance. This is probably caused by a manual line creation. "
|
||||
"Please remove this duplication for being able to save the "
|
||||
"order."
|
||||
)
|
||||
)
|
||||
|
||||
@api.depends("payment_line_ids", "payment_line_ids.amount_company_currency")
|
||||
def _compute_total(self):
|
||||
for rec in self:
|
||||
|
||||
@@ -83,6 +83,16 @@ class TestPaymentOrderInboundBase(AccountTestInvoicingCommon):
|
||||
|
||||
@tagged("-at_install", "post_install")
|
||||
class TestPaymentOrderInbound(TestPaymentOrderInboundBase):
|
||||
def _line_creation(self, inbound_order):
|
||||
vals = {
|
||||
"order_id": inbound_order.id,
|
||||
"partner_id": self.partner.id,
|
||||
"currency_id": inbound_order.payment_mode_id.company_id.currency_id.id,
|
||||
"amount_currency": 200.38,
|
||||
"move_line_id": self.invoice.invoice_line_ids[0].id,
|
||||
}
|
||||
return self.env["account.payment.line"].create(vals)
|
||||
|
||||
def test_constrains_type(self):
|
||||
with self.assertRaises(ValidationError):
|
||||
order = self.env["account.payment.order"].create(
|
||||
@@ -136,3 +146,15 @@ class TestPaymentOrderInbound(TestPaymentOrderInboundBase):
|
||||
payment_order.cancel2draft()
|
||||
payment_order.unlink()
|
||||
self.assertEqual(len(self.payment_order_obj.search(self.domain)), 0)
|
||||
|
||||
def test_constrains_payment_line(self):
|
||||
inbound_order = self.env["account.payment.order"].create(
|
||||
{"payment_mode_id": self.inbound_mode.id, "journal_id": self.journal.id}
|
||||
)
|
||||
# Create two payment lines with the same
|
||||
# move line id and try to assign them to inbound order
|
||||
payment_line_1 = self._line_creation(inbound_order)
|
||||
inbound_order.payment_line_ids |= payment_line_1
|
||||
with self.assertRaises(ValidationError):
|
||||
payment_line_2 = self._line_creation(inbound_order)
|
||||
inbound_order.payment_line_ids |= payment_line_2
|
||||
|
||||
@@ -225,6 +225,16 @@ class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase):
|
||||
self.assertEqual(order.move_ids[0].date, order.payment_ids[0].date)
|
||||
self.assertEqual(order.state, "uploaded")
|
||||
|
||||
def _line_creation(self, outbound_order):
|
||||
vals = {
|
||||
"order_id": outbound_order.id,
|
||||
"partner_id": self.partner.id,
|
||||
"currency_id": outbound_order.payment_mode_id.company_id.currency_id.id,
|
||||
"amount_currency": 200.38,
|
||||
"move_line_id": self.invoice.invoice_line_ids[0].id,
|
||||
}
|
||||
return self.env["account.payment.line"].create(vals)
|
||||
|
||||
def test_account_payment_line_creation_without_payment_mode(self):
|
||||
self.invoice.payment_mode_id = False
|
||||
self.invoice.action_post()
|
||||
@@ -276,6 +286,13 @@ class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase):
|
||||
)
|
||||
with self.assertRaises(ValidationError):
|
||||
outbound_order.date_scheduled = date.today() - timedelta(days=2)
|
||||
# Create two payment lines with the same
|
||||
# move line id and try to assign them to outbound order
|
||||
payment_line_1 = self._line_creation(outbound_order)
|
||||
outbound_order.payment_line_ids |= payment_line_1
|
||||
with self.assertRaises(ValidationError):
|
||||
payment_line_2 = self._line_creation(outbound_order)
|
||||
outbound_order.payment_line_ids |= payment_line_2
|
||||
|
||||
def test_invoice_communication_01(self):
|
||||
self.assertEqual(
|
||||
|
||||
Reference in New Issue
Block a user