Skip to content

Commit

Permalink
[IMP] account : Allow payment of 0 amount in write-off balance
Browse files Browse the repository at this point in the history
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: odoo#16429
  • Loading branch information
abh-odoo authored and smetl committed Aug 29, 2017
1 parent d2e33ba commit 3267e76
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
37 changes: 28 additions & 9 deletions addons/account/models/account_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -309,6 +309,24 @@ def open_payment_matching_screen(self):
'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):
Expand Down Expand Up @@ -526,18 +544,19 @@ def _create_payment_entry(self, amount):
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()
Expand Down
10 changes: 6 additions & 4 deletions addons/account/views/account_payment_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand All @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions addons/account_check_printing/models/account_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ def _onchange_journal_id(self):

@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)
Expand Down

0 comments on commit 3267e76

Please sign in to comment.