mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[FIX+IMP] account_payment_order:
* FIX: Bug #353 crash when selecting a payment mode that has a variable link to a bank account * FIX: Add 'post_move' option on account.payment.mode with default True, to keep the previous behavior * IMP: Explicit error when bank account is missing on bank journal * IMP: Add field default_date_prefered on payment mode.
This commit is contained in:
committed by
Pedro M. Baeza
parent
956e8d1a4a
commit
d059a5eb0d
@@ -9,7 +9,7 @@
|
||||
|
||||
{
|
||||
'name': 'Account Payment Order',
|
||||
'version': '10.0.1.1.1',
|
||||
'version': '10.0.1.2.0',
|
||||
'license': 'AGPL-3',
|
||||
'author': "ACSONE SA/NV, "
|
||||
"Therp BV, "
|
||||
|
||||
@@ -34,6 +34,8 @@ class AccountInvoice(models.Model):
|
||||
def _prepare_new_payment_order(self):
|
||||
self.ensure_one()
|
||||
vals = {'payment_mode_id': self.payment_mode_id.id}
|
||||
# other important fields are set by the inherit of create
|
||||
# in account_payment_order.py
|
||||
return vals
|
||||
|
||||
@api.multi
|
||||
|
||||
@@ -40,6 +40,12 @@ class AccountPaymentMode(models.Model):
|
||||
('due', 'Due'),
|
||||
('move', 'Move'),
|
||||
], default='due', string="Type of Date Filter")
|
||||
# default option for account.payment.order
|
||||
default_date_prefered = fields.Selection([
|
||||
('now', 'Immediately'),
|
||||
('due', 'Due Date'),
|
||||
('fixed', 'Fixed Date'),
|
||||
], string='Default Payment Execution Date')
|
||||
group_lines = fields.Boolean(
|
||||
string="Group Transactions in Payment Orders", default=True,
|
||||
help="If this mark is checked, the transaction lines of the "
|
||||
@@ -73,6 +79,7 @@ class AccountPaymentMode(models.Model):
|
||||
('date', 'One move per payment date'),
|
||||
('line', 'One move per payment line'),
|
||||
], string='Move Option', default='date')
|
||||
post_move = fields.Boolean(string='Post Move', default=True)
|
||||
|
||||
@api.multi
|
||||
@api.constrains(
|
||||
|
||||
@@ -39,9 +39,6 @@ class AccountPaymentOrder(models.Model):
|
||||
'account.journal', string='Bank Journal', ondelete='restrict',
|
||||
readonly=True, states={'draft': [('readonly', False)]},
|
||||
track_visibility='onchange')
|
||||
allowed_journal_ids = fields.Many2many(
|
||||
'account.journal', compute='_compute_allowed_journals', readonly=True,
|
||||
string='Selectable Bank Journals')
|
||||
# The journal_id field is only required at confirm step, to
|
||||
# allow auto-creation of payment order from invoice
|
||||
company_partner_bank_id = fields.Many2one(
|
||||
@@ -133,19 +130,6 @@ class AccountPaymentOrder(models.Model):
|
||||
for order in self:
|
||||
order.bank_line_count = len(order.bank_line_ids)
|
||||
|
||||
@api.multi
|
||||
@api.depends('payment_mode_id')
|
||||
def _compute_allowed_journals(self):
|
||||
for order in self:
|
||||
allowed_journal_ids = False
|
||||
if order.payment_mode_id:
|
||||
mode = order.payment_mode_id
|
||||
if mode.bank_account_link == 'fixed':
|
||||
allowed_journal_ids = mode.fixed_journal_id
|
||||
else:
|
||||
allowed_journal_ids = mode.variable_journal_ids
|
||||
order.allowed_journal_ids = allowed_journal_ids
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
if vals.get('name', 'New') == 'New':
|
||||
@@ -157,15 +141,29 @@ class AccountPaymentOrder(models.Model):
|
||||
vals['payment_type'] = payment_mode.payment_type
|
||||
if payment_mode.bank_account_link == 'fixed':
|
||||
vals['journal_id'] = payment_mode.fixed_journal_id.id
|
||||
if (
|
||||
not vals.get('date_prefered') and
|
||||
payment_mode.default_date_prefered):
|
||||
vals['date_prefered'] = payment_mode.default_date_prefered
|
||||
return super(AccountPaymentOrder, self).create(vals)
|
||||
|
||||
@api.onchange('payment_mode_id')
|
||||
def payment_mode_id_change(self):
|
||||
journal_id = False
|
||||
res = {'domain': {
|
||||
'journal_id': "[('id', '=', False)]",
|
||||
}}
|
||||
if self.payment_mode_id:
|
||||
if self.payment_mode_id.bank_account_link == 'fixed':
|
||||
journal_id = self.payment_mode_id.fixed_journal_id
|
||||
journal_id = self.payment_mode_id.fixed_journal_id.id
|
||||
res['domain']['journal_id'] = "[('id', '=', %d)]" % journal_id
|
||||
elif self.payment_mode_id.bank_account_link == 'variable':
|
||||
jrl_ids = self.payment_mode_id.variable_journal_ids.ids
|
||||
res['domain']['journal_id'] = "[('id', 'in', %s)]" % jrl_ids
|
||||
self.journal_id = journal_id
|
||||
if self.payment_mode_id.default_date_prefered:
|
||||
self.date_prefered = self.payment_mode_id.default_date_prefered
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def action_done(self):
|
||||
@@ -210,6 +208,12 @@ class AccountPaymentOrder(models.Model):
|
||||
if not order.journal_id:
|
||||
raise UserError(_(
|
||||
'Missing Bank Journal on payment order %s.') % order.name)
|
||||
if (
|
||||
order.payment_method_id.bank_account_required and
|
||||
not order.journal_id.bank_account_id):
|
||||
raise UserError(_(
|
||||
"Missing bank account on bank journal '%s'.")
|
||||
% order.journal_id.display_name)
|
||||
if not order.payment_line_ids:
|
||||
raise UserError(_(
|
||||
'There are no transactions on payment order %s.')
|
||||
@@ -433,6 +437,7 @@ class AccountPaymentOrder(models.Model):
|
||||
"""
|
||||
self.ensure_one()
|
||||
am_obj = self.env['account.move']
|
||||
post_move = self.payment_mode_id.post_move
|
||||
# prepare a dict "trfmoves" that can be used when
|
||||
# self.payment_mode_id.move_option = date or line
|
||||
# key = unique identifier (date or True or line.id)
|
||||
@@ -459,4 +464,5 @@ class AccountPaymentOrder(models.Model):
|
||||
mvals['line_ids'].append((0, 0, trf_ml_vals))
|
||||
move = am_obj.create(mvals)
|
||||
blines.reconcile_payment_lines()
|
||||
move.post()
|
||||
if post_move:
|
||||
move.post()
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
attrs="{'invisible': [('payment_order_ok', '=', False)]}">
|
||||
<field name="no_debit_before_maturity"
|
||||
attrs="{'invisible': ['|', ('payment_type', '!=', 'inbound'), ('payment_order_ok', '!=', True)]}"/>
|
||||
<field name="default_date_prefered"/>
|
||||
<field name="group_lines"/>
|
||||
</group>
|
||||
<group name="payment_order_create_defaults"
|
||||
@@ -40,6 +41,7 @@
|
||||
attrs="{'invisible': [('offsetting_account', '!=', 'transfer_account')], 'required': [('offsetting_account', '=', 'transfer_account')]}"/>
|
||||
<field name="move_option"
|
||||
attrs="{'invisible': [('generate_move', '=', False)], 'required': [('generate_move', '=', True)]}"/>
|
||||
<field name="post_move"/>
|
||||
</group>
|
||||
</group>
|
||||
</field>
|
||||
|
||||
@@ -33,9 +33,7 @@
|
||||
<field name="payment_mode_id"
|
||||
domain="[('payment_order_ok', '=', True), ('payment_type', '=', payment_type)]"
|
||||
widget="selection"/>
|
||||
<field name="journal_id" widget="selection"
|
||||
domain="[('id', 'in', allowed_journal_ids and allowed_journal_ids[0] and allowed_journal_ids[0][2] or [])]"/>
|
||||
<field name="allowed_journal_ids" invisible="1"/>
|
||||
<field name="journal_id" widget="selection"/>
|
||||
<field name="bank_account_link" invisible="1"/>
|
||||
<field name="company_partner_bank_id"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
|
||||
Reference in New Issue
Block a user