Skip to content

Commit

Permalink
[IMP] account_check: some improvment to checks (ingadhoc#151)
Browse files Browse the repository at this point in the history
Add a constrians to set amount_company_currency or amount if some of them are not setting
  • Loading branch information
nicomacr authored and jjscarafia committed Jul 1, 2019
1 parent b53d60a commit 28ef2fd
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion account_check/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
##############################################################################
{
'name': 'Account Check Management',
'version': '11.0.1.10.0',
'version': '11.0.1.11.0',
'category': 'Accounting',
'summary': 'Accounting, Payment, Check, Third, Issue',
'author': 'ADHOC SA',
Expand Down
16 changes: 16 additions & 0 deletions account_check/migrations/11.0.1.11.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from openupgradelib import openupgrade
import logging

_logger = logging.getLogger(__name__)


@openupgrade.migrate()
def migrate(env, version):

_logger.info('Setting inital values for amount_company_currency')
env.cr.execute("""
UPDATE account_check AS ac SET amount_company_currency = ac.amount
FROM res_company AS rc
WHERE rc.id = ac.company_id and ac.currency_id = rc.currency_id
and ac.amount_company_currency = 0.0
""")
14 changes: 14 additions & 0 deletions account_check/models/account_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,20 @@ def get_payment_values(self, journal):
# 'check_ids': [(4, self.id, False)],
}

@api.constrains('currency_id', 'amount', 'amount_company_currency')
def _check_amounts(self):
for rec in self.filtered(
lambda x: not x.amount or not x.amount_company_currency):
if rec.currency_id != rec.company_currency_id:
raise ValidationError(_(
'If you create a check with different currency thant the '
'company currency, you must provide "Amount" and "Amount '
'Company Currency"'))
elif not rec.amount:
rec.amount = rec.amount_company_currency
elif not rec.amount_company_currency:
rec.amount_company_currency = rec.amount

@api.multi
def reject(self):
self.ensure_one()
Expand Down
9 changes: 6 additions & 3 deletions account_check/views/account_check_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
<field name="id" invisible="1"/>
<field name="type" invisible="1"/>
<field name="journal_id" invisible="1"/>
<field name="currency_id" invisible="1"/>
<field name="issue_check_subtype" invisible="1"/>
<field name="company_currency_id" invisible="1"/>
<header>
Expand All @@ -67,13 +66,17 @@
<h1>
<field name="name"/>
</h1>
<group>
<group>
<group>
<field name="journal_id"/>
<field name="checkbook_id" attrs="{'invisible':[('type','!=','issue_check')],'required':[('type','=','issue_check')]}" domain="[('journal_id', '=', journal_id)]"/>
<field name="bank_id"/>
<field name="number"/>
<field name="amount"/>
<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="amount_company_currency"/>
</group>
<group>
Expand Down

0 comments on commit 28ef2fd

Please sign in to comment.