Skip to content

Commit

Permalink
[IMP] l10n_pt_account_invoicexpress: automatically set invx pay status
Browse files Browse the repository at this point in the history
  • Loading branch information
justreisz committed Jul 4, 2023
1 parent f08505a commit 686157a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions l10n_pt_account_invoicexpress/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,41 @@ def _post(self, soft=False):
invoice.action_send_invoicexpress_email(ignore_no_config=True)
return res

def _track_subtype(self, init_values):
res = super()._track_subtype(init_values)

Check warning on line 294 in l10n_pt_account_invoicexpress/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_pt_account_invoicexpress/models/account_move.py#L294

Added line #L294 was not covered by tests
if "payment_state" in init_values and self.payment_state == "paid":
for invoice in self:
if invoice.invoicexpress_id:
invoice._mark_invoice_paid()
return res

Check warning on line 299 in l10n_pt_account_invoicexpress/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_pt_account_invoicexpress/models/account_move.py#L298-L299

Added lines #L298 - L299 were not covered by tests

def _mark_invoice_paid(self):
InvoiceXpress = self.env["account.invoicexpress"]

Check warning on line 302 in l10n_pt_account_invoicexpress/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_pt_account_invoicexpress/models/account_move.py#L302

Added line #L302 was not covered by tests
for invoice in self.filtered("can_invoicexpress"):
doctype = invoice.invoicexpress_doc_type

Check warning on line 304 in l10n_pt_account_invoicexpress/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_pt_account_invoicexpress/models/account_move.py#L304

Added line #L304 was not covered by tests
if not doctype:
raise exceptions.UserError(

Check warning on line 306 in l10n_pt_account_invoicexpress/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_pt_account_invoicexpress/models/account_move.py#L306

Added line #L306 was not covered by tests
_("Invoice is missing the InvoiceXpress document type!")
)
response = InvoiceXpress.call(

Check warning on line 309 in l10n_pt_account_invoicexpress/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_pt_account_invoicexpress/models/account_move.py#L309

Added line #L309 was not covered by tests
invoice.company_id,
"{}s/{}/change-state.json".format(doctype, invoice.invoicexpress_id),
"PUT",
payload={"invoice": {"state": "settled"}},
raise_errors=True,
).json()
values = response.get(doctype)
seqnum = values and values.get("inverted_sequence_number")

Check warning on line 317 in l10n_pt_account_invoicexpress/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_pt_account_invoicexpress/models/account_move.py#L316-L317

Added lines #L316 - L317 were not covered by tests
if not seqnum:
raise exceptions.UserError(

Check warning on line 319 in l10n_pt_account_invoicexpress/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_pt_account_invoicexpress/models/account_move.py#L319

Added line #L319 was not covered by tests
_(
"Something went wrong: the InvoiceXpress response"
" is missing a sequence number."
)
)
msg = _("InvoiceXpress record has been modified to Paid.")
self.message_post(body=msg)

Check warning on line 326 in l10n_pt_account_invoicexpress/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_pt_account_invoicexpress/models/account_move.py#L325-L326

Added lines #L325 - L326 were not covered by tests


class AccountMoveLine(models.Model):
_inherit = "account.move.line"
Expand Down

0 comments on commit 686157a

Please sign in to comment.