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

View File

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

View File

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

View File

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

View File

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