Skip to content

Commit

Permalink
[REF] pre-commit changes
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniospneto committed Sep 17, 2024
1 parent 8a42cb4 commit e749f48
Show file tree
Hide file tree
Showing 107 changed files with 413 additions and 400 deletions.
2 changes: 1 addition & 1 deletion l10n_br_account/models/account_incoterms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ def name_get(self):
# name completo
if len(record.name) > 150:
name = record.name[:150] + " ..."
result.append((record.id, "%s - %s" % (record.code, name)))
result.append((record.id, f"{record.code} - {name}"))
return result
8 changes: 5 additions & 3 deletions l10n_br_account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ def _check_fiscal_document_type(self):
if rec.document_type_id and not rec.fiscal_document_id:
raise UserError(
_(
"You cannot set a document type when the move has no Fiscal Document!"
"You cannot set a document type when the move has no Fiscal "
"Document!"
)
)

Expand Down Expand Up @@ -174,7 +175,7 @@ def _inject_shadowed_fields(self, vals_list):
for vals in vals_list:
for field in self._shadowed_fields():
if field in vals:
vals["fiscal_proxy_%s" % (field,)] = vals[field]
vals[f"fiscal_proxy_{field}"] = vals[field]

def ensure_one_doc(self):
self.ensure_one()
Expand Down Expand Up @@ -242,7 +243,8 @@ def fields_view_get(

if invoice_view["fields"].get("line_ids"):
# it is required to inject the fiscal fields in the
# "accounting lines" view to avoid loosing fiscal values from the form.
# "accounting lines" view to avoid loosing fiscal values from the
# form.
sub_form_view = invoice_view["fields"]["line_ids"]["views"]["tree"][
"arch"
]
Expand Down
9 changes: 5 additions & 4 deletions l10n_br_account/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def _inject_shadowed_fields(self, vals_list):
for vals in vals_list:
for field in self._shadowed_fields():
if field in vals:
vals["fiscal_proxy_%s" % (field,)] = vals[field]
vals[f"fiscal_proxy_{field}"] = vals[field]

@api.model_create_multi
def create(self, vals_list):
Expand Down Expand Up @@ -247,7 +247,8 @@ def create(self, vals_list):
# Initialize the inverted index list with the same length as the original list
inverted_index = [0] * len(original_indexes)

# Iterate over the original_indexes list and fill the inverted_index list accordingly
# Iterate over the original_indexes list and fill the inverted_index list
# accordingly
for i, val in enumerate(original_indexes):
inverted_index[val] = i

Expand All @@ -257,8 +258,8 @@ def create(self, vals_list):
sorted_result |= result[idx]

for line in sorted_result:
# Forces the recalculation of price_total and price_subtotal fields which are
# recalculated by super
# Forces the recalculation of price_total and price_subtotal fields which
# are recalculated by super
if line.move_id.company_id.country_id.code == "BR":
line.update(line._get_price_total_and_subtotal())

Expand Down
4 changes: 3 additions & 1 deletion l10n_br_account/models/account_tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ def compute_all(
account_taxes_by_domain.update({tax.id: tax_domain})

for account_tax in taxes_results["taxes"]:
tax = self.filtered(lambda t: t.id == account_tax.get("id"))
tax = self.filtered(
lambda t, account_tax=account_tax: t.id == account_tax.get("id")
)
fiscal_tax = fiscal_taxes_results["taxes"].get(
account_taxes_by_domain.get(tax.id)
)
Expand Down
12 changes: 6 additions & 6 deletions l10n_br_account/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ def unlink(self):
@api.model_create_multi
def create(self, vals_list):
"""
It's not allowed to create a fiscal document line without a document_type_id anyway.
But instead of letting Odoo crash in this case we simply avoid creating the
record. This makes it possible to create an account.move without
a fiscal_document_id despite the _inherits system:
It's not allowed to create a fiscal document line without a document_type_id
anyway. But instead of letting Odoo crash in this case we simply avoid creating
the record. This makes it possible to create an account.move without a
fiscal_document_id despite the _inherits system:
Odoo will write NULL as the value in this case.
"""
if self._context.get("create_from_move"):
Expand Down Expand Up @@ -158,14 +158,14 @@ def cancel_move_ids(self):

def _document_cancel(self, justificative):
result = super()._document_cancel(justificative)
msg = "Cancelamento: {}".format(justificative)
msg = f"Cancelamento: {justificative}"

Check warning on line 161 in l10n_br_account/models/document.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account/models/document.py#L161

Added line #L161 was not covered by tests
self.cancel_move_ids()
self.message_post(body=msg)
return result

def _document_correction(self, justificative):
result = super()._document_correction(justificative)
msg = "Carta de correção: {}".format(justificative)
msg = f"Carta de correção: {justificative}"

Check warning on line 168 in l10n_br_account/models/document.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account/models/document.py#L168

Added line #L168 was not covered by tests
self.message_post(body=msg)
return result

Expand Down
12 changes: 5 additions & 7 deletions l10n_br_account/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ def init_invoice(
document_number=None,
):
"""
We could not override the super one because we need to inject extra BR fiscal fields.
We could not override the super one because we need to inject extra BR fiscal
fields.
"""
products = [] if products is None else products
amounts = [] if amounts is None else amounts
Expand Down Expand Up @@ -364,11 +365,8 @@ def line_log(cls, lines, index):
Utility method to help debugging
"""
lines = cls.sort_lines(lines.sorted())
log = "LINE %s %s %s %s %s" % (
index,
lines[index].name,
lines[index].debit,
lines[index].credit,
lines[index].account_id.name,
log = (

Check warning on line 368 in l10n_br_account/tests/common.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account/tests/common.py#L368

Added line #L368 was not covered by tests
f"LINE {index} {lines[index].name} {lines[index].debit}"
f" {lines[index].credit} {lines[index].account_id.name}"
)
return log
2 changes: 1 addition & 1 deletion l10n_br_account/tests/test_account_move_lc.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def setup_company_data(cls, company_name, chart_template=None, **kwargs):
icms_regulation_id=cls.env.ref("l10n_br_fiscal.tax_icms_regulation").id,
cnae_main_id=cls.env.ref("l10n_br_fiscal.cnae_3101200").id,
document_type_id=cls.env.ref("l10n_br_fiscal.document_55").id,
**kwargs
**kwargs,
)
res["company"].partner_id.state_id = cls.env.ref("base.state_br_sp").id
res["company"].partner_id.cnpj_cpf = cnpj
Expand Down
2 changes: 1 addition & 1 deletion l10n_br_account/tests/test_account_move_sn.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def setup_company_data(cls, company_name, chart_template=None, **kwargs):
cnae_main_id=cls.env.ref("l10n_br_fiscal.cnae_3101200").id,
document_type_id=cls.env.ref("l10n_br_fiscal.document_55").id,
annual_revenue=815000.0,
**kwargs
**kwargs,
)
chart_template.load_fiscal_taxes()
return res
Expand Down
6 changes: 4 additions & 2 deletions l10n_br_account/tests/test_document_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def test_document_date(self):
self.move_id.issuer = DOCUMENT_ISSUER_PARTNER
user_tz = timezone(self.env.user.tz or "UTC")
original_date = datetime.combine(datetime.now().date(), time.min)
# Convert the original_date to the user's timezone and remove the time for comparison
# Convert the original_date to the user's timezone and remove the time for
# comparison
original_date_in_user_tz = (
user_tz.localize(original_date).astimezone(UTC).replace(tzinfo=None)
)
Expand Down Expand Up @@ -123,7 +124,8 @@ def test_date_in_out(self):
self.move_id.issuer = DOCUMENT_ISSUER_PARTNER
user_tz = timezone(self.env.user.tz or "UTC")
original_date = datetime.combine(datetime.now().date(), time.min)
# Convert the original_date to the user's timezone and remove the time for comparison
# Convert the original_date to the user's timezone and remove the time for
# comparison
original_date_in_user_tz = (
user_tz.localize(original_date).astimezone(UTC).replace(tzinfo=None)
)
Expand Down
14 changes: 7 additions & 7 deletions l10n_br_account/tests/test_multi_localizations_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
_logger = logging.getLogger(__name__)


# flake8: noqa: B950 - line too long
# ruff: noqa: E501 - line too long
def addTest(self, test):
"""
This monkey patch is required to avoid triggering all the tests from
Expand Down Expand Up @@ -116,13 +116,13 @@ def test_force_out_invoice_line_onchange_cash_rounding_1(self):
def test_force_out_invoice_line_onchange_currency_1(self):
return super().test_out_invoice_line_onchange_currency_1()

# def test_force_out_invoice_line_tax_fixed_price_include_free_product(self):
# FIXME
# return super().test_out_invoice_line_tax_fixed_price_include_free_product()
# def test_force_out_invoice_line_tax_fixed_price_include_free_product(self):
# FIXME
# return super().test_out_invoice_line_tax_fixed_price_include_free_product()

# def test_force_out_invoice_line_taxes_fixed_price_include_free_product(self):
# FIXME
# return super().test_out_invoice_line_taxes_fixed_price_include_free_product()
# def test_force_out_invoice_line_taxes_fixed_price_include_free_product(self):
# FIXME
# return super().test_out_invoice_line_taxes_fixed_price_include_free_product()

def test_force_out_invoice_create_refund(self):
return super().test_out_invoice_create_refund()
Expand Down
2 changes: 1 addition & 1 deletion l10n_br_account_due_list/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AccountInvoice(models.Model):
def _compute_financial(self):
for move in self:
lines = move.line_ids.filtered(
lambda l: l.account_id.internal_type in ("receivable", "payable")
lambda line: line.account_id.internal_type in ("receivable", "payable")
)
move.financial_move_line_ids = lines.sorted()

Expand Down
4 changes: 2 additions & 2 deletions l10n_br_account_nfe/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ def _check_fiscal_payment_mode(self):
if not rec.move_ids.payment_mode_id.fiscal_payment_mode:
raise UserError(
_(
"Payment Mode %(mode)s should have "
"a Fiscal Payment Mode filled to be used in the Fiscal Document!",
"Payment Mode %(mode)s should have a Fiscal Payment Mode"
" filled to be used in the Fiscal Document!",
mode=rec.move_ids.payment_mode_id.name,
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ def test_invoice_without_payment_mode(self):
invoice.action_post()
self.assertFalse(
invoice.nfe40_dup,
"Error field nfe40_dup should not filled when Fiscal Operation are Bonificação.",
"Error field nfe40_dup should not filled when Fiscal Operation are "
"Bonificação.",
)
for detPag in invoice.nfe40_detPag:
self.assertEqual(
Expand Down
13 changes: 8 additions & 5 deletions l10n_br_account_payment_brcobranca/models/account_journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,17 @@ def _get_moves(self, parser, result_row_list):
raise
except Exception as e:
error_type, error_value, trbk = sys.exc_info()
st = "Error: %s\nDescription: %s\nTraceback:" % (
error_type.__name__,
error_value,
st = (

Check warning on line 232 in l10n_br_account_payment_brcobranca/models/account_journal.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account_payment_brcobranca/models/account_journal.py#L232

Added line #L232 was not covered by tests
f"Error: {error_type.__name__}\n"
f"Description: {error_value}\nTraceback:"
)
st += "".join(traceback.format_tb(trbk, 30))
raise ValidationError(
_("Statement import error " "The statement cannot be created: %s")
% st
_(
"Statement import error "
"The statement cannot be created: %(st)s",
st=st,
)
) from e

return moves
45 changes: 22 additions & 23 deletions l10n_br_account_payment_brcobranca/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ def send_payment(self):
move_line.debit
* ((move_line.payment_mode_id.boleto_interest_perc / 100) / 30),
)
instrucao_juros = (
"APÓS VENCIMENTO COBRAR PERCENTUAL"
+ " DE %s %% AO MÊS ( R$ %s AO DIA )"
% (
(
"%.2f" % move_line.payment_mode_id.boleto_interest_perc
).replace(".", ","),
("%.2f" % valor_juros).replace(".", ","),
percentual_formatado = (
f"{move_line.payment_mode_id.boleto_interest_perc:.2f}".replace(
".", ","
)
)
juros_formatado = f"{valor_juros:.2f}".replace(".", ",")
instrucao_juros = (
f"APÓS VENCIMENTO COBRAR PERCENTUAL DE {percentual_formatado}%"
f" AO MÊS (R${juros_formatado} AO DIA)"
)
boleto_cnab_api_data.update(
{
"instrucao3": instrucao_juros,
Expand All @@ -122,15 +122,13 @@ def send_payment(self):
valor_multa = move_line.currency_id.round(
move_line.debit * (move_line.payment_mode_id.boleto_fee_perc / 100),
)
percentual_formatado = (
f"{move_line.payment_mode_id.boleto_fee_perc:.2f}".replace(".", ",")
)
multa_formatado = f"{valor_multa:.2f}".replace(".", ",")
instrucao_multa = (
"APÓS VENCIMENTO COBRAR MULTA"
+ " DE %s %% ( R$ %s )"
% (
("%.2f" % move_line.payment_mode_id.boleto_fee_perc).replace(
".", ","
),
("%.2f" % valor_multa).replace(".", ","),
)
f"APÓS VENCIMENTO COBRAR MULTA DE {percentual_formatado}%"
f" (R${multa_formatado})"
)
boleto_cnab_api_data.update(
{
Expand All @@ -143,14 +141,15 @@ def send_payment(self):
valor_desconto = move_line.currency_id.round(
move_line.debit * (move_line.boleto_discount_perc / 100),
)
percentual_formatado = f"{move_line.boleto_discount_perc:.2f}".replace(
".", ","
)
desconto_formatado = f"{valor_desconto:.2f}".replace(".", ",")
vencimento_formatado = move_line.date_maturity.strftime("%d/%m/%Y")
instrucao_desconto_vencimento = (
"CONCEDER DESCONTO DE" + " %s %% "
"ATÉ O VENCIMENTO EM %s ( R$ %s )"
% (
("%.2f" % move_line.boleto_discount_perc).replace(".", ","),
move_line.date_maturity.strftime("%d/%m/%Y"),
("%.2f" % valor_desconto).replace(".", ","),
)
f"CONCEDER DESCONTO DE {percentual_formatado}% "
f"ATÉ O VENCIMENTO EM {vencimento_formatado} "
f"(R${desconto_formatado})"
)
boleto_cnab_api_data.update(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def delete_payments_created_from_payment_orders(env):
openupgrade.logged_query(
env.cr,
"""
DELETE FROM account_payment WHERE payment_order_id IS NOT NULL AND payment_method_id IN
DELETE FROM account_payment
WHERE payment_order_id IS NOT NULL AND payment_method_id IN
(SELECT id FROM account_payment_method WHERE code IN ('240', '400', '500'));
""",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

@openupgrade.migrate(use_env=True)
def migrate(env, version):

# Apagando o objeto bank.payment.line
openupgrade.logged_query(
env.cr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ def update_payment_mode_inbound(env):
if payment_mode.cnab_liq_return_move_code_ids:
liq_codes = env["l10n_br_cnab.code"]
for code in payment_mode.cnab_liq_return_move_code_ids:

liq_code = get_new_code(env, payment_mode, code, "return_move_code")
liq_codes |= liq_code

Expand Down
4 changes: 1 addition & 3 deletions l10n_br_account_payment_order/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ def _target_new_tab(self, attachment_id):
if attachment_id:
return {
"type": "ir.actions.act_url",
"url": "/web/content/{id}/{nome}".format(
id=attachment_id.id, nome=attachment_id.name
),
"url": f"/web/content/{attachment_id.id}/{attachment_id.name}",
"target": "new",
}

Expand Down
17 changes: 5 additions & 12 deletions l10n_br_account_payment_order/models/account_payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,11 @@ def generate_payment_file(self):

def get_file_name(self, cnab_type):
context_today = fields.Date.context_today(self)
date = context_today.strftime("%d%m")
file_number = self.file_number
if cnab_type == "240":
return "CB%s%s.REM" % (
context_today.strftime("%d%m"),
str(self.file_number),
)
return f"CB{date}{file_number}.REM"
elif cnab_type == "400":
return "CB%s%02d.REM" % (
context_today.strftime("%d%m"),
self.file_number or 1,
)
return f"CB{date}{file_number:02d}.REM"
elif cnab_type == "500":
return "PG%s%s.REM" % (
context_today.strftime("%d%m"),
str(self.file_number),
)
return f"PG{date}{file_number}.REM"

Check warning on line 237 in l10n_br_account_payment_order/models/account_payment_order.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account_payment_order/models/account_payment_order.py#L237

Added line #L237 was not covered by tests
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ def _msg_error_cnab_missing(self, payment_mode_name, missing):
"""
raise UserError(
_(
"Payment Mode %(payment_mode_name)s don't has %(missing)s for making CNAB"
"change, check if should have.",
"Payment Mode %(payment_mode_name)s don't has %(missing)s for making "
"CNAB change, check if should have.",
payment_mode_name=payment_mode_name,
missing=missing,
)
Expand Down
Loading

0 comments on commit e749f48

Please sign in to comment.