Skip to content

Commit

Permalink
[WIP] backport to v14
Browse files Browse the repository at this point in the history
  • Loading branch information
Clément Mombereau committed Jan 24, 2025
1 parent 4b4b186 commit 06b1d70
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 41 deletions.
13 changes: 7 additions & 6 deletions sale_import_base/models/sale_channel_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ def _create_payment(self, sale_order, data):
if not data.get("payment"):
return
pmt_data = data["payment"]
provider = self.env["payment.provider"].search([("ref", "=", pmt_data["mode"])])
if not provider:
acquirer = self.env["payment.acquirer"].search([("ref", "=", pmt_data["mode"])])
if not acquirer:
raise ValidationError(
_("Missing Provider with code {}").format(pmt_data["mode"])
_("Missing Acquirer_id with code {}").format(pmt_data["mode"])
)
if pmt_data.get("currency_code"):
currency = self.env["res.currency"].search(
Expand All @@ -265,13 +265,14 @@ def _create_payment(self, sale_order, data):
)
payment_vals = {
"partner_id": sale_order.partner_id.id,
"provider_id": provider.id,
"acquirer_id": acquirer.id,
"type": "server2server",
"state": "done",
"last_state_change": fields.Datetime.now(),
"date": fields.Datetime.now(),
"amount": pmt_data["amount"],
"fees": 0.00,
"reference": pmt_data["reference"],
"provider_reference": pmt_data.get("provider_reference"),
"acquirer_reference": pmt_data.get("acquirer_reference"),
"sale_order_ids": [(4, sale_order.id, 0)],
"currency_id": sale_order.currency_id.id,
"partner_country_id": country,
Expand Down
2 changes: 1 addition & 1 deletion sale_import_base/models/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Payment(BaseModel, metaclass=ExtendableModelMeta):
amount: float
reference: str
currency_code: str
provider_reference: Optional[str] = None
acquirer_reference: Optional[str] = None


class SaleOrder(BaseModel, metaclass=ExtendableModelMeta):
Expand Down
46 changes: 15 additions & 31 deletions sale_import_base/tests/common_sale_order_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def setUpClass(cls):
cls.init_extendable_registry()
account_user = cls.env.user
cls.env = cls.env(user=cls.env.ref("base.user_root"))
cls.setUpPaymentProvider()
cls.setUpPaymentAcquirer()
cls.env = cls.env(user=account_user)
cls.setUpMisc()
cls.setUpProducts()
Expand Down Expand Up @@ -111,35 +111,19 @@ def setUpProducts(cls): # TODO clear this out with TestSaleCommonNoDuplicates
cls.product_b.default_code = "SKU_B"

@classmethod
def setUpPaymentProvider(cls):
# Create manual provider
cls.env["payment.provider"]._fields["code"].selection.append(
("credit_card", "Credit Card")
)
cls.env["payment.provider"].create(
{
"name": "Credit Card",
"ref": "credit_card",
"code": "credit_card",
"company_id": cls.company_data["company"].id,
}
)
method = cls.env["account.payment.method"].create(
{
"code": "credit_card",
"name": "Credit Card",
"payment_type": "inbound",
}
)
cls.env["account.payment.method.line"].create(
[
{
"name": method.code,
"payment_method_id": method.id,
"journal_id": cls.company_data["default_journal_bank"].id,
}
]
)
def setUpPaymentAcquirer(cls):
PaymentAcquirer = cls.env["payment.acquirer"]

# Acquirer and mode of payment
acquirer_vals = {
"name": "Credit Card",
"ref": "credit_card",
"provider": "manual",
"company_id": cls.env.ref("base.main_company").id,
"payment_flow": "s2s",
"journal_id": cls.company_data["default_journal_bank"].id,
}
PaymentAcquirer.create(acquirer_vals)

@classmethod
def setUpMisc(cls):
Expand All @@ -162,4 +146,4 @@ def get_chunk_vals(cls, which_data):
def _helper_create_chunk(cls, vals_dict):
"""Converts data_str content to appropriate JSON format"""
vals_dict["data_str"] = json.dumps(vals_dict["data_str"])
return cls.env["queue.job.chunk"].create(vals_dict)
return cls.env["queue.job.chunk"].sudo().create(vals_dict)
2 changes: 1 addition & 1 deletion sale_import_base/tests/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"amount": 1173.00,
"reference": "PMT-EXAMPLE-001",
"currency_code": "USD",
"provider_reference": "T123",
"acquirer_reference": "T123",
},
"pricelist_id": 1,
"date_order": "2020-01-02",
Expand Down
4 changes: 2 additions & 2 deletions sale_import_base/tests/test_sale_order_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ def test_payment_create(self):
sale = self.get_created_sales()
new_payment = sale.transaction_ids
self.assertEqual(new_payment.reference, "PMT-EXAMPLE-001")
self.assertEqual(new_payment.provider_reference, "T123")
self.assertEqual(new_payment.amount, 1173),
self.assertEqual(new_payment.acquirer_reference, "T123")
(self.assertEqual(new_payment.amount, 1173),)
self.assertEqual(new_payment.currency_id.name, "USD")
self.assertEqual(new_payment.partner_id, sale.partner_id)

Expand Down

0 comments on commit 06b1d70

Please sign in to comment.