diff --git a/companyweb_payment_info/__manifest__.py b/companyweb_payment_info/__manifest__.py index 66e31940..01a24207 100644 --- a/companyweb_payment_info/__manifest__.py +++ b/companyweb_payment_info/__manifest__.py @@ -5,7 +5,7 @@ "summary": ("Send your customer payment information to Companyweb"), "author": "ACSONE SA/NV,Odoo Community Association (OCA)", "website": "https://github.com/OCA/l10n-belgium", - "version": "16.0.1.0.4", + "version": "17.0.1.0.0", "development_status": "Production/Stable", "license": "AGPL-3", "installable": True, diff --git a/companyweb_payment_info/tests/test_cweb_upload.py b/companyweb_payment_info/tests/test_cweb_upload.py index b2b6bb5a..dfe0d3bd 100644 --- a/companyweb_payment_info/tests/test_cweb_upload.py +++ b/companyweb_payment_info/tests/test_cweb_upload.py @@ -2,16 +2,31 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). import os +import requests +import werkzeug from freezegun import freeze_time +from requests import PreparedRequest, Session from vcr_unittest import VCRMixin from odoo.exceptions import UserError from odoo.tests.common import TransactionCase +_super_send = requests.Session.send + class TestUpload(VCRMixin, TransactionCase): + @classmethod + def _request_handler(cls, s: Session, r: PreparedRequest, /, **kw): + """ + Override to allow requests to the companyweb API + """ + url = werkzeug.urls.url_parse(r.url) + if url.host in ("payex.companyweb.be",): + return _super_send(s, r, **kw) + return super()._request_handler(s=s, r=r, **kw) + def setUp(self, *args, **kwargs): - super(TestUpload, self).setUp(*args, **kwargs) + super().setUp(*args, **kwargs) self.demo_user = self.env.ref("base.user_demo") self.env.user.company_id.vat = False self.demo_user.partner_id.email = "test@odoo.com" diff --git a/companyweb_payment_info/wizards/payment_info_wizard.py b/companyweb_payment_info/wizards/payment_info_wizard.py index 1dc8f281..0a756ccf 100644 --- a/companyweb_payment_info/wizards/payment_info_wizard.py +++ b/companyweb_payment_info/wizards/payment_info_wizard.py @@ -27,6 +27,8 @@ class CompanyWebPaymentInfoWizard(models.TransientModel): wizard_text = fields.Html("wizard_text") wizard_step = fields.Char(default="step1") wizard_email = fields.Char("wizard_email") + last_sent_month = fields.Integer() + last_sent_year = fields.Integer() def payment_info_entry_point(self): if self.wizard_step == "step1": @@ -51,8 +53,8 @@ def _check_group(self): def _cweb_payment_info_step1(self): self._check_group() - supplierVat = self.env.user.company_id.vat - if not supplierVat or not supplierVat.startswith("BE"): + supplier_vat = self.env.user.company_id.vat + if not supplier_vat or not supplier_vat.startswith("BE"): raise UserError( _( "Companyweb : You need to set a valid belgian's vat " @@ -69,31 +71,21 @@ def _cweb_payment_info_step1(self): "https://payex.companyweb.be/v1/PaymentExperienceService.asmx" ) - response_previous_period = self._get_previous_period(client, supplierVat) + response_previous_period = self._get_previous_period(client, supplier_vat) # 11/15/16 means bad credentials if response_previous_period["StatusCode"] in [11, 15, 16]: return self._cweb_call_wizard_credentials(_("Bad Credentials")) - last_date_sent = "%02d/%d" % ( - response_previous_period["PreviousMonth"], - response_previous_period["PreviousYear"], - ) + + self.last_sent_month = response_previous_period["PreviousMonth"] + self.last_sent_year = response_previous_period["PreviousYear"] period_to_send = self._get_period_to_send() - if ( - period_to_send.month == response_previous_period["PreviousMonth"] - and period_to_send.year == response_previous_period["PreviousYear"] - ): - raise UserError( - _("Companyweb : You already submitted invoices for {last_date}").format( - last_date=last_date_sent - ) - ) invoices_to_send = self._create_invoices_to_send(client) if len(invoices_to_send) == 0: raise UserError(_("Companyweb : No Invoices to send")) summary = self._create_step1_summary( - response_previous_period, invoices_to_send, last_date_sent, period_to_send + response_previous_period, invoices_to_send, period_to_send ) wizard = self.create( @@ -101,6 +93,8 @@ def _cweb_payment_info_step1(self): wizard_text=summary, wizard_step="step2", wizard_email=self.env.user.partner_id.email, + last_sent_month=self.last_sent_month, + last_sent_year=self.last_sent_year, ) ) return dict(wizard.get_formview_action(), target="new") @@ -133,9 +127,7 @@ def _cweb_payment_info_step2(self): ) transaction_key = result_start_transaction["TransactionKey"] self._cweb_send_batch(client, invoices_to_send, transaction_key) - result_summary = self._cweb_step3_summary( - client, transaction_key, invoices_to_send - ) + result_summary = self._cweb_step3_summary(client, transaction_key) result_commit = self._cweb_commit_tran(client, transaction_key) if result_commit["StatusCode"] != 0: @@ -165,7 +157,7 @@ def _cweb_commit_tran(self, client, transaction_key): ) return response_tran - def _cweb_step3_summary(self, client, transaction_key, invoices_to_send): + def _cweb_step3_summary(self, client, transaction_key): response_summary = client.service.Step3_GetSummary( dict( CompanyWebLogin=self.env.user.cweb_login, @@ -214,13 +206,16 @@ def _create_step1_summary( self, response_previous_period, invoice_to_send, - last_period_sent, period_to_send, ): print_period_to_send = "%02d/%d" % ( period_to_send.month, period_to_send.year, ) + print_last_period_sent = "%02d/%d" % ( + self.last_sent_month, + self.last_sent_year, + ) if response_previous_period["PreviousPeriodExists"]: summary = _( "