Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
TDu committed Dec 8, 2020
1 parent 7f9d633 commit 2053637
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 26 deletions.
11 changes: 8 additions & 3 deletions ebill_paynet/models/paynet_invoice_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,24 @@ def _get_payload_params(self):
# Get the invoice due date
date_due = None
if self.invoice_id.invoice_payment_term_id:
terms = self.invoice_id.invoice_payment_term_id.compute(self.invoice_id.amount_total)
terms = self.invoice_id.invoice_payment_term_id.compute(
self.invoice_id.amount_total
)
if terms:
# Returns all payment and their date like [('2020-12-07', 430.37), ...]
# Get the last payment date in the format "202021207"
date_due = terms[-1][0].replace("-", "")
if not date_due:
date_due = self.format_date(self.invoice_id.invoice_date_due or self.invoice_id.invoice_date)
date_due = self.format_date(
self.invoice_id.invoice_date_due or self.invoice_id.invoice_date
)
params["date_due"] = date_due
return params

def _get_jinja_env(self, template_dir):
jinja_env = Environment(
loader=FileSystemLoader(template_dir), autoescape=select_autoescape(["xml"]),
loader=FileSystemLoader(template_dir),
autoescape=select_autoescape(["xml"]),
)
return jinja_env

Expand Down
1 change: 1 addition & 0 deletions ebill_paynet/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from . import test_ebill_paynet

# Test for the B2C implemenation wich is not done, yet
# from . import test_invoice_message
from . import test_invoice_message_b2b
7 changes: 3 additions & 4 deletions ebill_paynet/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

import os

from os.path import dirname, join

from vcr import VCR
from xmlunittest import XmlTestMixin

from odoo.tests.common import SavepointCase
from xmlunittest import XmlTestMixin


class CommonCase(SavepointCase, XmlTestMixin):

@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down Expand Up @@ -186,7 +184,6 @@ def setUpClass(cls):
cls.invoice.invoice_payment_ref = "1234567890"
cls.invoice.invoice_partner_bank_id = cls.partner_bank.id


@staticmethod
def compare_xml_line_by_line(content, expected):
"""This a quick way to check the diff line by line to ease debugging"""
Expand All @@ -199,6 +196,7 @@ def compare_xml_line_by_line(content, expected):
i, number_of_lines, expected_line[i], generated_line[i],
)


def get_recorder(base_path=None, **kw):
base_path = base_path or dirname(__file__)
defaults = dict(
Expand All @@ -212,4 +210,5 @@ def get_recorder(base_path=None, **kw):
defaults.update(kw)
return VCR(**defaults)


recorder = get_recorder()
2 changes: 1 addition & 1 deletion ebill_paynet/tests/test_invoice_message_b2b.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def setUpClass(cls):
def test_invoice(self):
""" Check XML payload genetated for an invoice."""
self.invoice.name = "INV_TEST_01"
self.invoice.invoice_date_due = '2019-07-01'
self.invoice.invoice_date_due = "2019-07-01"
message = self.invoice.create_paynet_message()
message.payload = message._generate_payload()
# Remove the PDF file data from the XML to ease testing
Expand Down
5 changes: 1 addition & 4 deletions ebill_paynet_account_financial_discount/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
"license": "AGPL-3",
"author": "Camptocamp SA,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-switzerland",
"depends": [
"account_financial_discount",
"ebill_paynet",
],
"depends": ["account_financial_discount", "ebill_paynet"],
"auto_install": True,
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ def _get_payload_params(self):
params = super()._get_payload_params()
params["discount_template"] = DISCOUNT_TEMPLATE
discount = {}
if self.invoice_id.invoice_payment_term_id and self.invoice_id.invoice_payment_term_id.percent_discount:
if self.invoice_id.invoice_payment_term_id.percent_discount:
terms = self.invoice_id.invoice_payment_term_id
discount = {
"percentage": self.invoice_id.invoice_payment_term_id.percent_discount,
"days": self.invoice_id.invoice_payment_term_id.days_discount
"percentage": terms.percent_discount,
"days": terms.days_discount,
}
params["discount"] = discount
return params
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Copyright 2020 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from freezegun import freeze_time
from string import Template

from freezegun import freeze_time

from odoo.tools import file_open

from ...ebill_paynet.tests.common import CommonCase
Expand All @@ -15,19 +16,19 @@ class TestEbillPaynetAccountFinancialDiscount(CommonCase):
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.payment_term = cls.env['account.payment.term'].create(
cls.payment_term = cls.env["account.payment.term"].create(
{
'name': 'Skonto',
'days_discount': 10,
'percent_discount': 2.0,
'line_ids': [
"name": "Skonto",
"days_discount": 10,
"percent_discount": 2.0,
"line_ids": [
(
0,
0,
{
'value': 'balance',
'days': 60,
'option': 'day_after_invoice_date',
"value": "balance",
"days": 60,
"option": "day_after_invoice_date",
},
)
],
Expand All @@ -37,7 +38,7 @@ def setUpClass(cls):
def test_invoice(self):
""" Check XML payload genetated for an invoice."""
self.invoice.name = "INV_TEST_01"
self.invoice.invoice_date_due = '2019-07-01'
self.invoice.invoice_date_due = "2019-07-01"
self.invoice.invoice_payment_term_id = self.payment_term
message = self.invoice.create_paynet_message()
message.payload = message._generate_payload()
Expand All @@ -51,7 +52,9 @@ def test_invoice(self):
self.assertXmlDocument(payload)
# Prepare the XML file that is expected
expected_tmpl = Template(
file_open("ebill_paynet_account_financial_discount/tests/examples/invoice_b2b.xml").read()
file_open(
"ebill_paynet_account_financial_discount/tests/examples/invoice_b2b.xml"
).read()
)
expected = expected_tmpl.substitute(IC_REF=message.ic_ref).encode("utf8")
# Remove the comments in the expected xml
Expand Down
6 changes: 6 additions & 0 deletions setup/ebill_paynet_account_financial_discount/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 2053637

Please sign in to comment.