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
Enric Tobella
parent
13c6b70d1e
commit
55bd50361d
@@ -41,16 +41,16 @@ class AccountPaymentMode(models.Model):
|
||||
('move', 'Move'),
|
||||
], default='due', string="Type of Date Filter")
|
||||
group_lines = fields.Boolean(
|
||||
string="Group Lines in Payment Orders", default=True,
|
||||
help="If this mark is checked, the payment order lines will be "
|
||||
"grouped when validating the payment order before exporting the "
|
||||
"bank file. The grouping will be done only if the following "
|
||||
string="Group Transactions in Payment Orders", default=True,
|
||||
help="If this mark is checked, the transaction lines of the "
|
||||
"payment order will be grouped upon confirmation of the payment "
|
||||
"order.The grouping will be done only if the following "
|
||||
"fields matches:\n"
|
||||
"* Partner\n"
|
||||
"* Currency\n"
|
||||
"* Destination Bank Account\n"
|
||||
"* Communication Type (structured, free)\n"
|
||||
"* Payment Date\n"
|
||||
"and if the 'Communication Type' is 'Free'\n"
|
||||
"(other modules can set additional fields to restrict the "
|
||||
"grouping.)")
|
||||
generate_move = fields.Boolean(
|
||||
|
||||
@@ -78,7 +78,13 @@ class AccountPaymentOrder(models.Model):
|
||||
# v8 field : line_ids
|
||||
bank_line_ids = fields.One2many(
|
||||
'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(
|
||||
compute='_compute_total', store=True, readonly=True,
|
||||
currency_field='company_currency_id')
|
||||
@@ -343,12 +349,13 @@ class AccountPaymentOrder(models.Model):
|
||||
|
||||
@api.multi
|
||||
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':
|
||||
name = _('Payment order %s') % self.name
|
||||
else:
|
||||
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':
|
||||
account_id = self.journal_id.default_debit_account_id.id
|
||||
elif self.payment_mode_id.offsetting_account == 'transfer_account':
|
||||
@@ -358,17 +365,21 @@ class AccountPaymentOrder(models.Model):
|
||||
'partner_id': False,
|
||||
'account_id': account_id,
|
||||
'credit': (self.payment_type == 'outbound' and
|
||||
amount or 0.0),
|
||||
amount_company_currency or 0.0),
|
||||
'debit': (self.payment_type == 'inbound' and
|
||||
amount or 0.0),
|
||||
amount_company_currency or 0.0),
|
||||
'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
|
||||
|
||||
@api.multi
|
||||
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:
|
||||
account_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,
|
||||
'account_id': account_id,
|
||||
'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
|
||||
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
|
||||
|
||||
@api.multi
|
||||
@@ -415,25 +432,17 @@ class AccountPaymentOrder(models.Model):
|
||||
else:
|
||||
trfmoves[hashcode] = bline
|
||||
|
||||
company_currency = self.env.user.company_id.currency_id
|
||||
for hashcode, blines in trfmoves.iteritems():
|
||||
mvals = self._prepare_move()
|
||||
total_amount = 0
|
||||
total_company_currency = total_payment_currency = 0
|
||||
for bline in blines:
|
||||
total_amount += bline.amount_currency
|
||||
if bline.currency_id != company_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))
|
||||
|
||||
total_company_currency += bline.amount_company_currency
|
||||
total_payment_currency += bline.amount_currency
|
||||
partner_ml_vals = self._prepare_move_line_partner_account(
|
||||
bline)
|
||||
mvals['line_ids'].append((0, 0, partner_ml_vals))
|
||||
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))
|
||||
move = am_obj.create(mvals)
|
||||
blines.reconcile_payment_lines()
|
||||
|
||||
@@ -34,6 +34,10 @@ class BankPaymentLine(models.Model):
|
||||
amount_currency = fields.Monetary(
|
||||
string='Amount', currency_field='currency_id',
|
||||
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(
|
||||
'res.currency', required=True, readonly=True,
|
||||
related='payment_line_ids.currency_id') # v8 field: currency
|
||||
@@ -50,6 +54,9 @@ class BankPaymentLine(models.Model):
|
||||
company_id = fields.Many2one(
|
||||
related='order_id.payment_mode_id.company_id', store=True,
|
||||
readonly=True)
|
||||
company_currency_id = fields.Many2one(
|
||||
related='order_id.payment_mode_id.company_id.currency_id',
|
||||
readonly=True, store=True)
|
||||
|
||||
@api.model
|
||||
def same_fields_payment_line_and_bank_payment_line(self):
|
||||
@@ -67,9 +74,14 @@ class BankPaymentLine(models.Model):
|
||||
@api.multi
|
||||
@api.depends('payment_line_ids', 'payment_line_ids.amount_currency')
|
||||
def _compute_amount(self):
|
||||
for line in self:
|
||||
line.amount_currency = sum(
|
||||
line.mapped('payment_line_ids.amount_currency'))
|
||||
for bline in self:
|
||||
amount_currency = sum(
|
||||
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.returns('self')
|
||||
|
||||
@@ -33,14 +33,14 @@
|
||||
<field name="date"/>
|
||||
<field name="move_id" required="0"/>
|
||||
<field name="journal_id"/>
|
||||
<field name="name"/>
|
||||
<field name="partner_id"/>
|
||||
<field name="account_id"/>
|
||||
<field name="date_maturity"/>
|
||||
<field name="debit" sum="Total Debit"/>
|
||||
<field name="credit" sum="Total Credit"/>
|
||||
<field name="amount_currency" invisible="1"/>
|
||||
<field name="currency_id" invisible="1" />
|
||||
<field name="debit"/>
|
||||
<field name="credit"/>
|
||||
<field name="amount_residual" sum="Total Residual"/>
|
||||
<field name="amount_currency"/>
|
||||
<field name="amount_residual_currency"/>
|
||||
<field name="company_currency_id" invisible="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user