[IMP] account_move_base_import: black, isort, prettier

This commit is contained in:
Florian da Costa
2022-12-02 15:52:45 +01:00
parent 530dd92e32
commit a918cd88c4
8 changed files with 88 additions and 65 deletions

View File

@@ -32,7 +32,7 @@ class AccountJournal(models.Model):
"moves for this journal.",
)
last_import_date = fields.Datetime(string="Last Import Date")
last_import_date = fields.Datetime()
partner_id = fields.Many2one(
comodel_name="res.partner",
@@ -64,13 +64,11 @@ class AccountJournal(models.Model):
)
create_counterpart = fields.Boolean(
string="Create Counterpart",
help="Tick that box to automatically create the move counterpart",
default=True,
)
split_counterpart = fields.Boolean(
string="Split Counterpart",
help="Two counterparts will be automatically created : one for "
"the refunds and one for the payments",
)
@@ -218,8 +216,8 @@ class AccountJournal(models.Model):
:return: True
"""
self.message_post(
body=_("Move %s have been imported with %s " "lines.")
% (move.name, num_lines)
body=_("Move %(move_name)s have been imported with %(num_lines)s " "lines.")
% {"move_name": move.name, "num_lines": num_lines}
)
return True
@@ -397,5 +395,5 @@ class AccountJournal(models.Model):
st += "".join(traceback.format_tb(trbk, 30))
raise ValidationError(
_("Statement import error " "The statement cannot be created: %s") % st
)
) from None
return move

View File

@@ -42,8 +42,8 @@ class AccountMoveCompletionRule(models.Model):
_order = "sequence asc"
_description = "Account move completion method"
sequence = fields.Integer(string="Sequence", help="Lower means parsed first.")
name = fields.Char(string="Name")
sequence = fields.Integer(help="Lower means parsed first.")
name = fields.Char()
journal_ids = fields.Many2many(
comodel_name="account.journal",
relation="account_journal_completion_rule_rel",
@@ -94,10 +94,10 @@ class AccountMoveCompletionRule(models.Model):
else:
raise ErrorTooManyPartner(
_(
'Line named "%s" was matched by more than one '
"partner while looking on %s invoices"
'Line named "%(line_name)s" was matched by more than one '
"partner while looking on %(inv_type)s invoices"
)
% (line.name, inv_type)
% {"line_name": line.name, "inv_type": inv_type}
)
return False
@@ -177,9 +177,12 @@ class AccountMoveCompletionRule(models.Model):
if partners:
if len(partners) > 1:
msg = _(
'Line named "%s" was matched by more than '
"one partner while looking on partner label: %s"
) % (line.name, ",".join([x.name for x in partners]))
'Line named "%(line_name)s" was matched by more than '
"one partner while looking on partner label: %(partner_labels)s"
) % {
"line_name": line.name,
"partner_labels": ",".join([x.name for x in partners]),
}
raise ErrorTooManyPartner(msg)
res["partner_id"] = partners[0].id
return res
@@ -316,6 +319,7 @@ class AccountMove(models.Model):
move.partner_id = move.import_partner_id
else:
super(AccountMove, move)._compute_partner_id()
return
def write_completion_log(self, error_msg, number_imported):
"""Write the log in the completion_logs field of the bank statement to
@@ -332,22 +336,31 @@ class AccountMove(models.Model):
log = self.completion_logs or ""
completion_date = fields.Datetime.now()
message = _(
"%s Account Move %s has %s/%s lines completed by " "%s \n%s\n%s\n"
) % (
completion_date,
self.name,
number_imported,
number_line,
user_name,
error_msg,
log,
)
"%(completion_date)s Account Move %(move_name)s has %(num_imported)s/"
"%(number_line)s lines completed by "
"%(user_name)s \n%(error_msg)s\n%(log)s\n"
) % {
"completion_date": completion_date,
"move_name": self.name,
"num_imported": number_imported,
"number_line": number_line,
"user_name": user_name,
"error_msg": error_msg,
"log": log,
}
self.write({"completion_logs": message})
body = (
(
_("Statement ID %s auto-completed for %s/%s lines completed")
% (self.name, number_imported, number_line)
_(
"Statement ID %(move_name)s auto-completed for %(num_imported)s/"
"%(number_line)s lines completed"
)
% {
"move_name": self.name,
"num_imported": number_imported,
"number_line": number_line,
}
),
)
self.message_post(body=body)

View File

@@ -14,7 +14,6 @@ class ResPartner(models.Model):
_inherit = "res.partner"
bank_statement_label = fields.Char(
string="Bank Statement Label",
help="Enter the various label found on your bank statement "
"separated by a ; If one of this label is include in the "
"bank statement line, the partner will be automatically "

View File

@@ -158,33 +158,35 @@ class FileParser(AccountMoveImportParser):
raise UserError(
_(
"Date format is not valid."
" It should be YYYY-MM-DD for column: %s"
" value: %s \n \n \n Please check"
" the line with ref: %s \n \n Detail: %s"
)
% (
rule,
line.get(rule, _("Missing")),
line.get("ref", line),
repr(err),
)
" It should be YYYY-MM-DD for column: %(rule)s"
" value: %(line_value)s \n \n \n Please check"
" the line with ref: %(ref_value)s \n \n Detail: "
"%(error)s"
)
% {
"rule": rule,
"line_value": line.get(rule, _("Missing")),
"ref_value": line.get("ref", line),
"error": repr(err),
}
) from err
else:
try:
line[rule] = conversion_rules[rule](line[rule])
except Exception as err:
raise UserError(
_(
"Value %s of column %s is not valid.\n Please "
"check the line with ref %s:\n \n Detail: %s"
)
% (
line.get(rule, _("Missing")),
rule,
line.get("ref", line),
repr(err),
)
"Value %(line_value)s of column %(rule)s is not valid."
"\n Please check the line with ref %(value_ref)s:\n "
"\n Detail: %(error)s"
)
% {
"line_value": line.get(rule, _("Missing")),
"rule": rule,
"value_ref": line.get("ref", line),
"error": repr(err),
}
) from err
return result_set
def _from_xls(self, result_set, conversion_rules):
@@ -202,32 +204,34 @@ class FileParser(AccountMoveImportParser):
_(
"Date format is not valid. "
"Please modify the cell formatting to date "
"format for column: %s value: %s\n Please"
" check the line with ref: %s\n \n Detail: %s"
)
% (
rule,
line.get(rule, _("Missing")),
line.get("ref", line),
repr(err),
)
"format for column: %(rule)s value: %(line_value)s\n "
"Please check the line with ref: %(value_ref)s\n "
"\n Detail: %(error)s"
)
% {
"rule": rule,
"line_value": line.get(rule, _("Missing")),
"value_ref": line.get("ref", line),
"error": repr(err),
}
) from err
else:
try:
line[rule] = conversion_rules[rule](line[rule])
except Exception as err:
raise UserError(
_(
"Value %s of column %s is not valid.\n Please "
"check the line with ref %s:\n \n Detail: %s"
)
% (
line.get(rule, _("Missing")),
rule,
line.get("ref", line),
repr(err),
)
"Value %(line_value)s of column %(rule)s is not valid."
"\n Please check the line with ref %(value_ref)s:\n "
"\n Detail: %(error)s"
)
% {
"line_value": line.get(rule, _("Missing")),
"rule": rule,
"value_ref": line.get("ref", line),
"error": repr(err),
}
) from err
return result_set
def _cast_rows(self, *args, **kwargs):

View File

@@ -53,7 +53,7 @@
<field name="name">account.move.completion.rule.view</field>
<field name="model">account.move.completion.rule</field>
<field name="arch" type="xml">
<tree string="Move Completion Rule">
<tree>
<field name="sequence" />
<field name="name" select="1" />
<field name="journal_ids" />

2
requirements.txt Normal file
View File

@@ -0,0 +1,2 @@
# generated from manifests external_dependencies
xlrd

View File

@@ -0,0 +1 @@
../../../../account_move_base_import

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)