[IMP] Make commission feature compatible with

all parsers (not only generic_csvxls_so) + male it compatible with split_counterpart option
This commit is contained in:
Florian da Costa
2021-04-06 18:20:11 +02:00
parent 92ef9a4ee3
commit 5b0be92e5c
4 changed files with 24 additions and 8 deletions

View File

@@ -28,7 +28,6 @@ class AccountJournal(models.Model):
[("generic_csvxls_so", "Generic .csv/.xls based on SO Name")], [("generic_csvxls_so", "Generic .csv/.xls based on SO Name")],
string="Type of import", string="Type of import",
default="generic_csvxls_so", default="generic_csvxls_so",
required=True,
help="Choose here the method by which you want to import account " help="Choose here the method by which you want to import account "
"moves for this journal.", "moves for this journal.",
) )
@@ -116,17 +115,24 @@ class AccountJournal(models.Model):
move_line_obj = self.env["account.move.line"] move_line_obj = self.env["account.move.line"]
refund = 0.0 refund = 0.0
payment = 0.0 payment = 0.0
commission = 0.0
transfer_lines = [] transfer_lines = []
for move_line in move.line_ids: for move_line in move.line_ids:
if (
move_line.account_id == self.commission_account_id
and move_line.already_completed
):
commission -= move_line.debit
else:
refund -= move_line.debit refund -= move_line.debit
payment += move_line.credit payment += move_line.credit
if self.split_counterpart: if self.split_counterpart:
if refund: if refund:
transfer_lines.append(refund) transfer_lines.append(refund)
if payment: if payment:
transfer_lines.append(payment) transfer_lines.append(payment + commission)
else: else:
total_amount = refund + payment total_amount = refund + payment + commission
if total_amount: if total_amount:
transfer_lines.append(total_amount) transfer_lines.append(total_amount)
counterpart_date = parser.get_move_vals().get("date") or fields.Date.today() counterpart_date = parser.get_move_vals().get("date") or fields.Date.today()
@@ -156,8 +162,13 @@ class AccountJournal(models.Model):
""" """
move_line_obj = self.env["account.move.line"] move_line_obj = self.env["account.move.line"]
global_commission_amount = 0 global_commission_amount = 0
commmission_field = parser.commission_field
if commmission_field:
for row in parser.result_row_list: for row in parser.result_row_list:
global_commission_amount += float(row.get("commission_amount", "0.0")) global_commission_amount += float(row.get(commmission_field, "0.0"))
# If commission amount is positive in field, inverse the sign
if parser.commission_sign == "+":
global_commission_amount = -global_commission_amount
partner_id = self.partner_id.id partner_id = self.partner_id.id
# Commission line # Commission line
if global_commission_amount > 0.0: if global_commission_amount > 0.0:

View File

@@ -26,6 +26,8 @@ class GenericFileParser(FileParser):
# set self.env for later ORM searches # set self.env for later ORM searches
self.env = journal.env self.env = journal.env
super().__init__(journal, ftype=ftype, extra_fields=conversion_dict, **kwargs) super().__init__(journal, ftype=ftype, extra_fields=conversion_dict, **kwargs)
self.commission_field = "commission_amount"
self.commission_sign = "-"
@classmethod @classmethod
def parser_for(cls, parser_name): def parser_for(cls, parser_name):

View File

@@ -47,6 +47,8 @@ class AccountMoveImportParser(object):
self.move_name = None self.move_name = None
self.move_ref = None self.move_ref = None
self.support_multi_moves = None self.support_multi_moves = None
self.commission_field = None
self.commission_sign = "+"
@classmethod @classmethod
def parser_for(cls, parser_name): def parser_for(cls, parser_name):

View File

@@ -65,7 +65,8 @@ class CreditPartnerStatementImporter(models.TransientModel):
file_name=importer.file_name file_name=importer.file_name
).multi_move_import(importer.input_statement, ftype.replace(".", "")) ).multi_move_import(importer.input_statement, ftype.replace(".", ""))
action = action = self.env["ir.actions.actions"]._for_xml_id( action = action = self.env["ir.actions.actions"]._for_xml_id(
"account.action_move_journal_line") "account.action_move_journal_line"
)
if len(moves) > 1: if len(moves) > 1:
action["domain"] = [("id", "in", moves.ids)] action["domain"] = [("id", "in", moves.ids)]
else: else: