diff --git a/account_payment_order/models/account_payment_mode.py b/account_payment_order/models/account_payment_mode.py
index 83e7a4cb4..90770d679 100644
--- a/account_payment_order/models/account_payment_mode.py
+++ b/account_payment_order/models/account_payment_mode.py
@@ -47,8 +47,12 @@ class AccountPaymentMode(models.Model):
"* Payment Date\n"
"(other modules can set additional fields to restrict the "
"grouping.)")
- transfer_move = fields.Boolean(
+ generate_move = fields.Boolean(
'Generate Accounting Entries On File Upload')
+ offsetting_account = fields.Selection([
+ ('bank_account', 'Bank Account'),
+ ('transfer_account', 'Transfer Account'),
+ ], string='Offsetting Account')
transfer_account_id = fields.Many2one(
'account.account', string='Transfer Account',
domain=[('internal_type', '=', 'other'), ('reconcile', '=', True)],
@@ -59,26 +63,39 @@ class AccountPaymentMode(models.Model):
'account.journal', string='Transfer Journal',
help='Journal to write payment entries when confirming '
'payment/debit orders of this mode')
- transfer_move_option = fields.Selection([
+ move_option = fields.Selection([
('date', 'One move per payment date'),
('line', 'One move per payment line'),
- ], string='Transfer Move Option', default='date')
+ ], string='Move Option')
@api.multi
@api.constrains(
- 'transfer_move', 'transfer_account_id', 'transfer_journal_id',
- 'transfer_move_option')
+ 'generate_move', 'offsetting_account',
+ 'transfer_account_id', 'transfer_journal_id', 'move_option')
def transfer_move_constrains(self):
for mode in self:
- if mode.transfer_move and (
- not mode.transfer_account_id or
- not mode.transfer_journal_id or
- not mode.transfer_move_option):
- raise ValidationError(_(
- "The option 'Generate Accounting Entries On File Upload' "
- "is active on payment mode '%s', so the three parameters "
- "'Transfer Account', 'Transfer Journal' and "
- "'Transfer Move Option' must be set.") % mode.name)
+ if mode.generate_move:
+ if not mode.offsetting_account:
+ raise ValidationError(_(
+ "On the payment mode '%s', you must select an "
+ "option for the 'Offsetting Account' parameter")
+ % mode.name)
+ elif mode.offsetting_account == 'transfer_account':
+ if not mode.transfer_account_id:
+ raise ValidationError(_(
+ "On the payment mode '%s', you must "
+ "select a value for the 'Transfer Account'.")
+ % mode.name)
+ if not mode.transfer_journal_id:
+ raise ValidationError(_(
+ "On the payment mode '%s', you must "
+ "select a value for the 'Transfer Journal'.")
+ % mode.name)
+ if not mode.move_option:
+ raise ValidationError(_(
+ "On the payment mode '%s', you must "
+ "choose an option for the 'Move Option' "
+ "parameter.") % mode.name)
@api.onchange('payment_method_id')
def payment_method_id_change(self):
@@ -92,3 +109,21 @@ class AccountPaymentMode(models.Model):
aj_ids = ajo.search([
('type', 'in', ('sale_refund', 'sale'))]).ids
self.default_journal_ids = [(6, 0, aj_ids)]
+
+ @api.onchange('generate_move')
+ def generate_move_change(self):
+ if self.generate_move:
+ # default values
+ self.offsetting_account = 'bank_account'
+ self.move_option = 'date'
+ else:
+ self.offsetting_account = False
+ self.transfer_account_id = False
+ self.transfer_journal_id = False
+ self.move_option = False
+
+ @api.onchange('offsetting_account')
+ def offsetting_account_change(self):
+ if self.offsetting_account == 'bank_account':
+ self.transfer_account_id = False
+ self.transfer_journal_id = False
diff --git a/account_payment_order/models/account_payment_order.py b/account_payment_order/models/account_payment_order.py
index 9f36ae853..85d14fdfc 100644
--- a/account_payment_order/models/account_payment_order.py
+++ b/account_payment_order/models/account_payment_order.py
@@ -83,7 +83,7 @@ class AccountPaymentOrder(models.Model):
compute='_bank_line_count', string='Number of Bank Lines',
readonly=True)
move_ids = fields.One2many(
- 'account.move', 'payment_order_id', string='Transfer Journal Entries',
+ 'account.move', 'payment_order_id', string='Journal Entries',
readonly=True)
@api.multi
@@ -292,23 +292,26 @@ class AccountPaymentOrder(models.Model):
@api.multi
def generated2uploaded(self):
for order in self:
- if order.payment_mode_id.transfer_move:
- order.generate_transfer_move()
+ if order.payment_mode_id.generate_move:
+ order.generate_move()
self.write({
'state': 'uploaded',
'date_uploaded': fields.Date.context_today(self),
})
return True
- # Generation of transfer move
@api.multi
- def _prepare_transfer_move(self):
+ def _prepare_move(self):
if self.payment_type == 'outbound':
ref = _('Payment order %s') % self.name
else:
ref = _('Debit order %s') % self.name
+ if self.payment_mode_id.offsetting_account == 'bank_account':
+ journal_id = self.journal_id.id
+ elif self.payment_mode_id.offsetting_account == 'transfer_account':
+ journal_id = self.payment_mode_id.transfer_journal_id.id
vals = {
- 'journal_id': self.payment_mode_id.transfer_journal_id.id,
+ 'journal_id': journal_id,
'ref': ref,
'payment_order_id': self.id,
'line_ids': [],
@@ -316,17 +319,21 @@ class AccountPaymentOrder(models.Model):
return vals
@api.multi
- def _prepare_move_line_transfer_account(
+ def _prepare_move_line_offsetting_account(
self, amount, bank_payment_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
+ 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':
+ account_id = self.payment_mode_id.transfer_account_id.id
vals = {
'name': name,
'partner_id': False,
- 'account_id': self.payment_mode_id.transfer_account_id.id,
+ 'account_id': account_id,
'credit': (self.payment_type == 'outbound' and
amount or 0.0),
'debit': (self.payment_type == 'inbound' and
@@ -366,7 +373,7 @@ class AccountPaymentOrder(models.Model):
return vals
@api.multi
- def generate_transfer_move(self):
+ def generate_move(self):
"""
Create the moves that pay off the move lines from
the payment/debit order.
@@ -374,12 +381,12 @@ class AccountPaymentOrder(models.Model):
self.ensure_one()
am_obj = self.env['account.move']
# prepare a dict "trfmoves" that can be used when
- # self.payment_mode_id.transfer_move_option = date or line
+ # self.payment_mode_id.move_option = date or line
# key = unique identifier (date or True or line.id)
# value = bank_pay_lines (recordset that can have several entries)
trfmoves = {}
for bline in self.bank_line_ids:
- hashcode = bline.move_line_transfer_account_hashcode()
+ hashcode = bline.move_line_offsetting_account_hashcode()
if hashcode in trfmoves:
trfmoves[hashcode] += bline
else:
@@ -387,13 +394,13 @@ class AccountPaymentOrder(models.Model):
company_currency = self.env.user.company_id.currency_id
for hashcode, blines in trfmoves.iteritems():
- mvals = self._prepare_transfer_move()
+ mvals = self._prepare_move()
total_amount = 0
for bline in blines:
total_amount += bline.amount_currency
if bline.currency_id != company_currency:
raise UserError(_(
- "Cannot generate the transfer move when "
+ "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.")
@@ -402,7 +409,7 @@ class AccountPaymentOrder(models.Model):
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_transfer_account(
+ trf_ml_vals = self._prepare_move_line_offsetting_account(
total_amount, blines)
mvals['line_ids'].append((0, 0, trf_ml_vals))
move = am_obj.create(mvals)
diff --git a/account_payment_order/models/bank_payment_line.py b/account_payment_order/models/bank_payment_line.py
index 8126709cf..8bd0fc431 100644
--- a/account_payment_order/models/bank_payment_line.py
+++ b/account_payment_order/models/bank_payment_line.py
@@ -80,13 +80,13 @@ class BankPaymentLine(models.Model):
return super(BankPaymentLine, self).create(vals)
@api.multi
- def move_line_transfer_account_hashcode(self):
+ def move_line_offsetting_account_hashcode(self):
"""
This method is inherited in the module
account_banking_sepa_direct_debit
"""
self.ensure_one()
- if self.order_id.payment_mode_id.transfer_move_option == 'date':
+ if self.order_id.payment_mode_id.move_option == 'date':
hashcode = self.date
else:
hashcode = unicode(self.id)
diff --git a/account_payment_order/views/account_payment_mode.xml b/account_payment_order/views/account_payment_mode.xml
index fba7b0512..6ba387602 100644
--- a/account_payment_order/views/account_payment_mode.xml
+++ b/account_payment_order/views/account_payment_mode.xml
@@ -20,15 +20,17 @@
-
-
+
+
+
-
+ attrs="{'invisible': [('offsetting_account', '!=', 'transfer_account')], 'required': [('offsetting_account', '=', 'transfer_account')]}"/>
+