[IMP] account : Allow payment of 0 amount in write-off balance

The user can register a payment of 0 amount with "Mark Invoice as Paid" option and selecting an account to post the difference.

task: https://www.odoo.com/web#id=29959&view_type=form&model=project.task&action=333&active_id=131&menu_id=4720
PR: #16429
This commit is contained in:
Akash Bhavsar
2017-08-29 12:05:59 +02:00
committed by Laurent Smet
parent d2e33ba57c
commit 3267e76520
3 changed files with 36 additions and 15 deletions
+28 -9
View File
@@ -56,8 +56,8 @@ class account_abstract_payment(models.AbstractModel):
@api.one
@api.constrains('amount')
def _check_amount(self):
if not self.amount > 0.0:
raise ValidationError(_('The payment amount must be strictly positive.'))
if self.amount < 0:
raise ValidationError(_('The payment amount cannot be negative.'))
@api.multi
@api.depends('payment_type', 'journal_id')
@@ -309,6 +309,24 @@ class account_payment(models.Model):
'context': action_context,
}
@api.onchange('amount', 'currency_id')
def _onchange_amount(self):
journal_type = ['bank', 'cash']
domain = []
if self.currency_id.is_zero(self.amount):
# In case of payment with 0 amount, allow to select a journal of type 'general' like
# 'Miscellaneous Operations' and set this journal by default.
journal_type.append('general')
self.payment_difference_handling = 'reconcile'
self.journal_id = self.env['account.journal'].search([('type', '=', 'general')], limit=1)
else:
if self.payment_type == 'inbound':
domain.append(('at_least_one_inbound', '=', True))
else:
domain.append(('at_least_one_outbound', '=', True))
domain.append(('type', 'in', journal_type))
return {'domain': {'journal_id': domain}}
@api.one
@api.depends('invoice_ids', 'payment_type', 'partner_type', 'partner_id')
def _compute_destination_account_id(self):
@@ -526,18 +544,19 @@ class account_payment(models.Model):
writeoff_line['amount_currency'] = amount_currency_wo
writeoff_line['currency_id'] = currency_id
writeoff_line = aml_obj.create(writeoff_line)
if counterpart_aml['debit']:
if counterpart_aml['debit'] or writeoff_line['credit']:
counterpart_aml['debit'] += credit_wo - debit_wo
if counterpart_aml['credit']:
if counterpart_aml['credit'] or writeoff_line['debit']:
counterpart_aml['credit'] += debit_wo - credit_wo
counterpart_aml['amount_currency'] -= amount_currency_wo
#Write counterpart lines
if not self.currency_id != self.company_id.currency_id:
amount_currency = 0
liquidity_aml_dict = self._get_shared_move_line_vals(credit, debit, -amount_currency, move.id, False)
liquidity_aml_dict.update(self._get_liquidity_move_line_vals(-amount))
aml_obj.create(liquidity_aml_dict)
if not self.currency_id.is_zero(self.amount):
if not self.currency_id != self.company_id.currency_id:
amount_currency = 0
liquidity_aml_dict = self._get_shared_move_line_vals(credit, debit, -amount_currency, move.id, False)
liquidity_aml_dict.update(self._get_liquidity_move_line_vals(-amount))
aml_obj.create(liquidity_aml_dict)
#validate the payment
move.post()
@@ -230,15 +230,15 @@
<field name="partner_id" invisible="1"/>
<field name="state" invisible="1"/>
<group>
<field name="journal_id" widget="selection"/>
<field name="hide_payment_method" invisible="1"/>
<field name="payment_method_id" widget="radio" attrs="{'invisible': [('hide_payment_method', '=', True)]}"/>
<field name="payment_method_code" invisible="1"/>
<label for="amount"/>
<div name="amount_div" class="o_row">
<field name="amount"/>
<field name="currency_id" options="{'no_create': True, 'no_open': True}" groups="base.group_multi_currency"/>
</div>
<field name="journal_id" widget="selection" attrs="{'invisible': [('amount', '=', 0)]}"/>
<field name="hide_payment_method" invisible="1"/>
<field name="payment_method_id" widget="radio" attrs="{'invisible': ['|', ('hide_payment_method', '=', True), ('amount', '=', 0.0)]}"/>
<field name="payment_method_code" invisible="1"/>
</group>
<group>
<field name="payment_date"/>
@@ -252,6 +252,8 @@
<div attrs="{'invisible': [('payment_difference_handling','=','open')]}">
<label for="writeoff_account_id" class="oe_edit_only" string="Post Difference In"/>
<field name="writeoff_account_id" string="Post Difference In" attrs="{'required': [('payment_difference_handling', '=', 'reconcile')]}"/>
<label string="Journal" attrs="{'invisible': [('amount', '!=', 0)]}"/>
<field name="journal_id" string="Journal" widget="selection" attrs="{'invisible': [('amount', '!=', 0)]}"/>
<label for="writeoff_label" class="oe_edit_only" string="Label"/>
<field name="writeoff_label" attrs="{'required': [('payment_difference_handling', '=', 'reconcile')]}"/>
</div>
@@ -68,9 +68,9 @@ class AccountPayment(models.Model):
@api.onchange('amount')
def _onchange_amount(self):
if hasattr(super(AccountPayment, self), '_onchange_amount'):
super(AccountPayment, self)._onchange_amount()
res = super(AccountPayment, self)._onchange_amount()
self.check_amount_in_words = self._get_check_amount_in_words(self.amount)
return res
def _check_communication(self, payment_method_id, communication):
super(AccountPayment, self)._check_communication(payment_method_id, communication)