Skip to content

Commit 28ef2fd

Browse files
nicomacrjjscarafia
authored andcommitted
[IMP] account_check: some improvment to checks (ingadhoc#151)
Add a constrians to set amount_company_currency or amount if some of them are not setting
1 parent b53d60a commit 28ef2fd

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

account_check/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
##############################################################################
2020
{
2121
'name': 'Account Check Management',
22-
'version': '11.0.1.10.0',
22+
'version': '11.0.1.11.0',
2323
'category': 'Accounting',
2424
'summary': 'Accounting, Payment, Check, Third, Issue',
2525
'author': 'ADHOC SA',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from openupgradelib import openupgrade
2+
import logging
3+
4+
_logger = logging.getLogger(__name__)
5+
6+
7+
@openupgrade.migrate()
8+
def migrate(env, version):
9+
10+
_logger.info('Setting inital values for amount_company_currency')
11+
env.cr.execute("""
12+
UPDATE account_check AS ac SET amount_company_currency = ac.amount
13+
FROM res_company AS rc
14+
WHERE rc.id = ac.company_id and ac.currency_id = rc.currency_id
15+
and ac.amount_company_currency = 0.0
16+
""")

account_check/models/account_check.py

+14
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,20 @@ def get_payment_values(self, journal):
634634
# 'check_ids': [(4, self.id, False)],
635635
}
636636

637+
@api.constrains('currency_id', 'amount', 'amount_company_currency')
638+
def _check_amounts(self):
639+
for rec in self.filtered(
640+
lambda x: not x.amount or not x.amount_company_currency):
641+
if rec.currency_id != rec.company_currency_id:
642+
raise ValidationError(_(
643+
'If you create a check with different currency thant the '
644+
'company currency, you must provide "Amount" and "Amount '
645+
'Company Currency"'))
646+
elif not rec.amount:
647+
rec.amount = rec.amount_company_currency
648+
elif not rec.amount_company_currency:
649+
rec.amount_company_currency = rec.amount
650+
637651
@api.multi
638652
def reject(self):
639653
self.ensure_one()

account_check/views/account_check_view.xml

+6-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
<field name="id" invisible="1"/>
4848
<field name="type" invisible="1"/>
4949
<field name="journal_id" invisible="1"/>
50-
<field name="currency_id" invisible="1"/>
5150
<field name="issue_check_subtype" invisible="1"/>
5251
<field name="company_currency_id" invisible="1"/>
5352
<header>
@@ -67,13 +66,17 @@
6766
<h1>
6867
<field name="name"/>
6968
</h1>
70-
<group>
69+
<group>
7170
<group>
7271
<field name="journal_id"/>
7372
<field name="checkbook_id" attrs="{'invisible':[('type','!=','issue_check')],'required':[('type','=','issue_check')]}" domain="[('journal_id', '=', journal_id)]"/>
7473
<field name="bank_id"/>
7574
<field name="number"/>
76-
<field name="amount"/>
75+
<label for="amount"/>
76+
<div name="amount_div" class="o_row">
77+
<field name="amount"/>
78+
<field name="currency_id" options="{'no_create': True, 'no_open': True}" groups="base.group_multi_currency"/>
79+
</div>
7780
<field name="amount_company_currency"/>
7881
</group>
7982
<group>

0 commit comments

Comments
 (0)