mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
Add support for multi-currency in the generation of the account move.
Take into account all the remaining remarks of Frederic Clementi dated May 30: - see multi-currency amounts in the wizard to add transaction lines - add help msg on bank payment lines
This commit is contained in:
committed by
Pedro M. Baeza
parent
d8494aef0d
commit
3a135fcba8
@@ -41,16 +41,16 @@ class AccountPaymentMode(models.Model):
|
|||||||
('move', 'Move'),
|
('move', 'Move'),
|
||||||
], default='due', string="Type of Date Filter")
|
], default='due', string="Type of Date Filter")
|
||||||
group_lines = fields.Boolean(
|
group_lines = fields.Boolean(
|
||||||
string="Group Lines in Payment Orders", default=True,
|
string="Group Transactions in Payment Orders", default=True,
|
||||||
help="If this mark is checked, the payment order lines will be "
|
help="If this mark is checked, the transaction lines of the "
|
||||||
"grouped when validating the payment order before exporting the "
|
"payment order will be grouped upon confirmation of the payment "
|
||||||
"bank file. The grouping will be done only if the following "
|
"order.The grouping will be done only if the following "
|
||||||
"fields matches:\n"
|
"fields matches:\n"
|
||||||
"* Partner\n"
|
"* Partner\n"
|
||||||
"* Currency\n"
|
"* Currency\n"
|
||||||
"* Destination Bank Account\n"
|
"* Destination Bank Account\n"
|
||||||
"* Communication Type (structured, free)\n"
|
|
||||||
"* Payment Date\n"
|
"* Payment Date\n"
|
||||||
|
"and if the 'Communication Type' is 'Free'\n"
|
||||||
"(other modules can set additional fields to restrict the "
|
"(other modules can set additional fields to restrict the "
|
||||||
"grouping.)")
|
"grouping.)")
|
||||||
generate_move = fields.Boolean(
|
generate_move = fields.Boolean(
|
||||||
|
|||||||
@@ -78,7 +78,13 @@ class AccountPaymentOrder(models.Model):
|
|||||||
# v8 field : line_ids
|
# v8 field : line_ids
|
||||||
bank_line_ids = fields.One2many(
|
bank_line_ids = fields.One2many(
|
||||||
'bank.payment.line', 'order_id', string="Bank Payment Lines",
|
'bank.payment.line', 'order_id', string="Bank Payment Lines",
|
||||||
readonly=True)
|
readonly=True,
|
||||||
|
help="The bank payment lines are used to generate the payment file. "
|
||||||
|
"They are automatically created from transaction lines upon "
|
||||||
|
"confirmation of the payment order: one bank payment line can "
|
||||||
|
"group several transaction lines if the option "
|
||||||
|
"'Group Transactions in Payment Orders' is active on the payment "
|
||||||
|
"mode.")
|
||||||
total_company_currency = fields.Monetary(
|
total_company_currency = fields.Monetary(
|
||||||
compute='_compute_total', store=True, readonly=True,
|
compute='_compute_total', store=True, readonly=True,
|
||||||
currency_field='company_currency_id')
|
currency_field='company_currency_id')
|
||||||
@@ -343,12 +349,13 @@ class AccountPaymentOrder(models.Model):
|
|||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _prepare_move_line_offsetting_account(
|
def _prepare_move_line_offsetting_account(
|
||||||
self, amount, bank_payment_lines):
|
self, amount_company_currency, amount_payment_currency,
|
||||||
|
bank_lines):
|
||||||
if self.payment_type == 'outbound':
|
if self.payment_type == 'outbound':
|
||||||
name = _('Payment order %s') % self.name
|
name = _('Payment order %s') % self.name
|
||||||
else:
|
else:
|
||||||
name = _('Debit order %s') % self.name
|
name = _('Debit order %s') % self.name
|
||||||
date_maturity = bank_payment_lines[0].date
|
date_maturity = bank_lines[0].date
|
||||||
if self.payment_mode_id.offsetting_account == 'bank_account':
|
if self.payment_mode_id.offsetting_account == 'bank_account':
|
||||||
account_id = self.journal_id.default_debit_account_id.id
|
account_id = self.journal_id.default_debit_account_id.id
|
||||||
elif self.payment_mode_id.offsetting_account == 'transfer_account':
|
elif self.payment_mode_id.offsetting_account == 'transfer_account':
|
||||||
@@ -358,17 +365,21 @@ class AccountPaymentOrder(models.Model):
|
|||||||
'partner_id': False,
|
'partner_id': False,
|
||||||
'account_id': account_id,
|
'account_id': account_id,
|
||||||
'credit': (self.payment_type == 'outbound' and
|
'credit': (self.payment_type == 'outbound' and
|
||||||
amount or 0.0),
|
amount_company_currency or 0.0),
|
||||||
'debit': (self.payment_type == 'inbound' and
|
'debit': (self.payment_type == 'inbound' and
|
||||||
amount or 0.0),
|
amount_company_currency or 0.0),
|
||||||
'date_maturity': date_maturity,
|
'date_maturity': date_maturity,
|
||||||
}
|
}
|
||||||
|
if bank_lines[0].currency_id != bank_lines[0].company_currency_id:
|
||||||
|
sign = self.payment_type == 'outbound' and -1 or 1
|
||||||
|
vals.update({
|
||||||
|
'currency_id': bank_lines[0].currency_id.id,
|
||||||
|
'amount_currency': amount_payment_currency * sign,
|
||||||
|
})
|
||||||
return vals
|
return vals
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _prepare_move_line_partner_account(self, bank_line):
|
def _prepare_move_line_partner_account(self, bank_line):
|
||||||
# TODO : ALEXIS check don't group if move_line_id.account_id
|
|
||||||
# is not the same
|
|
||||||
if bank_line.payment_line_ids[0].move_line_id:
|
if bank_line.payment_line_ids[0].move_line_id:
|
||||||
account_id =\
|
account_id =\
|
||||||
bank_line.payment_line_ids[0].move_line_id.account_id.id
|
bank_line.payment_line_ids[0].move_line_id.account_id.id
|
||||||
@@ -389,10 +400,16 @@ class AccountPaymentOrder(models.Model):
|
|||||||
'partner_id': bank_line.partner_id.id,
|
'partner_id': bank_line.partner_id.id,
|
||||||
'account_id': account_id,
|
'account_id': account_id,
|
||||||
'credit': (self.payment_type == 'inbound' and
|
'credit': (self.payment_type == 'inbound' and
|
||||||
bank_line.amount_currency or 0.0),
|
bank_line.amount_company_currency or 0.0),
|
||||||
'debit': (self.payment_type == 'outbound' and
|
'debit': (self.payment_type == 'outbound' and
|
||||||
bank_line.amount_currency or 0.0),
|
bank_line.amount_company_currency or 0.0),
|
||||||
}
|
}
|
||||||
|
if bank_line.currency_id != bank_line.company_currency_id:
|
||||||
|
sign = self.payment_type == 'inbound' and -1 or 1
|
||||||
|
vals.update({
|
||||||
|
'currency_id': bank_line.currency_id.id,
|
||||||
|
'amount_currency': bank_line.amount_currency * sign,
|
||||||
|
})
|
||||||
return vals
|
return vals
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@@ -415,25 +432,17 @@ class AccountPaymentOrder(models.Model):
|
|||||||
else:
|
else:
|
||||||
trfmoves[hashcode] = bline
|
trfmoves[hashcode] = bline
|
||||||
|
|
||||||
company_currency = self.env.user.company_id.currency_id
|
|
||||||
for hashcode, blines in trfmoves.iteritems():
|
for hashcode, blines in trfmoves.iteritems():
|
||||||
mvals = self._prepare_move()
|
mvals = self._prepare_move()
|
||||||
total_amount = 0
|
total_company_currency = total_payment_currency = 0
|
||||||
for bline in blines:
|
for bline in blines:
|
||||||
total_amount += bline.amount_currency
|
total_company_currency += bline.amount_company_currency
|
||||||
if bline.currency_id != company_currency:
|
total_payment_currency += bline.amount_currency
|
||||||
raise UserError(_(
|
|
||||||
"Cannot generate the account move when "
|
|
||||||
"the currency of the payment (%s) is not the "
|
|
||||||
"same as the currency of the company (%s). This "
|
|
||||||
"is not supported for the moment.")
|
|
||||||
% (bline.currency_id.name, company_currency.name))
|
|
||||||
|
|
||||||
partner_ml_vals = self._prepare_move_line_partner_account(
|
partner_ml_vals = self._prepare_move_line_partner_account(
|
||||||
bline)
|
bline)
|
||||||
mvals['line_ids'].append((0, 0, partner_ml_vals))
|
mvals['line_ids'].append((0, 0, partner_ml_vals))
|
||||||
trf_ml_vals = self._prepare_move_line_offsetting_account(
|
trf_ml_vals = self._prepare_move_line_offsetting_account(
|
||||||
total_amount, blines)
|
total_company_currency, total_payment_currency, blines)
|
||||||
mvals['line_ids'].append((0, 0, trf_ml_vals))
|
mvals['line_ids'].append((0, 0, trf_ml_vals))
|
||||||
move = am_obj.create(mvals)
|
move = am_obj.create(mvals)
|
||||||
blines.reconcile_payment_lines()
|
blines.reconcile_payment_lines()
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ class BankPaymentLine(models.Model):
|
|||||||
amount_currency = fields.Monetary(
|
amount_currency = fields.Monetary(
|
||||||
string='Amount', currency_field='currency_id',
|
string='Amount', currency_field='currency_id',
|
||||||
compute='_compute_amount', store=True, readonly=True)
|
compute='_compute_amount', store=True, readonly=True)
|
||||||
|
amount_company_currency = fields.Monetary(
|
||||||
|
string='Amount in Company Currency',
|
||||||
|
currency_field='company_currency_id',
|
||||||
|
compute='_compute_amount', store=True, readonly=True)
|
||||||
currency_id = fields.Many2one(
|
currency_id = fields.Many2one(
|
||||||
'res.currency', required=True, readonly=True,
|
'res.currency', required=True, readonly=True,
|
||||||
related='payment_line_ids.currency_id') # v8 field: currency
|
related='payment_line_ids.currency_id') # v8 field: currency
|
||||||
@@ -50,6 +54,9 @@ class BankPaymentLine(models.Model):
|
|||||||
company_id = fields.Many2one(
|
company_id = fields.Many2one(
|
||||||
related='order_id.payment_mode_id.company_id', store=True,
|
related='order_id.payment_mode_id.company_id', store=True,
|
||||||
readonly=True)
|
readonly=True)
|
||||||
|
company_currency_id = fields.Many2one(
|
||||||
|
related='order_id.payment_mode_id.company_id.currency_id',
|
||||||
|
readonly=True, store=True)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def same_fields_payment_line_and_bank_payment_line(self):
|
def same_fields_payment_line_and_bank_payment_line(self):
|
||||||
@@ -67,9 +74,14 @@ class BankPaymentLine(models.Model):
|
|||||||
@api.multi
|
@api.multi
|
||||||
@api.depends('payment_line_ids', 'payment_line_ids.amount_currency')
|
@api.depends('payment_line_ids', 'payment_line_ids.amount_currency')
|
||||||
def _compute_amount(self):
|
def _compute_amount(self):
|
||||||
for line in self:
|
for bline in self:
|
||||||
line.amount_currency = sum(
|
amount_currency = sum(
|
||||||
line.mapped('payment_line_ids.amount_currency'))
|
bline.mapped('payment_line_ids.amount_currency'))
|
||||||
|
amount_company_currency = bline.currency_id.with_context(
|
||||||
|
date=bline.date).compute(
|
||||||
|
amount_currency, bline.company_currency_id)
|
||||||
|
bline.amount_currency = amount_currency
|
||||||
|
bline.amount_company_currency = amount_company_currency
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
@api.returns('self')
|
@api.returns('self')
|
||||||
|
|||||||
@@ -33,14 +33,14 @@
|
|||||||
<field name="date"/>
|
<field name="date"/>
|
||||||
<field name="move_id" required="0"/>
|
<field name="move_id" required="0"/>
|
||||||
<field name="journal_id"/>
|
<field name="journal_id"/>
|
||||||
<field name="name"/>
|
|
||||||
<field name="partner_id"/>
|
<field name="partner_id"/>
|
||||||
<field name="account_id"/>
|
<field name="account_id"/>
|
||||||
<field name="date_maturity"/>
|
<field name="date_maturity"/>
|
||||||
<field name="debit" sum="Total Debit"/>
|
<field name="debit"/>
|
||||||
<field name="credit" sum="Total Credit"/>
|
<field name="credit"/>
|
||||||
<field name="amount_currency" invisible="1"/>
|
<field name="amount_residual" sum="Total Residual"/>
|
||||||
<field name="currency_id" invisible="1" />
|
<field name="amount_currency"/>
|
||||||
|
<field name="amount_residual_currency"/>
|
||||||
<field name="company_currency_id" invisible="1"/>
|
<field name="company_currency_id" invisible="1"/>
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
|
|||||||
Reference in New Issue
Block a user